protected ContentEntityBase::getEntityKey($key)
Gets the value of the given entity key, if defined.
Parameters
string $key: Name of the entity key, for example id, revision or bundle.
Return value
mixed The value of the entity key, NULL if not defined.
File
- core/lib/Drupal/Core/Entity/ContentEntityBase.php, line 1088
Class
- ContentEntityBase
- Implements Entity Field API specific enhancements to the Entity class.
Namespace
Drupal\Core\Entity
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | protected function getEntityKey( $key ) { // If the value is known already, return it. if (isset( $this ->entityKeys[ $key ])) { return $this ->entityKeys[ $key ]; } if (isset( $this ->translatableEntityKeys[ $key ][ $this ->activeLangcode])) { return $this ->translatableEntityKeys[ $key ][ $this ->activeLangcode]; } // Otherwise fetch the value by creating a field object. $value = NULL; if ( $this ->getEntityType()->hasKey( $key )) { $field_name = $this ->getEntityType()->getKey( $key ); $definition = $this ->getFieldDefinition( $field_name ); $property = $definition ->getFieldStorageDefinition()->getMainPropertyName(); $value = $this ->get( $field_name )-> $property ; // Put it in the right array, depending on whether it is translatable. if ( $definition ->isTranslatable()) { $this ->translatableEntityKeys[ $key ][ $this ->activeLangcode] = $value ; } else { $this ->entityKeys[ $key ] = $value ; } } else { $this ->entityKeys[ $key ] = $value ; } return $value ; } |
Please login to continue.