You are here

public function ContentEntityBase::get in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::get()
  2. 10 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::get()

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

8 calls to ContentEntityBase::get()
Comment::getThread in core/modules/comment/src/Entity/Comment.php
Returns the alphadecimal representation of the comment's place in a thread.
ContentEntityBase::getFields in core/lib/Drupal/Core/Entity/ContentEntityBase.php
Gets an array of all field item lists.
ContentEntityBase::getTranslatableFields in core/lib/Drupal/Core/Entity/ContentEntityBase.php
Gets an array of field item lists for translatable fields.
ContentEntityBase::onChange in core/lib/Drupal/Core/Entity/ContentEntityBase.php
Reacts to changes to a field.
ContentEntityBase::setDefaultLangcode in core/lib/Drupal/Core/Entity/ContentEntityBase.php
Populates the local cache for the default language code.

... See full list

File

core/lib/Drupal/Core/Entity/ContentEntityBase.php, line 566

Class

ContentEntityBase
Implements Entity Field API specific enhancements to the Entity class.

Namespace

Drupal\Core\Entity

Code

public function get($field_name) {
  if (!isset($this->fields[$field_name][$this->activeLangcode])) {
    return $this
      ->getTranslatedField($field_name, $this->activeLangcode);
  }
  return $this->fields[$field_name][$this->activeLangcode];
}