diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php index ca8cc92..37c8ae7 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php @@ -210,7 +210,7 @@ public function getComponent($name) { $options = $this->content[$name]; if ($handler = $this->getComponentHandler($type)) { - $options = $handler->massageOut($name, $options); + $options = $handler->onComponentGet($name, $options); } // The 'handler_type' entry is strictly internal. @@ -231,7 +231,7 @@ public function setComponent($name, $type = 'field', array $options = array()) { } if ($handler = $this->getComponentHandler($type)) { - $options = $handler->massageIn($name, $options); + $options = $handler->onComponentSet($name, $options); } $this->content[$name] = array('handler_type' => $type) + $options; @@ -252,10 +252,8 @@ public function removeComponent($name) { $type = $this->content[$name]['handler_type']; if ($handler = $this->getComponentHandler($type)) { - $options = $handler->massageIn($name); + $options = $handler->onComponentRemove($name); } - // Some component handlers may need to store their components in display and - // use own logic to manage removed components. For example extra fields. if (isset($options)) { $this->content[$name] = array('handler_type' => $type) + $options; } diff --git a/core/modules/entity/lib/Drupal/entity/Plugin/DisplayComponent/ExtraFieldDisplayComponentHandler.php b/core/modules/entity/lib/Drupal/entity/Plugin/DisplayComponent/ExtraFieldDisplayComponentHandler.php index b010931..ce9a51e 100644 --- a/core/modules/entity/lib/Drupal/entity/Plugin/DisplayComponent/ExtraFieldDisplayComponentHandler.php +++ b/core/modules/entity/lib/Drupal/entity/Plugin/DisplayComponent/ExtraFieldDisplayComponentHandler.php @@ -86,7 +86,7 @@ public function prepareDisplayComponents(array &$components) { /** * {@inheritdoc} */ - public function massageOut($name, array $options = NULL) { + public function onComponentGet($name, array $options = array()) { // We always store 'extra fields', whether they are visible or hidden. Only // return an options array for visible components. if (!isset($options['visible']) || $options['visible'] == TRUE) { @@ -98,19 +98,20 @@ public function massageOut($name, array $options = NULL) { /** * {@inheritdoc} */ - public function massageIn($name, array $options = NULL) { + public function onComponentSet($name, array $options = array()) { + // All 'Extra fields' are visible by default. + return array('visible' => TRUE); + } + + /** + * {@inheritdoc} + */ + public function onComponentRemove($name) { // 'Extra fields' are exposed in hooks and can appear at any given time. // Therefore we store extra fields that are explicitly being hidden, so // that we can differentiate with those that are simply not configured // yet. - if (is_null($options)) { - $options['visible'] = FALSE; - } - else { - $options['visible'] = TRUE; - } - - return $options; + return array('visible' => FALSE); } } diff --git a/core/modules/entity/lib/Drupal/entity/Plugin/Type/DisplayComponentHandlerBase.php b/core/modules/entity/lib/Drupal/entity/Plugin/Type/DisplayComponentHandlerBase.php index 25df81e..94855ce 100644 --- a/core/modules/entity/lib/Drupal/entity/Plugin/Type/DisplayComponentHandlerBase.php +++ b/core/modules/entity/lib/Drupal/entity/Plugin/Type/DisplayComponentHandlerBase.php @@ -31,40 +31,75 @@ public function setContext(array $context) { } /** - * @todo + * Prepares display components. + * + * Allows handlers to inject additions components to display on display load. + * + * @see \Drupal\entity\Plugin\DisplayComponent\ExtraFieldDisplayComponentHandler::prepareDisplayComponents() * * @param array $components + * Display components stored in the display. */ public function prepareDisplayComponents(array &$components) { } /** - * @todo + * Processes component options when retrieved from display. * * @param string $name + * The component name. * @param array $options + * The component options stored in display. + * * @return array + * Processed component options. */ - public function massageOut($name, array $options = NULL) { + public function onComponentGet($name, array $options = array()) { return $options; } /** - * @todo + * Processes component options before storing in display. * * @param string $name + * The component name. * @param array $options + * The component options to be stored in display. + * * @return array + * Processed component options to store in display. */ - public function massageIn($name, array $options = NULL) { + public function onComponentSet($name, array $options = array()) { return $options; } /** - * @todo + * Processes component on removal. + * + * Some component handlers may need to prevent removal their components from + * display and use their internal logic to manage removed components. + * + * @see \Drupal\entity\Plugin\DisplayComponent\ExtraFieldDisplayComponentHandler::onComponentRemove() + * + * @param string $name + * The component name. + * + * @return NULL|array + * To prevent removal component handlers should return array of options. + */ + public function onComponentRemove($name) { + } + + /** + * Returns the object responsible for rendering the component. * * @param string $name + * The component name. * @param array $options + * Array of options to initialize rendering plugin. + * + * @return object|null + * Instantiated render object or NULL when component is hidden. */ public function getRenderer($name, array $options = NULL) { } diff --git a/core/modules/field/lib/Drupal/field/Plugin/DisplayComponent/FieldDisplayComponentHandler.php b/core/modules/field/lib/Drupal/field/Plugin/DisplayComponent/FieldDisplayComponentHandler.php index 217e12a..8d86609 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/DisplayComponent/FieldDisplayComponentHandler.php +++ b/core/modules/field/lib/Drupal/field/Plugin/DisplayComponent/FieldDisplayComponentHandler.php @@ -83,12 +83,10 @@ public static function create(ContainerInterface $container, array $configuratio /** * {@inheritdoc} */ - public function massageIn($name, array $options = array()) { + public function onComponentSet($name, array $options = array()) { $field = $this->fieldInfo->getField($this->context['entity_type'], $name); - if (!$field) { - // The field in process of removal from display. - return $options; - } + // @todo Is there a reason to check field or instance existence. + // Prepare configuration on render plugin to not prepare on render. if ($this->context['display_context'] == 'display') { return $this->formatterPluginManager->prepareConfiguration($field->getFieldType(), $options); }