diff --git a/core/lib/Drupal/Core/Entity/Display/EntityDisplayInterface.php b/core/lib/Drupal/Core/Entity/Display/EntityDisplayInterface.php index 45663ac..21e67f8 100644 --- a/core/lib/Drupal/Core/Entity/Display/EntityDisplayInterface.php +++ b/core/lib/Drupal/Core/Entity/Display/EntityDisplayInterface.php @@ -90,4 +90,58 @@ public function getHighestWeight(); */ public function getRenderer($field_name); + /** + * Returns the entity type this display mode is used for. + * + * @return string + * The entity type id. + */ + public function getTargetEntityTypeId(); + + /** + * Sets the target entity type to be displayed. + * + * @param string target_entity_type_id + * The entity type to be displayed. + * + * @return $this + */ + public function setTargetEntityTypeId($target_entity_type_id); + + /** + * Return the view or form mode to be displayed. + * + * @return string + */ + public function getMode(); + + /** + * Sets the view or form mode to be displayed. + * + * @param string mode + * The new mode of this EntityDisplay + * + * @return $this + */ + public function setMode($mode); + + /** + * Return the original view or form mode that was requested (case of view/form modes + * being configured to fall back to the 'default' display). + * + * @return string + */ + public function getOriginalMode(); + + /** + * Set the original view or form mode that was requested (case of view/form modes + * being configured to fall back to the 'default' display). + * + * @param string original_mode + * The original mode of this EntityDisplay + * + * @return $this + */ + public function setOriginalMode($original_mode); + } diff --git a/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php b/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php index fe2a6c8..f57041a 100644 --- a/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php +++ b/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php @@ -184,7 +184,7 @@ public function processForm($element, $form_state, $form) { } // Hide extra fields. - $extra_fields = field_info_extra_fields($this->targetEntityType, $this->bundle, 'form'); + $extra_fields = field_info_extra_fields($this->getTargetEntityTypeId(), $this->bundle, 'form'); foreach ($extra_fields as $extra_field => $info) { if (!$this->getComponent($extra_field)) { $element[$extra_field]['#access'] = FALSE; diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php index dd1bfa0..76f6e79 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php @@ -61,6 +61,7 @@ */ public $status; + /** * List of component display options, keyed by component name. * @@ -135,7 +136,7 @@ public function __construct(array $values, $entity_type) { * {@inheritdoc} */ public function id() { - return $this->targetEntityType . '.' . $this->bundle . '.' . $this->mode; + return $this->getTargetEntityTypeId() . '.' . $this->bundle . '.' . $this->mode; } /** @@ -152,7 +153,7 @@ public function preSave(EntityStorageInterface $storage, $update = TRUE) { */ public function calculateDependencies() { parent::calculateDependencies(); - $target_entity_type = \Drupal::entityManager()->getDefinition($this->targetEntityType); + $target_entity_type = \Drupal::entityManager()->getDefinition($this->getTargetEntityTypeId()); $bundle_entity_type_id = $target_entity_type->getBundleEntityType(); if ($bundle_entity_type_id != 'bundle') { @@ -164,7 +165,7 @@ public function calculateDependencies() { // Create dependencies on both hidden and visible fields. $fields = $this->content + $this->hidden; foreach ($fields as $field_name => $component) { - $field_instance = Field::fieldInfo()->getInstance($this->targetEntityType, $this->bundle, $field_name); + $field_instance = Field::fieldInfo()->getInstance($this->getTargetEntityTypeId(), $this->bundle, $field_name); if ($field_instance) { $this->addDependency('entity', $field_instance->getConfigDependencyName()); } @@ -188,8 +189,8 @@ public function calculateDependencies() { */ public function postSave(EntityStorageInterface $storage, $update = TRUE) { // Reset the render cache for the target entity type. - if (\Drupal::entityManager()->hasController($this->targetEntityType, 'view_builder')) { - \Drupal::entityManager()->getViewBuilder($this->targetEntityType)->resetCache(); + if (\Drupal::entityManager()->hasController($this->getTargetEntityTypeId(), 'view_builder')) { + \Drupal::entityManager()->getViewBuilder($this->getTargetEntityTypeId())->resetCache(); } } @@ -236,7 +237,7 @@ public function toArray() { */ protected function init() { // Fill in defaults for extra fields. - $extra_fields = field_info_extra_fields($this->targetEntityType, $this->bundle, ($this->displayContext == 'view' ? 'display' : $this->displayContext)); + $extra_fields = field_info_extra_fields($this->getTargetEntityTypeId(), $this->bundle, ($this->displayContext == 'view' ? 'display' : $this->displayContext)); foreach ($extra_fields as $name => $definition) { if (!isset($this->content[$name]) && !isset($this->hidden[$name])) { // Extra fields are visible by default unless they explicitly say so. @@ -340,7 +341,7 @@ public function getHighestWeight() { } // Let other modules feedback about their own additions. - $weights = array_merge($weights, \Drupal::moduleHandler()->invokeAll('field_info_max_weight', array($this->targetEntityType, $this->bundle, $this->displayContext, $this->mode))); + $weights = array_merge($weights, \Drupal::moduleHandler()->invokeAll('field_info_max_weight', array($this->getTargetEntityTypeId(), $this->bundle, $this->displayContext, $this->mode))); return $weights ? max($weights) : NULL; } @@ -359,12 +360,12 @@ protected function getFieldDefinition($field_name) { protected function getFieldDefinitions() { // Entity displays are sometimes created for non-content entities. // @todo Prevent this in https://drupal.org/node/2095195. - if (!\Drupal::entityManager()->getDefinition($this->targetEntityType)->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { + if (!\Drupal::entityManager()->getDefinition($this->getTargetEntityTypeId())->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { return array(); } if (!isset($this->fieldDefinitions)) { - $definitions = \Drupal::entityManager()->getFieldDefinitions($this->targetEntityType, $this->bundle); + $definitions = \Drupal::entityManager()->getFieldDefinitions($this->getTargetEntityTypeId(), $this->bundle); // The display only cares about fields that specify display options. // Discard base fields that are not rendered through formatters / widgets. @@ -377,4 +378,47 @@ protected function getFieldDefinitions() { return $this->fieldDefinitions; } + /** + * {@inheritdoc} + */ + public function getTargetEntityTypeId() { + return $this->targetEntityType; + } + + /** + * {@inheritdoc} + */ + public function setTargetEntityTypeId($target_entity_type_id) { + $this->set('targetEntityType', $target_entity_type_id); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getMode() { + return $this->get('mode'); + } + /** + * {@inheritdoc} + */ + public function setMode($mode) { + $this->set('mode', $mode); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getOriginalMode() { + return $this->get('originalMode'); + } + + /** + * {@inheritdoc} + */ + public function setOriginalMode($original_mode) { + $this->set('originalMode', $original_mode); + return $this; + } }