Add an attribute value

@param AttributeValueInterface $attributeValue

@return $this
183596
public function addAttributeValue(AttributeValueInterface $attributeValue)
    {
        if (!$this->attributeValues->contains($attributeValue)) {
            $attributeValue->setSubject($this);
            $this->attributeValues->add($attributeValue);
        }

        return $this;
    }
260422
protected function createAttributeValue(Attribute $attribute, \DOMNode $node, ObjectManager $manager)
    {
        $value = new AttributeValue();
        $value->setAttribute($attribute);

        $manager->persist($value);

        $attribute->addValue($value);

        foreach ($node->childNodes as $childNode) {
            $locale = $childNode->attributes->getNamedItem('locale')->nodeValue;
            $translation = $this->createAttributeValueTranslation(
                $childNode->nodeValue,
                $locale
            );
            $translation->setAttributeValue($value);
            $value->addTranslation($translation);

            $manager->persist($translation);
        }

        return $value;
    }
411000
public function addValueData(AttributeInterface $attribute, $valueData, array $context = null)
    {
        $this->checkAttribute($attribute);
        if (!$attribute->isCollection()) {
            $m = "Cannot append data to a non-collection attribute '{$attribute->getCode()}'";
            throw new InvalidValueDataException($m);
        }
        $newValue = $this->createValue($attribute, $context);
        $position = -1;
        foreach ($this->getInternalValues($attribute, $context) as $value) {
            $position = max($position, $value->getPosition());
        }
        $newValue->setPosition($position + 1);
        $this->setInternalValueData($attribute, $newValue, $valueData);

        return $this;
    }
372355
protected function setInternalValuesData(AttributeInterface $attribute, $dataValues, array $context = null)
    {
        $this->checkAttribute($attribute);
        $dataValues = $this->ensureNativeArray($dataValues, $this->getFamilyCode().'.'.$attribute->getCode());
        $values = new ArrayCollection();
        $position = 0; // Reset position to zero

        foreach ($this->getInternalValues($attribute, $context) as $value) {
            // If there values to replace
            if (\count($dataValues)) {
                // Extract new values and replaces them one by one
                $dataValue = array_shift($dataValues);
                $value->setPosition(++$position);
                $this->setInternalValueData($attribute, $value, $dataValue);
                $values->add($value);
            } else {
                // If there are too much existing values previously, remove the extra ones
                $this->removeValue($value);
            }
        }

        // If there are still values to add
        foreach ($dataValues as $dataValue) {
            $value = $this->createValue($attribute, $context);
            $value->setPosition(++$position);
            $this->setInternalValueData($attribute, $value, $dataValue);
            $values->add($value);
        }

        return $values;
    }
293661
public function addAttribute($attribute, $value)
    {
        $value = is_array($value) ? $value : [$value];

        if (!isset($this->attributes[$attribute])) {
            $this->attributes[$attribute] = [];
        }
        foreach ($value as $attrValue) {
            $this->attributes[$attribute][] = $attrValue;
        }

        return $this;
    }
800549
protected function isNodeChoiceAttribute($attributeValue)
    {
        return is_array($attributeValue)
        && (
            array_key_exists('contentNodeId', $attributeValue) ||
            array_key_exists('nodeName', $attributeValue) ||
            array_key_exists('nodeToLink', $attributeValue)
        );
    }
801154
public function removeValue(ValueInterface $value)
    {
        $this->values->removeElement($value);
        $value->setData(null);

        $this->removeValueByAttribute($value);

        return $this;
    }
146345
public Targeting addAttributes(String attributeName, String attributeValue){
        attributesMap.put(attributeName,attributeValue);
        return this;
    }
157837
public function createValue(AttributeInterface $attribute, array $context = null)
    {
        $this->checkAttribute($attribute);

        return $this->getFamily()->createValue($this, $attribute, $context);
    }
517129
function setAttribute( $attributeName, $attributeValue )
    {
        if ( in_array( $attributeName,
                       array( 'alternative_text',
                              'original_filename' ) ) )
        {
            $aliasList = $this->aliasList();
            foreach ( array_keys( $aliasList ) as $aliasName )
            {
                $this->setAliasAttribute( $aliasName, $attributeName, $attributeValue );
            }
            if ( $attributeName == 'alternative_text' )
            {
                $text = $this->displayText( $attributeValue );
                foreach ( array_keys( $aliasList ) as $aliasName )
                {
                    $this->setAliasAttribute( $aliasName, 'text', $text );
                }
            }
            $this->recreateDOMTree();
            $this->setStorageRequired();
            return true;
        }
        return false;
    }
214758
public function emptyValues(AttributeInterface $attribute = null, array $context = null)
    {
        $values = $this->getInternalValues($attribute, $context);
        foreach ($values as $value) {
            $this->removeValue($value);
        }

        return $this;
    }
318035
public function addValue(ValueInterface $value)
    {
        if ($value instanceof ContextualValueInterface && !$value->getContext()) {
            $value->setContext($this->getCurrentContext());
        }
        $this->getAttribute($value->getAttributeCode()); // Only to check that the attribute does exists

        $this->values->add($value);
        $value->setData($this);

        $this->addValueByAttribute($value);

        return $this;
    }
315818
public function writeAttribute(string $attributeName, string $attributeValue): XmlStreamWriter
    {
        $this->writer->writeAttribute($attributeName, $attributeValue);
        return $this;
    }
277076
public function addAttribute($attributeName, $attributeValue)
  {
    if (!array_key_exists($attributeName, $this->attributes)) {
      $this->attributes[$attributeName] = $attributeValue;
      return true;
    }
    return false;
  }
1150586
public function setDefaultValue($defaultValue): FieldInterface
    {
        if (!is_scalar($defaultValue) && !is_null($defaultValue)) {
            throw new \InvalidArgumentException(
                "invalid value provided for 'defaultValue'; ".
                "expecting either a scalar or null value"
            );
        }
        $this->defaultValue = $defaultValue;
        return $this;
    }
522116
public static function fromAttributeValues(AttributeValue ...$values): self
    {
        $attribs = array_map(
            function (AttributeValue $value) {
                return $value->toAttribute();
            }, $values);
        return new self(...$attribs);
    }
49871
protected function getValuesByAttribute(AttributeInterface $attribute)
    {
        if (null === $this->valuesByAttributes) {
            $this->valuesByAttributes = [];
        }

        if (!array_key_exists($attribute->getCode(), $this->valuesByAttributes)) {
            $this->valuesByAttributes[$attribute->getCode()] = [];
            foreach ($this->values as $value) {
                if ($value->getAttributeCode() === $attribute->getCode()) {
                    $this->addValueByAttribute($value);
                }
            }
        }

        return $this->valuesByAttributes[$attribute->getCode()];
    }