X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fviews%2Fsrc%2FPlugin%2Fviews%2Ffield%2FEntityField.php;fp=web%2Fcore%2Fmodules%2Fviews%2Fsrc%2FPlugin%2Fviews%2Ffield%2FEntityField.php;h=ee2882c3b5b0b93095f9fdfedcd08414bca64b0a;hp=5ee05a24d57bd9c85889fb1c81375fe03db73ed1;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/views/src/Plugin/views/field/EntityField.php b/web/core/modules/views/src/Plugin/views/field/EntityField.php index 5ee05a24d..ee2882c3b 100644 --- a/web/core/modules/views/src/Plugin/views/field/EntityField.php +++ b/web/core/modules/views/src/Plugin/views/field/EntityField.php @@ -23,6 +23,7 @@ use Drupal\Core\TypedData\TypedDataInterface; use Drupal\views\FieldAPIHandlerTrait; use Drupal\views\Entity\Render\EntityFieldRenderer; use Drupal\views\Plugin\views\display\DisplayPluginBase; +use Drupal\views\Plugin\DependentWithRemovalPluginInterface; use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -34,7 +35,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * * @ViewsField("field") */ -class EntityField extends FieldPluginBase implements CacheableDependencyInterface, MultiItemsFieldHandlerInterface { +class EntityField extends FieldPluginBase implements CacheableDependencyInterface, MultiItemsFieldHandlerInterface, DependentWithRemovalPluginInterface { use FieldAPIHandlerTrait; use PluginDependencyTrait; @@ -315,24 +316,33 @@ class EntityField extends FieldPluginBase implements CacheableDependencyInterfac } /** - * Gets the field storage of the used field. + * Gets the field storage definition. * * @return \Drupal\Core\Field\FieldStorageDefinitionInterface + * The field storage definition used by this handler. */ protected function getFieldStorageDefinition() { $entity_type_id = $this->definition['entity_type']; $field_storage_definitions = $this->entityManager->getFieldStorageDefinitions($entity_type_id); - $field_storage = NULL; // @todo Unify 'entity field'/'field_name' instead of converting back and // forth. https://www.drupal.org/node/2410779 - if (isset($this->definition['field_name'])) { - $field_storage = $field_storage_definitions[$this->definition['field_name']]; + if (isset($this->definition['field_name']) && isset($field_storage_definitions[$this->definition['field_name']])) { + return $field_storage_definitions[$this->definition['field_name']]; } - elseif (isset($this->definition['entity field'])) { - $field_storage = $field_storage_definitions[$this->definition['entity field']]; + + if (isset($this->definition['entity field']) && isset($field_storage_definitions[$this->definition['entity field']])) { + return $field_storage_definitions[$this->definition['entity field']]; + } + + // The list of field storage definitions above does not include computed + // base fields, so we need to explicitly fetch a list of all base fields in + // order to support them. + // @see \Drupal\Core\Entity\EntityFieldManager::getFieldStorageDefinitions() + $base_fields = $this->entityManager->getBaseFieldDefinitions($entity_type_id); + if (isset($this->definition['field_name']) && isset($base_fields[$this->definition['field_name']])) { + return $base_fields[$this->definition['field_name']]->getFieldStorageDefinition(); } - return $field_storage; } /** @@ -1042,10 +1052,13 @@ class EntityField extends FieldPluginBase implements CacheableDependencyInterfac */ public function getValue(ResultRow $values, $field = NULL) { $entity = $this->getEntity($values); + // Retrieve the translated object. + $translated_entity = $this->getEntityFieldRenderer()->getEntityTranslation($entity, $values); + // Some bundles might not have a specific field, in which case the entity // (potentially a fake one) doesn't have it either. /** @var \Drupal\Core\Field\FieldItemListInterface $field_item_list */ - $field_item_list = isset($entity->{$this->definition['field_name']}) ? $entity->{$this->definition['field_name']} : NULL; + $field_item_list = isset($translated_entity->{$this->definition['field_name']}) ? $translated_entity->{$this->definition['field_name']} : NULL; if (!isset($field_item_list)) { // There isn't anything we can do without a valid field. @@ -1077,4 +1090,29 @@ class EntityField extends FieldPluginBase implements CacheableDependencyInterfac } } + /** + * {@inheritdoc} + */ + public function onDependencyRemoval(array $dependencies) { + // See if this handler is responsible for any of the dependencies being + // removed. If this is the case, indicate that this handler needs to be + // removed from the View. + $remove = FALSE; + // Get all the current dependencies for this handler. + $current_dependencies = $this->calculateDependencies(); + foreach ($current_dependencies as $group => $dependency_list) { + // Check if any of the handler dependencies match the dependencies being + // removed. + foreach ($dependency_list as $config_key) { + if (isset($dependencies[$group]) && array_key_exists($config_key, $dependencies[$group])) { + // This handlers dependency matches a dependency being removed, + // indicate that this handler needs to be removed. + $remove = TRUE; + break 2; + } + } + } + return $remove; + } + }