You are here

public function FieldAttributeConverter::getFieldValueFromAttribute in Apigee Edge 8

Gets field value from the related attribute.

Parameters

string $entity_type: The entity type.

string $field_name: Name of a field in Drupal.

\Apigee\Edge\Structure\AttributesProperty $attributes: Attribute property that contains the attributes on an entity.

Return value

mixed|null Field value from related attribute. It returns NULL if field does not have an attribute on the entity or its value is actually NULL.

Overrides FieldAttributeConverterInterface::getFieldValueFromAttribute

File

src/FieldAttributeConverter.php, line 111

Class

FieldAttributeConverter
Default field-attribute converter service implementation.

Namespace

Drupal\apigee_edge

Code

public function getFieldValueFromAttribute(string $entity_type, string $field_name, AttributesProperty $attributes) {
  $attribute_name = $this
    ->getAttributeName($field_name);
  if ($attributes
    ->has($attribute_name)) {
    $attribute_value = $attributes
      ->getValue($attribute_name);
    if ($formatter = $this
      ->findFieldStorageFormatter($entity_type, $field_name)) {
      return $formatter
        ->decode($attribute_value);
    }
  }
  return NULL;
}