You are here

public function FieldableEdgeEntityBase::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 FieldableEntityInterface::get

4 calls to FieldableEdgeEntityBase::get()
AttributesAwareFieldableEdgeEntityBase::get in src/Entity/AttributesAwareFieldableEdgeEntityBase.php
Gets a field item list.
FieldableEdgeEntityBase::convertFieldValueToPropertyValue in src/Entity/FieldableEdgeEntityBase.php
Converts a field value to a property value.
FieldableEdgeEntityBase::getFields in src/Entity/FieldableEdgeEntityBase.php
Gets an array of all field item lists.
FieldableEdgeEntityBase::getTranslatableFields in src/Entity/FieldableEdgeEntityBase.php
Gets an array of field item lists for translatable fields.
1 method overrides FieldableEdgeEntityBase::get()
AttributesAwareFieldableEdgeEntityBase::get in src/Entity/AttributesAwareFieldableEdgeEntityBase.php
Gets a field item list.

File

src/Entity/FieldableEdgeEntityBase.php, line 248

Class

FieldableEdgeEntityBase
Base field support for Apigee Entities without making them content entities.

Namespace

Drupal\apigee_edge\Entity

Code

public function get($field_name) {
  if (!isset($this->fields[$field_name])) {
    $value = $this
      ->getFieldValue($field_name);

    // Here field name equals the property name.
    if ($value !== NULL) {

      // Fix field value of a timestamp property field.
      if (static::propertyFieldType($field_name) === 'timestamp') {
        if (is_array($value)) {
          $value = array_map(function ($item) {

            /** @var \DateTimeImmutable $item */
            return $item
              ->getTimestamp();
          }, $value);
        }
        else {

          /** @var \DateTimeImmutable $value */
          $value = $value
            ->getTimestamp();
        }
      }
    }

    // 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];
}