You are here

public function AttributesAwareFieldableEdgeEntityBase::setPropertyValue in Apigee Edge 8

Updates the property value on an entity by field name.

Parameters

string $field_name: Name of the field (which usually the name of the property.)

mixed $value: Value of the field.

Overrides FieldableEdgeEntityBase::setPropertyValue

File

src/Entity/AttributesAwareFieldableEdgeEntityBase.php, line 100

Class

AttributesAwareFieldableEdgeEntityBase
For fieldable Edge entities that can use attributes as field storage.

Namespace

Drupal\apigee_edge\Entity

Code

public function setPropertyValue(string $field_name, $value) : void {

  // If value is null, parent setPropertyValue() is going to ignore it
  // because SDK entity's simple property setters does not support parameters
  // with null value. But if field is not a base field then we have to clear
  // its value.
  if ($value === NULL && !$this
    ->getFieldDefinition($field_name) instanceof BaseFieldDefinition) {
    $this
      ->setAttributeValueFromField($field_name);
  }
  else {
    try {
      parent::setPropertyValue($field_name, $value);
    } catch (InvalidArgumentException $e) {

      // Property not found for the field, let's try to save field's value
      // as an attribute.
      $this
        ->setAttributeValueFromField($field_name);
    }
  }
}