You are here

public function AttributesAwareFieldableEdgeEntityBase::get in Apigee Edge 8

Gets a field item list.

Parameters

string $field_name: The name of the field to get; e.g., 'title' or 'name'.

Return value

\Drupal\Core\Field\FieldItemListInterface The field item list, containing the field items.

Throws

\InvalidArgumentException If an invalid field name is given.

Overrides FieldableEdgeEntityBase::get

1 call to AttributesAwareFieldableEdgeEntityBase::get()
App::get in src/Entity/App.php
Gets a field item list.
1 method overrides AttributesAwareFieldableEdgeEntityBase::get()
App::get in src/Entity/App.php
Gets a field item list.

File

src/Entity/AttributesAwareFieldableEdgeEntityBase.php, line 72

Class

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

Namespace

Drupal\apigee_edge\Entity

Code

public function get($field_name) {
  $definition = $this
    ->getFieldDefinition($field_name);

  // No field found with this name.
  if ($definition === NULL) {
    return NULL;
  }

  // Ignore base fields, because their value should be stored in entity
  // properties.
  if ($definition instanceof BaseFieldDefinition) {
    return parent::get($field_name);
  }
  if (!isset($this->fields[$field_name])) {

    /** @var \Drupal\field\Entity\FieldConfig $definition */

    // Otherwise let's try to get the value of a field from an attribute
    // on the decorated entity.
    $value = $this
      ->fieldAttributeConverter()
      ->getFieldValueFromAttribute($this->entityTypeId, $field_name, $this->decorated
      ->getAttributes());

    // Based on \Drupal\Core\Entity\ContentEntityBase::getTranslatedField().

    /** @var \Drupal\Core\Field\FieldTypePluginManagerInterface $manager */
    $manager = \Drupal::service('plugin.manager.field.field_type');
    $this->fields[$field_name] = $manager
      ->createFieldItemList($this, $field_name, $value);
  }
  return $this->fields[$field_name];
}