trait FieldAPIHandlerTrait
Same name in other branches
- 9 core/modules/views/src/FieldAPIHandlerTrait.php \Drupal\views\FieldAPIHandlerTrait
- 10 core/modules/views/src/FieldAPIHandlerTrait.php \Drupal\views\FieldAPIHandlerTrait
- 11.x core/modules/views/src/FieldAPIHandlerTrait.php \Drupal\views\FieldAPIHandlerTrait
A trait containing helper methods for field definitions.
Hierarchy
- trait \Drupal\views\FieldAPIHandlerTrait
7 files declare their use of FieldAPIHandlerTrait
- Date.php in core/
modules/ datetime/ src/ Plugin/ views/ sort/ Date.php - Date.php in core/
modules/ datetime/ src/ Plugin/ views/ filter/ Date.php - Date.php in core/
modules/ datetime/ src/ Plugin/ views/ argument/ Date.php - EntityField.php in core/
modules/ views/ src/ Plugin/ views/ field/ EntityField.php - ListField.php in core/
modules/ options/ src/ Plugin/ views/ filter/ ListField.php
File
-
core/
modules/ views/ src/ FieldAPIHandlerTrait.php, line 10
Namespace
Drupal\viewsView source
trait FieldAPIHandlerTrait {
/**
* The field definition.
*
* @var \Drupal\Core\Field\FieldDefinitionInterface
*/
protected $fieldDefinition;
/**
* The field storage definition.
*
* @var \Drupal\field\FieldStorageConfigInterface
*/
protected $fieldStorageDefinition;
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* Gets the field definition.
*
* A View works on an entity type across bundles, and thus only has access to
* field storage definitions. In order to be able to use widgets and
* formatters, we create a generic field definition out of that storage
* definition.
*
* @see BaseFieldDefinition::createFromFieldStorageDefinition()
*
* @return \Drupal\Core\Field\FieldDefinitionInterface
* The field definition used by this handler.
*/
protected function getFieldDefinition() {
if (!$this->fieldDefinition) {
$field_storage_config = $this->getFieldStorageDefinition();
$this->fieldDefinition = BaseFieldDefinition::createFromFieldStorageDefinition($field_storage_config);
}
return $this->fieldDefinition;
}
/**
* Gets the field storage configuration.
*
* @return \Drupal\field\FieldStorageConfigInterface
* The field storage definition used by this handler
*/
protected function getFieldStorageDefinition() {
if (!$this->fieldStorageDefinition) {
$field_storage_definitions = $this->getEntityFieldManager()
->getFieldStorageDefinitions($this->definition['entity_type']);
$this->fieldStorageDefinition = $field_storage_definitions[$this->definition['field_name']];
}
return $this->fieldStorageDefinition;
}
/**
* Returns the entity manager.
*
* @return \Drupal\Core\Entity\EntityManagerInterface
* The entity manager service.
*
* @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use
* \Drupal\views\FieldAPIHandlerTrait::getEntityFieldManager() instead.
*
* @see https://www.drupal.org/node/2549139
*/
protected function getEntityManager() {
@trigger_error(__METHOD__ . ' is deprecated in drupal:8.8.0 and is removed in drupal:9.0.0. Use \\Drupal\\views\\FieldAPIHandlerTrait::getEntityFieldManager() instead. See https://www.drupal.org/node/2549139', E_USER_DEPRECATED);
if (!isset($this->entityManager)) {
$this->entityManager = \Drupal::entityManager();
}
return $this->entityManager;
}
/**
* Returns the entity field manager.
*
* @return \Drupal\Core\Entity\EntityManagerInterface
* The entity field manager.
*/
protected function getEntityFieldManager() {
if (!isset($this->entityFieldManager)) {
$this->entityFieldManager = \Drupal::service('entity_field.manager');
}
return $this->entityFieldManager;
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|---|
FieldAPIHandlerTrait::$entityFieldManager | protected | property | The entity field manager. | ||
FieldAPIHandlerTrait::$fieldDefinition | protected | property | The field definition. | ||
FieldAPIHandlerTrait::$fieldStorageDefinition | protected | property | The field storage definition. | ||
FieldAPIHandlerTrait::getEntityFieldManager | protected | function | Returns the entity field manager. | ||
FieldAPIHandlerTrait::getEntityManager | Deprecated | protected | function | Returns the entity manager. | |
FieldAPIHandlerTrait::getFieldDefinition | protected | function | Gets the field definition. | ||
FieldAPIHandlerTrait::getFieldStorageDefinition | protected | function | Gets the field storage configuration. | 1 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.