diff --git a/core/lib/Drupal/Core/Entity/DisplayComponentHandlerInterface.php b/core/lib/Drupal/Core/Entity/DisplayComponentHandlerInterface.php index 675fe98..fcb886d 100644 --- a/core/lib/Drupal/Core/Entity/DisplayComponentHandlerInterface.php +++ b/core/lib/Drupal/Core/Entity/DisplayComponentHandlerInterface.php @@ -13,7 +13,7 @@ interface DisplayComponentHandlerInterface { /** - * Checks if the component handler has the passed element. + * Checks if the component handler should process the passed component. * * @param string $name * The name of a display component. @@ -24,7 +24,7 @@ public function hasElement($name); /** - * Prepares the element options before set them to storage. + * Prepares the options before they are stored. * * @param string $name * The name of a display component. @@ -55,25 +55,25 @@ public function setContext(array $context); * @param string $name * The name of a display component. * @param array $options - * An array of configuration options to instantiate render plugin. + * An array of configuration options to instantiate the render plugin. * * @return mixed - * The object to render component or null. + * The object to render the component or null. */ public function getRenderer($name, array $options); /** - * Prepares components when display created. + * Prepares components when the display gets created. * * @param array $components - * A visible display components. + * The visible display components, passed by reference. * @param array $hidden_components - * A hidden display components. + * The hidden display components, passed by reference. */ public function prepareDisplayComponents(array &$components, array &$hidden_components); /** - * Prepares the display options after they retrieved from storage. + * Prepares the display options after they are retrieved from the storage. * * @param array $properties * The entity display properties. diff --git a/core/lib/Drupal/Core/Entity/DisplayComponentHandlerPluginManager.php b/core/lib/Drupal/Core/Entity/DisplayComponentHandlerPluginManager.php index 87616d8..60d41b5 100644 --- a/core/lib/Drupal/Core/Entity/DisplayComponentHandlerPluginManager.php +++ b/core/lib/Drupal/Core/Entity/DisplayComponentHandlerPluginManager.php @@ -41,7 +41,6 @@ class DisplayComponentHandlerPluginManager extends DefaultPluginManager { */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { parent::__construct('Plugin/DisplayComponent', $namespaces, $module_handler, 'Drupal\Core\Entity\DisplayComponentHandlerInterface' , 'Drupal\Core\Entity\Annotation\DisplayComponent'); - // @todo Document the alter hook. $this->alterInfo('display_component_handler_info'); $this->setCacheBackend($cache_backend, 'display_component_handlers'); } diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php index f1bc818..1ab3651 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php @@ -9,8 +9,8 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; -use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\EntityDisplayBase; +use Drupal\Core\Entity\FieldableEntityInterface; /** * Configuration entity that contains display options for all components of a diff --git a/core/lib/Drupal/Core/Entity/Plugin/DisplayComponent/FieldDisplayComponentHandler.php b/core/lib/Drupal/Core/Entity/Plugin/DisplayComponent/FieldDisplayComponentHandler.php index 013aabd..0b51039 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/DisplayComponent/FieldDisplayComponentHandler.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DisplayComponent/FieldDisplayComponentHandler.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Entity\Plugin\DisplayComponent; +use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FormatterPluginManager; use Drupal\Core\Field\WidgetPluginManager; @@ -38,6 +39,14 @@ class FieldDisplayComponentHandler extends DisplayComponentHandlerBase implement protected $widgetPluginManager; /** + * The entity manager. + * + * @var \Drupal\Core\Entity\EntityManagerInterface + */ + protected $entityManager; + + + /** * Constructs a FieldDisplayComponentHandler object. * * @param array $configuration @@ -51,11 +60,12 @@ class FieldDisplayComponentHandler extends DisplayComponentHandlerBase implement * @param \Drupal\Core\Field\WidgetPluginManager $widget_plugin_manager * The field widget plugin manager. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, FormatterPluginManager $formatter_plugin_manager, WidgetPluginManager $widget_plugin_manager) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, FormatterPluginManager $formatter_plugin_manager, WidgetPluginManager $widget_plugin_manager, EntityManagerInterface $entity_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->formatterPluginManager = $formatter_plugin_manager; $this->widgetPluginManager = $widget_plugin_manager; + $this->entityManager = $entity_manager; } /** @@ -64,7 +74,8 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static($configuration, $plugin_id, $plugin_definition, $container->get('plugin.manager.field.formatter'), - $container->get('plugin.manager.field.widget') + $container->get('plugin.manager.field.widget'), + $container->get('entity.manager') ); } @@ -177,12 +188,10 @@ protected function getFieldDefinition($field_name) { * Returns the definitions of the fields that are candidate for display. */ protected function getFieldDefinitions() { - $entity_manager = \Drupal::entityManager(); - $entity_type = $this->context['entity_type']; $bundle = $this->context['bundle']; $display_context = $this->context['display_context']; - $definitions = $entity_manager->getFieldDefinitions($entity_type, $bundle); + $definitions = $this->entityManager->getFieldDefinitions($entity_type, $bundle); // The display only cares about fields that specify display options. // Discard base fields that are not rendered through formatters / widgets. diff --git a/core/modules/system/entity.api.php b/core/modules/system/entity.api.php index b9f60fe..1a05c6a 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -1948,3 +1948,18 @@ function hook_entity_extra_field_info_alter(&$info) { } } } + +/** + * Modify the list of available component handler plugins. + * + * This hook may be used to modify plugin properties after they have been + * specified by other modules. + * + * @param $plugins + * An array of all the existing plugin definitions, passed by reference. + * + * @see DisplayComponentHandlerPluginManager + */ +function hook_display_component_handler_info_alter(array &$plugins) { + $plugins['someplugin']['label'] = t('Better name'); +}