diff --git a/core/includes/entity.inc b/core/includes/entity.inc index e91eda7..1cfc9e4 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -622,7 +622,7 @@ function entity_view_multiple(array $entities, $view_mode, $langcode = NULL, $re * hidden on article nodes in the 'default' display. * @code * entity_get_display('node', 'article', 'default') - * ->setComponent('body', array( + * ->setComponent('body', 'field', array( * 'type' => 'text_summary_or_trimmed', * 'settings' => array('trim_length' => '200') * 'weight' => 1, @@ -726,11 +726,11 @@ function entity_get_render_display(EntityInterface $entity, $view_mode) { * 'default' form mode. * @code * entity_get_form_display('node', 'article', 'default') - * ->setComponent('body', array( + * ->setComponent('body', 'field', array( * 'type' => 'text_textarea_with_summary', * 'weight' => 1, * )) - * ->setComponent('field_image', array( + * ->setComponent('field_image', 'field', array( * 'type' => 'hidden', * )) * ->save(); diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 1e75646..f724fc6 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormController.php +++ b/core/lib/Drupal/Core/Entity/EntityFormController.php @@ -190,7 +190,7 @@ public function processForm($element, $form_state, $form) { // Hide or assign weights for extra fields. $extra_fields = field_info_extra_fields($this->entity->entityType(), $this->entity->bundle(), 'form'); foreach ($extra_fields as $extra_field => $info) { - $component = $this->getFormDisplay($form_state)->getComponent($extra_field); + $component = $this->getFormDisplay($form_state)->getComponent($extra_field, 'extra_field'); if (!$component) { $element[$extra_field]['#access'] = FALSE; } diff --git a/core/modules/block/block.install b/core/modules/block/block.install index ad7d0d7..9cf32b2 100644 --- a/core/modules/block/block.install +++ b/core/modules/block/block.install @@ -304,6 +304,7 @@ function block_update_8008() { // Assign form settings for the 'default' form mode. $form_display = _update_8000_entity_get_form_display('custom_block', 'basic', 'default'); $form_display->set('content.user_picture', array( + 'handler_type' => 'field', 'type' => 'text_textarea_with_summary', )) ->save(); diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index 4cf2e68..faf5eb0 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -179,14 +179,14 @@ function custom_block_add_body_field($block_type_id, $label = 'Block body') { // Assign widget settings for the 'default' form mode. entity_get_form_display('custom_block', $block_type_id, 'default') - ->setComponent('body', array( + ->setComponent('body', 'field', array( 'type' => 'text_textarea_with_summary', )) ->save(); // Assign display settings for 'default' view mode. entity_get_display('custom_block', $block_type_id, 'default') - ->setComponent('body', array( + ->setComponent('body', 'field', array( 'label' => 'hidden', 'type' => 'text_default', )) diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php index 54b5d6f..67ea7be 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php @@ -81,12 +81,12 @@ public function testBlockFields() { )); $this->instance->save(); entity_get_form_display('custom_block', 'link', 'default') - ->setComponent($this->field->getFieldName(), array( + ->setComponent($this->field->getFieldName(), 'field', array( 'type' => 'link_default', )) ->save(); entity_get_display('custom_block', 'link', 'default') - ->setComponent($this->field->getFieldName(), array( + ->setComponent($this->field->getFieldName(), 'field', array( 'type' => 'link', 'label' => 'hidden', )) diff --git a/core/modules/comment/comment.api.php b/core/modules/comment/comment.api.php index e43c577..fe5876a 100644 --- a/core/modules/comment/comment.api.php +++ b/core/modules/comment/comment.api.php @@ -99,7 +99,7 @@ function hook_comment_view(\Drupal\comment\Entity\Comment $comment, \Drupal\enti // Only do the extra work if the component is configured to be displayed. // This assumes a 'mymodule_addition' extra field has been defined for the // node type in hook_field_extra_fields(). - if ($display->getComponent('mymodule_addition')) { + if ($display->getComponent('mymodule_addition', 'extra_field')) { $comment->content['mymodule_addition'] = array( '#markup' => mymodule_addition($comment), '#theme' => 'mymodule_my_additional_field', diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 28b6b9d..c19b588 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -586,6 +586,7 @@ function comment_update_8006(&$sandbox) { // Prepare defaults for the default and full view modes. $display_options_default = array( + 'handler_type' => 'field', 'label' => 'hidden', 'type' => 'comment_default', 'settings' => array(), diff --git a/core/modules/comment/lib/Drupal/comment/CommentManager.php b/core/modules/comment/lib/Drupal/comment/CommentManager.php index 3816fc4..96602f8 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentManager.php +++ b/core/modules/comment/lib/Drupal/comment/CommentManager.php @@ -120,7 +120,7 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment', // Assign widget settings for the 'default' form mode. entity_get_form_display($entity_type, $bundle, 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'comment_default', 'weight' => 20, )) @@ -128,7 +128,7 @@ public function addDefaultField($entity_type, $bundle, $field_name = 'comment', // Set default to display comment list. entity_get_display($entity_type, $bundle, 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'label' => 'hidden', 'type' => 'comment_default', 'weight' => 20, @@ -171,14 +171,14 @@ public function addBodyField($entity_type, $field_name) { // Assign widget settings for the 'default' form mode. entity_get_form_display('comment', $comment_bundle, 'default') - ->setComponent('comment_body', array( + ->setComponent('comment_body', 'field', array( 'type' => 'text_textarea', )) ->save(); // Assign display settings for the 'default' view mode. entity_get_display('comment', $comment_bundle, 'default') - ->setComponent('comment_body', array( + ->setComponent('comment_body', 'field', array( 'label' => 'hidden', 'type' => 'text_default', 'weight' => 0, diff --git a/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php b/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php index 4feeb4f..4a790a4 100644 --- a/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php +++ b/core/modules/contact/lib/Drupal/contact/MessageViewBuilder.php @@ -24,7 +24,7 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang foreach ($entities as $entity) { // Add the message extra field, if enabled. $display = $displays[$entity->bundle()]; - if ($entity->getMessage() && $display->getComponent('message')) { + if ($entity->getMessage() && $display->getComponent('message', 'extra_field')) { $entity->content['message'] = array( '#type' => 'item', '#title' => t('Message'), diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationTestBase.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationTestBase.php index d1485d2..cdeff28 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationTestBase.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationTestBase.php @@ -182,7 +182,7 @@ protected function setupTestFields() { 'label' => 'Test translatable text-field', ))->save(); entity_get_form_display($this->entityType, $this->bundle, 'default') - ->setComponent($this->fieldName, array( + ->setComponent($this->fieldName, 'field', array( 'type' => 'text_textfield', 'weight' => 0, )) diff --git a/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php b/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php index 5bee2e3..fed40a0 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php +++ b/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php @@ -73,7 +73,7 @@ function setUp() { $this->instance->save(); entity_get_form_display($this->instance->entity_type, $this->instance->bundle, 'default') - ->setComponent($this->field->name, array( + ->setComponent($this->field->name, 'field', array( 'type' => 'datetime_default', )) ->save(); @@ -84,7 +84,7 @@ function setUp() { 'settings' => array('format_type' => 'medium'), ); entity_get_display($this->instance->entity_type, $this->instance->bundle, 'full') - ->setComponent($this->field->name, $this->display_options) + ->setComponent($this->field->getFieldName(), 'field', $this->display_options) ->save(); } @@ -130,7 +130,7 @@ function testDateField() { // Update the entity display settings. $this->display_options['settings'] = array($setting => $new_value); entity_get_display($this->instance->entity_type, $this->instance->bundle, 'full') - ->setComponent($field_name, $this->display_options) + ->setComponent($field_name, 'field', $this->display_options) ->save(); $this->renderTestEntity($id); @@ -148,7 +148,7 @@ function testDateField() { // Verify that the plain formatter works. $this->display_options['type'] = 'datetime_plain'; entity_get_display($this->instance->entity_type, $this->instance->bundle, 'full') - ->setComponent($field_name, $this->display_options) + ->setComponent($field_name, 'field', $this->display_options) ->save(); $expected = $date->format(DATETIME_DATE_STORAGE_FORMAT); $this->renderTestEntity($id); @@ -198,7 +198,7 @@ function testDatetimeField() { // Update the entity display settings. $this->display_options['settings'] = array($setting => $new_value); entity_get_display($this->instance->entity_type, $this->instance->bundle, 'full') - ->setComponent($field_name, $this->display_options) + ->setComponent($field_name, 'field', $this->display_options) ->save(); $this->renderTestEntity($id); @@ -216,7 +216,7 @@ function testDatetimeField() { // Verify that the plain formatter works. $this->display_options['type'] = 'datetime_plain'; entity_get_display($this->instance->entity_type, $this->instance->bundle, 'full') - ->setComponent($field_name, $this->display_options) + ->setComponent($field_name, 'field', $this->display_options) ->save(); $expected = $date->format(DATETIME_DATETIME_STORAGE_FORMAT); $this->renderTestEntity($id); @@ -234,7 +234,7 @@ function testDatelistWidget() { // Change the widget to a datelist widget. entity_get_form_display($this->instance->entity_type, $this->instance->bundle, 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'datetime_datelist', 'settings' => array( 'increment' => 1, diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php b/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php index 2eb3c7d..a5af6f3 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php @@ -102,20 +102,20 @@ function setUp() { ))->save(); entity_get_form_display('node', 'article', 'default') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'taxonomy_autocomplete', 'weight' => -4, )) ->save(); entity_get_display('node', 'article', 'default') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'taxonomy_term_reference_link', 'weight' => 10, )) ->save(); entity_get_display('node', 'article', 'teaser') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'taxonomy_term_reference_link', 'weight' => 10, )) diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php b/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php index eb7fef6..c92a8fc 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php @@ -76,7 +76,7 @@ function createFieldWithInstance($field_name, $type, $cardinality, $label, $inst $this->$instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => $widget_type, 'label' => $label, 'settings' => $widget_settings, @@ -84,7 +84,7 @@ function createFieldWithInstance($field_name, $type, $cardinality, $label, $inst ->save(); entity_get_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'label' => 'above', 'type' => $formatter_type, 'settings' => $formatter_settings diff --git a/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php b/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php index 60fd532..5e33242 100644 --- a/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php +++ b/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php @@ -76,7 +76,7 @@ function testEmailField() { // Create a form display for the default form mode. entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'email_default', 'settings' => array( 'placeholder' => 'example@example.com', @@ -85,7 +85,7 @@ function testEmailField() { ->save(); // Create a display for the full view mode. entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'email_mailto', )) ->save(); diff --git a/core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php b/core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php index 86b0645..126d06b 100644 --- a/core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php +++ b/core/modules/email/lib/Drupal/email/Tests/EmailItemTest.php @@ -48,7 +48,7 @@ public function setUp() { // Create a form display for the default form mode. entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent('field_email', array( + ->setComponent('field_email', 'field', array( 'type' => 'email_default', )) ->save(); diff --git a/core/modules/entity/entity.services.yml b/core/modules/entity/entity.services.yml new file mode 100644 index 0000000..81ab979 --- /dev/null +++ b/core/modules/entity/entity.services.yml @@ -0,0 +1,4 @@ +services: + plugin.manager.entity.display_component_handler: + class: Drupal\entity\Plugin\Type\DisplayComponentHandlerPluginManager + parent: default_plugin_manager diff --git a/core/modules/entity/lib/Drupal/entity/Annotation/DisplayComponent.php b/core/modules/entity/lib/Drupal/entity/Annotation/DisplayComponent.php new file mode 100644 index 0000000..7c87043 --- /dev/null +++ b/core/modules/entity/lib/Drupal/entity/Annotation/DisplayComponent.php @@ -0,0 +1,26 @@ +pluginManager = \Drupal::service('plugin.manager.field.formatter'); + $this->handlerManager = \Drupal::service('plugin.manager.entity.display_component_handler'); $this->displayContext = 'display'; parent::__construct($values, $entity_type); + + // Let the component handlers add missing components. + $handlers = $this->handlerManager->getDefinitions(); + foreach (array_keys($handlers) as $type) { + $this->getComponentHandler($type)->prepareDisplayComponents($this->content); + } + } /** * {@inheritdoc} */ - public function getRenderer($field_name) { - if (isset($this->plugins[$field_name])) { - return $this->plugins[$field_name]; - } - - // Instantiate the formatter object from the stored display properties. - if ($configuration = $this->getComponent($field_name)) { - $instance = field_info_instance($this->targetEntityType, $field_name, $this->bundle); - $formatter = $this->pluginManager->getInstance(array( - 'field_definition' => $instance, - 'view_mode' => $this->originalMode, - // No need to prepare, defaults have been merged in setComponent(). - 'prepare' => FALSE, - 'configuration' => $configuration - )); + public function getRenderer($name, $type = 'field') { + if (!isset($this->renderers[$name]) && !array_key_exists($name, $this->renderers)) { + $options = $this->getComponent($name, $type); + if ($handler = $this->getComponentHandler($type)) { + $this->renderers[$name] = $handler->getRenderer($name, $options); + } + else { + $this->renderers[$name] = NULL; + } } - else { - $formatter = NULL; - } - - // Persist the formatter object. - $this->plugins[$field_name] = $formatter; - return $formatter; + return $this->renderers[$name]; } } diff --git a/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php b/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php index 461f7ce..fd791eb 100644 --- a/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php +++ b/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php @@ -37,15 +37,23 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn */ public function __construct(array $values, $entity_type) { $this->pluginManager = \Drupal::service('plugin.manager.field.widget'); + $this->handlerManager =\Drupal::service('plugin.manager.entity.display_component_handler'); $this->displayContext = 'form'; parent::__construct($values, $entity_type); + + // Let the component handlers add missing components. + $handlers = $this->handlerManager->getDefinitions(); + foreach (array_keys($handlers) as $type) { + $this->getComponentHandler($type)->prepareDisplayComponents($this->content); + } + } /** * {@inheritdoc} */ - public function getRenderer($field_name) { + public function getRenderer($field_name, $type = 'field') { if (isset($this->plugins[$field_name])) { return $this->plugins[$field_name]; } diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php index 0278c58..c6960d5 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php @@ -95,6 +95,13 @@ protected $pluginManager; /** + * The display component handler plugin manager. + * + * @var \Drupal\entity\Plugin\Type\DisplayComponentHandlerPluginManager + */ + protected $handlerManager; + + /** * {@inheritdoc} */ public function __construct(array $values, $entity_type) { @@ -113,6 +120,9 @@ public function __construct(array $values, $entity_type) { if (!isset($this->displayContext)) { throw new \RuntimeException('Missing display context type.'); } + if (!isset($this->handlerManager)) { + throw new \RuntimeException('Missing display component handler plugin manager.'); + } parent::__construct($values, $entity_type); @@ -172,12 +182,15 @@ public function createCopy($mode) { /** * {@inheritdoc} */ - public function getComponents() { + public function getComponents($type = '') { $result = array(); foreach ($this->content as $name => $options) { if (!isset($options['visible']) || $options['visible'] == TRUE) { unset($options['visible']); $result[$name] = $options; + if (empty($type) || $options['handler_type'] == $type) { + $result[$name] = $this->getComponent($name, $options['handler_type']); + } } } return $result; @@ -186,45 +199,28 @@ public function getComponents() { /** * {@inheritdoc} */ - public function getComponent($name) { - // We always store 'extra fields', whether they are visible or hidden. - $extra_fields = field_info_extra_fields($this->targetEntityType, $this->bundle, $this->displayContext); - if (isset($extra_fields[$name])) { - // If we have explicit settings, return an array or NULL depending on - // visibility. - if (isset($this->content[$name])) { - if ($this->content[$name]['visible']) { - return array( - 'weight' => $this->content[$name]['weight'], - ); - } - else { - return NULL; - } - } - - // If no explicit settings for the extra field, look at the default - // visibility in its definition. - $definition = $extra_fields[$name]; - if (!isset($definition['visible']) || $definition['visible'] == TRUE) { - return array( - 'weight' => $definition['weight'] - ); - } - else { - return NULL; - } + public function getComponent($name, $type = 'field') { + if (!isset($this->content[$name]['handler_type']) || $this->content[$name]['handler_type'] !== $type) { + return NULL; } - if (isset($this->content[$name])) { - return $this->content[$name]; + $options = $this->content[$name]; + + if ($handler = $this->getComponentHandler($type)) { + $options = $handler->massageOut($name, $options); } + + // The 'handler_type' entry is strictly internal. + unset($options['handler_type']); + + return $options; + } /** * {@inheritdoc} */ - public function setComponent($name, array $options = array()) { + public function setComponent($name, $type = 'field', array $options = array()) { // If no weight specified, make sure the field sinks at the bottom. if (!isset($options['weight'])) { $max = $this->getHighestWeight(); @@ -238,13 +234,10 @@ public function setComponent($name, array $options = array()) { unset($this->plugins[$name]); } - // We always store 'extra fields', whether they are visible or hidden. - $extra_fields = field_info_extra_fields($this->targetEntityType, $this->bundle, $this->displayContext); - if (isset($extra_fields[$name])) { - $options['visible'] = TRUE; - } + $this->content[$name] = array('handler_type' => $type) + $options; - $this->content[$name] = $options; + // Clear the associated renderer object. + unset($this->renderers[$name]); return $this; } @@ -252,22 +245,20 @@ public function setComponent($name, array $options = array()) { /** * {@inheritdoc} */ - public function removeComponent($name) { - $extra_fields = field_info_extra_fields($this->targetEntityType, $this->bundle, $this->displayContext); - if (isset($extra_fields[$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 differenciate with those that are simply not configured - // yet. - $this->content[$name] = array( - 'visible' => FALSE, - ); + public function removeComponent($name, $type = 'field') { + if ($handler = $this->getComponentHandler($type)) { + $options = $handler->massageIn($name); + } + if (isset($options)) { + $this->content[$name] = array('handler_type' => $type) + $options; } else { unset($this->content[$name]); - unset($this->plugins[$name]); } + // Clear the associated renderer object. + unset($this->renderers[$name]); + return $this; } @@ -290,4 +281,20 @@ public function getHighestWeight() { return $weights ? max($weights) : NULL; } + /** + * {@inheritdoc} + */ + public function getComponentHandler($type) { + $handler = $this->handlerManager->getInstance(array('type' => $type)); + if ($handler) { + $handler->setContext(array( + 'entity_type' => $this->targetEntityType, + 'bundle' => $this->bundle, + 'view_mode' => $this->originalMode, + 'display_context' => $this->displayContext, + )); + } + return $handler; + } + } diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayBaseInterface.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayBaseInterface.php index 93fa3bb..4450a58 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayBaseInterface.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayBaseInterface.php @@ -31,46 +31,59 @@ public function createCopy($view_mode); /** * Gets the display options for all components. * + * @param string $type + * The type of the component (i.e. the plugin id of its + * display_component_handler). + * * @return array * The array of display options, keyed by component name. */ - public function getComponents(); + public function getComponents($type = ''); /** * Gets the display options set for a component. * * @param string $name * The name of the component. + * @param string $type + * The type of the component (i.e. the plugin id of its + * display_component_handler). * * @return array|null * The display options for the component, or NULL if the component is not * displayed. */ - public function getComponent($name); + public function getComponent($name, $type = 'field'); /** * Sets the display options for a component. * * @param string $name * The name of the component. + * @param string $type + * The type of the component (i.e. the plugin id of its + * display_component_handler). * @param array $options * The display options. * * @return \Drupal\entity\Entity\EntityDisplay * The EntityDisplay object. */ - public function setComponent($name, array $options = array()); + public function setComponent($name, $type = 'field', array $options = array()); /** * Sets a component to be hidden. * * @param string $name * The name of the component. + * @param string $type + * The type of the component (i.e. the plugin id of its + * display_component_handler). * * @return \Drupal\entity\Entity\EntityDisplay * The EntityDisplay object. */ - public function removeComponent($name); + public function removeComponent($name, $type = 'field'); /** * Returns the highest weight of the components in the display. @@ -82,14 +95,28 @@ public function removeComponent($name); public function getHighestWeight(); /** - * Returns the renderer plugin for a field (e.g. widget, formatter). + * Returns the object responsible for rendering the component. + * + * @param string $name + * The component name. + * @param string $type + * The type of the component (i.e. the plugin id of its + * display_component_handler). + * + * @return + * If the component is not hidden, the object to use for rendering it. + */ + public function getRenderer($name, $type = 'field'); + + /** + * Returns the component handler plugin for a given component type. * - * @param string $field_name - * The field name. + * @param string $type + * The component type. * - * @return \Drupal\Core\Field\PluginSettingsInterface|null - * A widget or formatter plugin or NULL if the field does not exist. + * @return \Drupal\entity\Plugin\Type\DisplayComponentHandlerBase + * The component handler plugin if it exists, NULL otherwise. */ - public function getRenderer($field_name); + public function getComponentHandler($type); } diff --git a/core/modules/entity/lib/Drupal/entity/Plugin/DisplayComponent/ExtraFieldDisplayComponentHandler.php b/core/modules/entity/lib/Drupal/entity/Plugin/DisplayComponent/ExtraFieldDisplayComponentHandler.php new file mode 100644 index 0000000..7c5c20c --- /dev/null +++ b/core/modules/entity/lib/Drupal/entity/Plugin/DisplayComponent/ExtraFieldDisplayComponentHandler.php @@ -0,0 +1,77 @@ +context['entity_type'], $this->context['bundle'], $this->context['display_context']); + foreach ($extra_fields as $name => $definition) { + if (!isset($components[$name])) { + if (!isset($definition['visible']) || $definition['visible'] == TRUE) { + $components[$name] = array( + 'visible' => TRUE, + 'weight' => $definition['weight'], + ); + } + else { + $components[$name] = array( + 'visible' => FALSE, + ); + } + + $components[$name]['handler_type'] = $this->pluginId; + } + } + // @todo : we could add a custom $display->hiddenExtraFields property on the display, and merge them back on save. + } + + /** + * {@inheritdoc} + */ + public function massageOut($name, array $options = NULL) { + // 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) { + unset($options['visible']); + return $options; + } + } + + /** + * {@inheritdoc} + */ + public function massageIn($name, array $options = NULL) { + // '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; + } +} diff --git a/core/modules/entity/lib/Drupal/entity/Plugin/Type/DisplayComponentHandlerBase.php b/core/modules/entity/lib/Drupal/entity/Plugin/Type/DisplayComponentHandlerBase.php new file mode 100644 index 0000000..b86c0ec --- /dev/null +++ b/core/modules/entity/lib/Drupal/entity/Plugin/Type/DisplayComponentHandlerBase.php @@ -0,0 +1,38 @@ +context = $context; + } + + public function prepareDisplayComponents(array &$components) { } + + public function massageOut($name, array $options = NULL) { + return $options; + } + + public function massageIn($name, array $options = NULL) { + return $options; + } + + public function getRenderer($name, array $options = NULL) { } + +} diff --git a/core/modules/entity/lib/Drupal/entity/Plugin/Type/DisplayComponentHandlerPluginManager.php b/core/modules/entity/lib/Drupal/entity/Plugin/Type/DisplayComponentHandlerPluginManager.php new file mode 100644 index 0000000..23158ac --- /dev/null +++ b/core/modules/entity/lib/Drupal/entity/Plugin/Type/DisplayComponentHandlerPluginManager.php @@ -0,0 +1,63 @@ +alterInfo($module_handler, 'display_component_handler_info'); + $this->setCacheBackend($cache_backend, $language_manager, 'display_component_handlers'); + } + + /** + * {@inheritdoc} + */ + public function getInstance(array $options) { + $plugin_id = $options['type']; + + if (!isset($this->plugins[$plugin_id]) && !array_key_exists($plugin_id, $this->plugins)) { + $this->plugins[$plugin_id] = $this->discovery->getDefinition($plugin_id) ? $this->createInstance($plugin_id) : NULL; + } + + return $this->plugins[$plugin_id]; + } + +} diff --git a/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php b/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php index 5fe5f89..2d8eb32 100644 --- a/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php +++ b/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php @@ -45,34 +45,34 @@ public function testEntityDisplayCRUD() { // being assigned. $expected['component_1'] = array('weight' => 0); $expected['component_2'] = array('weight' => 1); - $display->setComponent('component_1'); - $display->setComponent('component_2'); - $this->assertEqual($display->getComponent('component_1'), $expected['component_1']); - $this->assertEqual($display->getComponent('component_2'), $expected['component_2']); + $display->setComponent('component_1', 'default'); + $display->setComponent('component_2', 'default'); + $this->assertEqual($display->getComponent('component_1', 'default'), $expected['component_1']); + $this->assertEqual($display->getComponent('component_2', 'default'), $expected['component_2']); // Check that arbitrary options are correctly stored. $expected['component_3'] = array('weight' => 10, 'foo' => 'bar'); - $display->setComponent('component_3', $expected['component_3']); - $this->assertEqual($display->getComponent('component_3'), $expected['component_3']); + $display->setComponent('component_3', 'default', $expected['component_3']); + $this->assertEqual($display->getComponent('component_3', 'default'), $expected['component_3']); // Check that the display can be properly saved and read back. $display->save(); $display = entity_load('entity_display', $display->id()); foreach (array('component_1', 'component_2', 'component_3') as $name) { - $this->assertEqual($display->getComponent($name), $expected[$name]); + $this->assertEqual($display->getComponent($name, 'default'), $expected[$name]); } // Check that getComponents() returns options for all components. - $this->assertEqual($display->getComponents(), $expected); + $this->assertEqual($display->getComponents('default'), $expected); // Check that a component can be removed. - $display->removeComponent('component_3'); - $this->assertNULL($display->getComponent('component_3')); + $display->removeComponent('component_3', 'default'); + $this->assertNULL($display->getComponent('component_3', 'default')); // Check that the removal is correctly persisted. $display->save(); $display = entity_load('entity_display', $display->id()); - $this->assertNULL($display->getComponent('component_3')); + $this->assertNULL($display->getComponent('component_3', 'default')); // Check that CreateCopy() creates a new component that can be correclty // saved. @@ -95,14 +95,14 @@ public function testEntityGetDisplay() { $this->assertTrue($display->isNew()); // Add some components and save the display. - $display->setComponent('component_1', array('weight' => 10)) + $display->setComponent('component_1', 'default', array('weight' => 10)) ->save(); // Check that entity_get_display() returns the correct object. $display = entity_get_display('entity_test', 'entity_test', 'default'); $this->assertFalse($display->isNew()); $this->assertEqual($display->id, 'entity_test.entity_test.default'); - $this->assertEqual($display->getComponent('component_1'), array('weight' => 10)); + $this->assertEqual($display->getComponent('component_1', 'default'), array('weight' => 10)); } /** @@ -111,20 +111,20 @@ public function testEntityGetDisplay() { public function testExtraFieldComponent() { $display = entity_create('entity_display', array( 'targetEntityType' => 'entity_test', - 'bundle' => 'entity_test', + 'bundle' => 'bundle_with_extra_fields', 'mode' => 'default', )); // Check that the default visibility taken into account for extra fields // unknown in the display. - $this->assertEqual($display->getComponent('display_extra_field'), array('weight' => 5)); - $this->assertNull($display->getComponent('display_extra_field_hidden')); + $this->assertEqual($display->getComponent('display_extra_field', 'extra_field'), array('weight' => 5)); + $this->assertNull($display->getComponent('display_extra_field_hidden', 'extra_field')); // Check that setting explicit options overrides the defaults. - $display->removeComponent('display_extra_field'); - $display->setComponent('display_extra_field_hidden', array('weight' => 10)); - $this->assertNull($display->getComponent('display_extra_field')); - $this->assertEqual($display->getComponent('display_extra_field_hidden'), array('weight' => 10)); + $display->removeComponent('display_extra_field', 'extra_field'); + $display->setComponent('display_extra_field_hidden', 'extra_field', array('weight' => 10)); + $this->assertNull($display->getComponent('display_extra_field', 'extra_field')); + $this->assertEqual($display->getComponent('display_extra_field_hidden', 'extra_field'), array('weight' => 10)); } /** @@ -167,7 +167,7 @@ public function testFieldComponent() { ); $this->assertEqual($display->getComponent($field_name), $expected); - // Check that the getFormatter() method returns the correct formatter plugin. + // Check that the getRenderer() method returns the correct formatter plugin. $formatter = $display->getRenderer($field_name); $this->assertEqual($formatter->getPluginId(), $default_formatter); $this->assertEqual($formatter->getSettings(), $formatter_settings['settings']); @@ -180,7 +180,7 @@ public function testFieldComponent() { $this->assertEqual($formatter->randomValue, $random_value); // Check that changing the definition creates a new formatter. - $display->setComponent($field_name, array( + $display->setComponent($field_name, 'field', array( 'type' => 'field_test_multiple', )); $formatter = $display->getRenderer($field_name); @@ -190,7 +190,7 @@ public function testFieldComponent() { // Check that specifying an unknown formatter (e.g. case of a disabled // module) gets stored as is in the display, but results in the default // formatter being used. - $display->setComponent($field_name, array( + $display->setComponent($field_name, 'field', array( 'type' => 'unknown_formatter', )); $options = $display->getComponent($field_name); diff --git a/core/modules/entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php b/core/modules/entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php index a364b3f..0a5e4ce 100644 --- a/core/modules/entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php +++ b/core/modules/entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php @@ -39,14 +39,14 @@ public function testEntityGetFromDisplay() { $this->assertTrue($form_display->isNew()); // Add some components and save the display. - $form_display->setComponent('component_1', array('weight' => 10)) + $form_display->setComponent('component_1', 'default', array('weight' => 10)) ->save(); // Check that entity_get_form_display() returns the correct object. $form_display = entity_get_form_display('entity_test', 'entity_test', 'default'); $this->assertFalse($form_display->isNew()); $this->assertEqual($form_display->id, 'entity_test.entity_test.default'); - $this->assertEqual($form_display->getComponent('component_1'), array('weight' => 10)); + $this->assertEqual($form_display->getComponent('component_1', 'default'), array('weight' => 10)); } /** @@ -101,7 +101,7 @@ public function testFieldComponent() { $this->assertEqual($widget->randomValue, $random_value); // Check that changing the definition creates a new widget. - $form_display->setComponent($field_name, array( + $form_display->setComponent($field_name, 'field', array( 'type' => 'field_test_multiple', )); $widget = $form_display->getRenderer($field_name); @@ -111,7 +111,7 @@ public function testFieldComponent() { // Check that specifying an unknown widget (e.g. case of a disabled module) // gets stored as is in the display, but results in the default widget being // used. - $form_display->setComponent($field_name, array( + $form_display->setComponent($field_name, 'field', array( 'type' => 'unknown_widget', )); $options = $form_display->getComponent($field_name); @@ -146,12 +146,12 @@ public function testDeleteFieldInstance() { 'targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'default', - ))->setComponent($field_name)->save(); + ))->setComponent($field_name, 'field')->save(); entity_create('entity_form_display', array( 'targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'compact', - ))->setComponent($field_name)->save(); + ))->setComponent($field_name, 'field')->save(); // Check the component exists. $display = entity_get_form_display('entity_test', 'entity_test', 'default'); diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php index b2879dc..ab49eef 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php @@ -70,7 +70,7 @@ function setUp() { ->setComponent('test_field') ->save(); entity_get_form_display('node', $referencing->type, 'default') - ->setComponent('test_field', array( + ->setComponent('test_field', 'field', array( 'type' => 'entity_reference_autocomplete', )) ->save(); diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFormatterTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFormatterTest.php index 44bcca1..b45df73 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFormatterTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFormatterTest.php @@ -80,7 +80,7 @@ public function testAccess() { foreach ($formatter_manager->getOptions('entity_reference') as $formatter => $name) { // Set formatter type for the 'full' view mode. entity_get_display($this->entityType, $this->bundle, 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => $formatter, )) ->save(); diff --git a/core/modules/field/field.install b/core/modules/field/field.install index 55d6ff4..dacf333 100644 --- a/core/modules/field/field.install +++ b/core/modules/field/field.install @@ -198,6 +198,7 @@ function field_update_8002() { // Migrate 'widget' settings. if (isset($data['widget'])) { $widget_options = $data['widget']; + $widget_options['handler_type'] = 'field'; // Determine name and create initial entry in the $form_displays array. $form_display_id = $record->entity_type . '.' . $record->bundle . '.default'; if (!isset($form_displays[$form_display_id])) { @@ -206,6 +207,7 @@ function field_update_8002() { // We do not need the 'module' key anymore. unset($widget_options['module']); + $widget_options['handler_type'] = 'field'; $form_displays[$form_display_id]->set("content.$record->field_name", $widget_options); } @@ -223,6 +225,7 @@ function field_update_8002() { if ($display_options['type'] != 'hidden') { // We do not need the 'module' key anymore. unset($display_options['module']); + $display_options['handler_type'] = 'field'; $displays[$display_id]->set("content.$record->field_name", $display_options); } } @@ -274,7 +277,10 @@ function field_update_8002() { } // Set options in the display. - $new_options = array('visible' => $display_options['visible']); + $new_options = array( + 'handler_type' => 'extra_field', + 'visible' => $display_options['visible'] + ); // The display object only stores the weight for 'visible' extra // fields. if ($display_options['visible']) { diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 0d56a0a..dc07f45 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -485,7 +485,7 @@ function field_view_value(EntityInterface $entity, $field_name, $item, $display * - label: (string) Position of the label. The default 'field' theme * implementation supports the values 'inline', 'above' and 'hidden'. * Defaults to 'above'. - * - type: (string) The formatter to use. Defaults to the + * - formatter: (string) The formatter to use. Defaults to the * 'default_formatter' for the field type. The default formatter will also * be used if the requested formatter is not available. * - settings: (array) Settings specific to the formatter. Defaults to the diff --git a/core/modules/field/lib/Drupal/field/Plugin/DisplayComponent/FieldDisplayComponentHandler.php b/core/modules/field/lib/Drupal/field/Plugin/DisplayComponent/FieldDisplayComponentHandler.php new file mode 100644 index 0000000..eb2d306 --- /dev/null +++ b/core/modules/field/lib/Drupal/field/Plugin/DisplayComponent/FieldDisplayComponentHandler.php @@ -0,0 +1,50 @@ +getField($this->context['entity_type'], $name); + return \Drupal::service('plugin.manager.field.formatter')->prepareConfiguration($field['type'], $options); + } + } + + /** + * {@inheritdoc} + */ + public function getRenderer($name, array $options = NULL) { + if ($options) { + return \Drupal::service('plugin.manager.field.formatter')->getInstance(array( + 'field_definition' => Field::fieldInfo()->getInstance($this->context['entity_type'], $this->context['bundle'], $name), + 'view_mode' => $this->context['view_mode'], + 'configuration' => $options, + // No need to prepare, defaults have been merged when the options were written in the display. + 'prepare' => FALSE, + )); + } + } + +} diff --git a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php index 86e723c..22fddce 100644 --- a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php @@ -101,11 +101,11 @@ function setUp() { entity_create('field_instance', $instance)->save(); // Create a display for the default view mode. entity_get_display($instance['entity_type'], $instance['bundle'], 'default') - ->setComponent($this->field_name, $this->display_options['default']) + ->setComponent($this->field_name, 'field', $this->display_options['default']) ->save(); // Create a display for the teaser view mode. entity_get_display($instance['entity_type'], $instance['bundle'], 'teaser') - ->setComponent($this->field_name, $this->display_options['teaser']) + ->setComponent($this->field_name, 'field', $this->display_options['teaser']) ->save(); // Create an entity with values. diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php index 23e7fd1..24f733b 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php @@ -69,7 +69,7 @@ function testFieldAttachView() { 'test_formatter_setting' => $formatter_setting, ), ); - $display->setComponent($this->field->getFieldName(), $display_options); + $display->setComponent($this->field->getFieldName(), 'field', $display_options); $formatter_setting_2 = $this->randomName(); $display_options_2 = array( @@ -79,7 +79,7 @@ function testFieldAttachView() { 'test_formatter_setting' => $formatter_setting_2, ), ); - $display->setComponent($this->field_2->getFieldName(), $display_options_2); + $display->setComponent($this->field_2->getFieldName(), 'field', $display_options_2); // View all fields. field_attach_prepare_view($entity_type, array($entity->id() => $entity), $displays); @@ -100,7 +100,7 @@ function testFieldAttachView() { // Label hidden. $entity = clone($entity_init); $display_options['label'] = 'hidden'; - $display->setComponent($this->field->getFieldName(), $display_options); + $display->setComponent($this->field->getFieldName(), 'field', $display_options); field_attach_prepare_view($entity_type, array($entity->id() => $entity), $displays); $entity->content = field_attach_view($entity, $display); $output = drupal_render($entity->content); @@ -122,7 +122,7 @@ function testFieldAttachView() { // Multiple formatter. $entity = clone($entity_init); $formatter_setting = $this->randomName(); - $display->setComponent($this->field->getFieldName(), array( + $display->setComponent($this->field->getFieldName(), 'field', array( 'label' => 'above', 'type' => 'field_test_multiple', 'settings' => array( @@ -142,7 +142,7 @@ function testFieldAttachView() { // Test a formatter that uses hook_field_formatter_prepare_view(). $entity = clone($entity_init); $formatter_setting = $this->randomName(); - $display->setComponent($this->field->getFieldName(), array( + $display->setComponent($this->field->getFieldName(), 'field', array( 'label' => 'above', 'type' => 'field_test_with_prepare_view', 'settings' => array( @@ -194,7 +194,7 @@ function testFieldAttachPrepareViewMultiple() { $this->instance2->save(); $display_2 = entity_get_display('entity_test', 'test_bundle_2', 'full') - ->setComponent($this->field->getFieldName(), array( + ->setComponent($this->field->getFieldName(), 'field', array( 'type' => 'field_test_with_prepare_view', 'settings' => array( 'test_formatter_setting_additional' => $formatter_setting, diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php index d9a776b..447ab11 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php @@ -89,7 +89,7 @@ function createFieldWithInstance($suffix = '', $entity_type = 'entity_test', $bu $this->$instance->save(); entity_get_form_display($entity_type, $bundle, 'default') - ->setComponent($this->$field_name, array( + ->setComponent($this->$field_name, 'field', array( 'type' => 'test_field_widget', 'settings' => array( 'test_widget_setting' => $this->randomName(), diff --git a/core/modules/field/lib/Drupal/field/Tests/FormTest.php b/core/modules/field/lib/Drupal/field/Tests/FormTest.php index 0f57fce..6b26b73 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FormTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FormTest.php @@ -365,7 +365,7 @@ function testFieldFormMultivalueWithRequiredRadio() { ); entity_create('field_instance', $instance)->save(); entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default') - ->setComponent($instance['field_name'], array( + ->setComponent($instance['field_name'], 'field', array( 'type' => 'options_buttons', )) ->save(); @@ -453,7 +453,7 @@ function testFieldFormMultipleWidget() { entity_create('field_entity', $field)->save(); entity_create('field_instance', $this->instance)->save(); entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'test_field_widget_multiple', )) ->save(); @@ -615,7 +615,7 @@ function testHiddenField() { $this->instance->default_value = NULL; $this->instance->save(); entity_get_form_display($entity_type, $this->instance->bundle, 'default') - ->setComponent($this->instance->getFieldName(), array( + ->setComponent($this->instance->getFieldName(), 'field', array( 'type' => 'test_field_widget', )) ->save(); diff --git a/core/modules/field/lib/Drupal/field/Tests/reEnableModuleFieldTest.php b/core/modules/field/lib/Drupal/field/Tests/reEnableModuleFieldTest.php index 928adbb..e6b536c 100644 --- a/core/modules/field/lib/Drupal/field/Tests/reEnableModuleFieldTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/reEnableModuleFieldTest.php @@ -63,7 +63,7 @@ function testReEnabledField() { ))->save(); entity_get_form_display('node', 'article', 'default') - ->setComponent('field_telephone', array( + ->setComponent('field_telephone', 'field', array( 'type' => 'telephone_default', 'settings' => array( 'placeholder' => '123-456-7890', @@ -72,7 +72,7 @@ function testReEnabledField() { ->save(); entity_get_display('node', 'article', 'default') - ->setComponent('field_telephone', array( + ->setComponent('field_telephone', 'field', array( 'type' => 'telephone_link', 'weight' => 1, )) diff --git a/core/modules/field_ui/field_ui.api.php b/core/modules/field_ui/field_ui.api.php index 176993d..5dc31f1 100644 --- a/core/modules/field_ui/field_ui.api.php +++ b/core/modules/field_ui/field_ui.api.php @@ -34,7 +34,7 @@ function hook_field_formatter_settings_form_alter(&$element, &$form_state, $cont $element['mysetting'] = array( '#type' => 'checkbox', '#title' => t('My setting'), - '#default_value' => $context['formatter']->getSetting('mysetting'), + '#default_value' => $context['type']->getSetting('mysetting'), ); } } @@ -62,7 +62,7 @@ function hook_field_widget_settings_form_alter(&$element, &$form_state, $context $element['mysetting'] = array( '#type' => 'checkbox', '#title' => t('My setting'), - '#default_value' => $context['formatter']->getSetting('mysetting'), + '#default_value' => $context['type']->getSetting('mysetting'), ); } } @@ -85,9 +85,7 @@ function hook_field_formatter_settings_summary_alter(&$summary, $context) { // Append a message to the summary when an instance of foo_formatter has // mysetting set to TRUE for the current view mode. if ($context['formatter']->getPluginId() == 'foo_formatter') { - if ($context['formatter']->getSetting('mysetting')) { - $summary[] = t('My setting enabled.'); - } + $summary[] = t('My setting enabled.'); } } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php index 870df32..399b08f 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php @@ -49,8 +49,8 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, /** * {@inheritdoc} */ - protected function buildFieldRow($field_id, FieldInstanceInterface $instance, EntityDisplayBaseInterface $entity_display, array $form, array &$form_state) { - $field_row = parent::buildFieldRow($field_id, $instance, $entity_display, $form, $form_state); + protected function buildFieldRow($type, $field_id, FieldInstanceInterface $instance, EntityDisplayBaseInterface $entity_display, array $form, array &$form_state) { + $field_row = parent::buildFieldRow($type, $field_id, $instance, $entity_display, $form, $form_state); $display_options = $entity_display->getComponent($field_id); // Insert the label column. @@ -80,8 +80,8 @@ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, En /** * {@inheritdoc} */ - protected function buildExtraFieldRow($field_id, $extra_field, $entity_display) { - $extra_field_row = parent::buildExtraFieldRow($field_id, $extra_field, $entity_display); + protected function buildExtraFieldRow($type, $field_id, $extra_field, $entity_display) { + $extra_field_row = parent::buildExtraFieldRow($type, $field_id, $extra_field, $entity_display); // Insert an empty placeholder for the label column. $label = array( diff --git a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php index 06a4bdc..66060de 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php @@ -128,12 +128,12 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, // Field rows. foreach ($instances as $field_id => $instance) { - $table[$field_id] = $this->buildFieldRow($field_id, $instance, $entity_display, $form, $form_state); + $table[$field_id] = $this->buildFieldRow('field', $field_id, $instance, $entity_display, $form, $form_state); } // Non-field elements. foreach ($extra_fields as $field_id => $extra_field) { - $table[$field_id] = $this->buildExtraFieldRow($field_id, $extra_field, $entity_display); + $table[$field_id] = $this->buildExtraFieldRow('extra_field', $field_id, $extra_field, $entity_display); } $form['fields'] = $table; @@ -205,6 +205,8 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, /** * Builds the table row structure for a single field. * + * @param string $type + * The component type. * @param string $field_id * The field ID. * @param \Drupal\field\FieldInstanceInterface $instance @@ -219,7 +221,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, * @return array * A table row array. */ - protected function buildFieldRow($field_id, FieldInstanceInterface $instance, EntityDisplayBaseInterface $entity_display, array $form, array &$form_state) { + protected function buildFieldRow($type, $field_id, FieldInstanceInterface $instance, EntityDisplayBaseInterface $entity_display, array $form, array &$form_state) { $display_options = $entity_display->getComponent($field_id); $label = $instance->getFieldLabel(); @@ -391,8 +393,8 @@ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, En * @return array * A table row array. */ - protected function buildExtraFieldRow($field_id, $extra_field, $entity_display) { - $display_options = $entity_display->getComponent($field_id); + protected function buildExtraFieldRow($type, $field_id, $extra_field, $entity_display) { + $display_options = $entity_display->getComponent($field_id, $type); $extra_field_row = array( '#attributes' => array('class' => array('draggable', 'tabledrag-leaf')), @@ -491,17 +493,17 @@ public function submitForm(array &$form, array &$form_state) { $component_values['label'] = $values['label']; } - $display->setComponent($field_name, $component_values); + $display->setComponent($field_name, 'field', $component_values); } } // Collect data for 'extra' fields. foreach ($form['#extra'] as $name) { if ($form_values['fields'][$name]['type'] == 'hidden') { - $display->removeComponent($name); + $display->removeComponent($name, 'extra_field'); } else { - $display->setComponent($name, array( + $display->setComponent($name, 'extra_field', array( 'weight' => $form_values['fields'][$name]['weight'], )); } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php index 0c4877c..f02455d 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php @@ -49,8 +49,8 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, /** * {@inheritdoc} */ - protected function buildFieldRow($field_id, FieldInstanceInterface $instance, EntityDisplayBaseInterface $entity_display, array $form, array &$form_state) { - $field_row = parent::buildFieldRow($field_id, $instance, $entity_display, $form, $form_state); + protected function buildFieldRow($type, $field_id, FieldInstanceInterface $instance, EntityDisplayBaseInterface $entity_display, array $form, array &$form_state) { + $field_row = parent::buildFieldRow($type, $field_id, $instance, $entity_display, $form, $form_state); // Update the (invisible) title of the 'plugin' column. $field_row['plugin']['#title'] = $this->t('Formatter for @title', array('@title' => $instance->getFieldLabel())); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php index 502aef3..404ff23 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php @@ -402,7 +402,7 @@ function testLockedField() { 'bundle' => $this->type, ))->save(); entity_get_form_display('node', $this->type, 'default') - ->setComponent($field->id, array( + ->setComponent($field->id, 'field', array( 'type' => 'test_field_widget', )) ->save(); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php index 7edeec7..7ddcb13 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php @@ -112,7 +112,7 @@ function attachFileField($name, $entity_type, $bundle, $instance_settings = arra entity_create('field_instance', $instance)->save(); entity_get_form_display($entity_type, $bundle, 'default') - ->setComponent($name, array( + ->setComponent($name, 'field', array( 'type' => 'file_generic', 'settings' => $widget_settings, )) @@ -128,7 +128,7 @@ function updateFileField($name, $type_name, $instance_settings = array(), $widge $instance->save(); entity_get_form_display('node', $type_name, 'default') - ->setComponent($name, array( + ->setComponent($name, 'field', array( 'settings' => $widget_settings, )) ->save(); diff --git a/core/modules/forum/config/entity.display.taxonomy_term.forums.default.yml b/core/modules/forum/config/entity.display.taxonomy_term.forums.default.yml index c4d4f8b..fe8dcd4 100644 --- a/core/modules/forum/config/entity.display.taxonomy_term.forums.default.yml +++ b/core/modules/forum/config/entity.display.taxonomy_term.forums.default.yml @@ -6,5 +6,6 @@ mode: default status: 1 content: description: + handler_type: extra_field weight: '0' visible: '1' diff --git a/core/modules/forum/config/entity.form_display.taxonomy_term.forums.default.yml b/core/modules/forum/config/entity.form_display.taxonomy_term.forums.default.yml index f091e30..96a6dce 100644 --- a/core/modules/forum/config/entity.form_display.taxonomy_term.forums.default.yml +++ b/core/modules/forum/config/entity.form_display.taxonomy_term.forums.default.yml @@ -6,8 +6,10 @@ mode: default status: 1 content: name: + handler_type: extra_field weight: '-5' visible: '1' description: + handler_type: extra_field weight: '0' visible: '1' diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index 3f7d02b..150da36 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -58,20 +58,20 @@ function forum_install() { // Assign form display settings for the 'default' form mode. entity_get_form_display('node', 'forum', 'default') - ->setComponent('taxonomy_forums', array( + ->setComponent('taxonomy_forums', 'field', array( 'type' => 'options_select', )) ->save(); // Assign display settings for the 'default' and 'teaser' view modes. entity_get_display('node', 'forum', 'default') - ->setComponent('taxonomy_forums', array( + ->setComponent('taxonomy_forums', 'field', array( 'type' => 'taxonomy_term_reference_link', 'weight' => 10, )) ->save(); entity_get_display('node', 'forum', 'teaser') - ->setComponent('taxonomy_forums', array( + ->setComponent('taxonomy_forums', 'field', array( 'type' => 'taxonomy_term_reference_link', 'weight' => 10, )) diff --git a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php index d67bcad..db4c9f9 100644 --- a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php +++ b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php @@ -159,7 +159,7 @@ protected static function replaceImageStyle(ImageStyleInterface $style) { // Update display information for any instance using the image // style that was just deleted. $display_options['settings']['image_style'] = $style->id(); - $display->setComponent($field_name, $display_options) + $display->setComponent($field_name, 'field', $display_options) ->save(); } } @@ -167,7 +167,7 @@ protected static function replaceImageStyle(ImageStyleInterface $style) { $widget_configuration = $entity_form_display->getComponent($field_name); if ($widget_configuration['settings']['preview_image_style'] == $style->getOriginalId()) { $widget_options['settings']['preview_image_style'] = $style->id(); - $entity_form_display->setComponent($field_name, $widget_options) + $entity_form_display->setComponent($field_name, 'field', $widget_options) ->save(); } } diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php index 698b1bb..fa988b9 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php @@ -264,7 +264,7 @@ function testStyleReplacement() { $field_name = strtolower($this->randomName(10)); $this->createImageField($field_name, 'article'); entity_get_display('node', 'article', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'image', 'settings' => array('image_style' => $style_name), )) @@ -398,7 +398,7 @@ function testConfigImport() { $field_name = strtolower($this->randomName(10)); $this->createImageField($field_name, 'article'); entity_get_display('node', 'article', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'image', 'settings' => array('image_style' => $style_name), )) diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php index a616a4d..ee4d731 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php @@ -100,7 +100,7 @@ public function testDefaultImages() { $widget_settings = entity_get_form_display('node', $instance->bundle, 'default')->getComponent($field_name); entity_get_form_display('node', 'page', 'default') - ->setComponent($field_name, $widget_settings) + ->setComponent($field_name, 'field', $widget_settings) ->save(); entity_get_display('node', 'page', 'default') ->setComponent($field_name) diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php index 9ef2167..e68929f 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php @@ -72,7 +72,7 @@ function _testImageFieldFormatters($scheme) { 'settings' => array('image_link' => 'file'), ); $display = entity_get_display('node', $node->getType(), 'default'); - $display->setComponent($field_name, $display_options) + $display->setComponent($field_name, 'field',$display_options) ->save(); $image = array( @@ -103,7 +103,7 @@ function _testImageFieldFormatters($scheme) { // Test the image linked to content formatter. $display_options['settings']['image_link'] = 'content'; - $display->setComponent($field_name, $display_options) + $display->setComponent($field_name, 'field', $display_options) ->save(); $image = array( '#theme' => 'image', @@ -118,7 +118,7 @@ function _testImageFieldFormatters($scheme) { // Test the image style 'thumbnail' formatter. $display_options['settings']['image_link'] = ''; $display_options['settings']['image_style'] = 'thumbnail'; - $display->setComponent($field_name, $display_options) + $display->setComponent($field_name, 'field', $display_options) ->save(); // Ensure the derivative image is generated so we do not have to deal with diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php index 64523a1..7872fbd 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php @@ -88,7 +88,7 @@ function createImageField($name, $type_name, $field_settings = array(), $instanc $field_instance->save(); entity_get_form_display('node', $type_name, 'default') - ->setComponent($field['name'], array( + ->setComponent($field['name'], 'field', array( 'type' => 'image_image', 'settings' => $widget_settings, )) diff --git a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php index e71beac..6e66bef 100644 --- a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php +++ b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php @@ -81,7 +81,7 @@ function testURLValidation() { ), ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'link_default', 'settings' => array( 'placeholder_url' => 'http://example.com', @@ -89,7 +89,7 @@ function testURLValidation() { )) ->save(); entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'link', )) ->save(); @@ -156,7 +156,7 @@ function testLinkTitle() { )); $this->instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'link_default', 'settings' => array( 'placeholder_url' => 'http://example.com', @@ -165,7 +165,7 @@ function testLinkTitle() { )) ->save(); entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'link', 'label' => 'hidden', )) @@ -274,7 +274,7 @@ function testLinkFormatter() { ), ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'link_default', )) ->save(); @@ -283,7 +283,7 @@ function testLinkFormatter() { 'label' => 'hidden', ); entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($field_name, $display_options) + ->setComponent($field_name, 'field', $display_options) ->save(); // Create an entity with two link field values: @@ -339,7 +339,7 @@ function testLinkFormatter() { $display_options['settings'] = $new_value; } entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($field_name, $display_options) + ->setComponent($field_name, 'field', $display_options) ->save(); $this->renderTestEntity($id); @@ -419,12 +419,12 @@ function testLinkSeparateFormatter() { 'label' => 'hidden', ); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'link_default', )) ->save(); entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($field_name, $display_options) + ->setComponent($field_name, 'field', $display_options) ->save(); // Create an entity with two link field values: @@ -460,7 +460,7 @@ function testLinkSeparateFormatter() { // Update the field formatter settings. $display_options['settings'] = array($setting => $new_value); entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($field_name, $display_options) + ->setComponent($field_name, 'field', $display_options) ->save(); $this->renderTestEntity($id); diff --git a/core/modules/node/lib/Drupal/node/NodeViewBuilder.php b/core/modules/node/lib/Drupal/node/NodeViewBuilder.php index 036d283..8762923 100644 --- a/core/modules/node/lib/Drupal/node/NodeViewBuilder.php +++ b/core/modules/node/lib/Drupal/node/NodeViewBuilder.php @@ -65,7 +65,7 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang ); // Add Language field text element to node render array. - if ($display->getComponent('langcode')) { + if ($display->getComponent('langcode', 'extra_field')) { $entity->content['langcode'] = array( '#type' => 'item', '#title' => t('Language'), diff --git a/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php b/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php index 25036b9..08350c3 100644 --- a/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php @@ -55,7 +55,7 @@ function testMultiStepNodeFormBasicOptions() { ), ))->save(); entity_get_form_display('node', 'page', 'default') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'text_textfield', )) ->save(); diff --git a/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php index 8bd1081..35d45d2 100644 --- a/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php @@ -88,19 +88,19 @@ function setUp() { ))->save(); entity_get_form_display('node', 'page', 'default') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'taxonomy_autocomplete', )) ->save(); // Show on default display and teaser. entity_get_display('node', 'page', 'default') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'taxonomy_term_reference_link', )) ->save(); entity_get_display('node', 'page', 'teaser') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'taxonomy_term_reference_link', )) ->save(); diff --git a/core/modules/node/lib/Drupal/node/Tests/SummaryLengthTest.php b/core/modules/node/lib/Drupal/node/Tests/SummaryLengthTest.php index 9ad3373..c7f7f40 100644 --- a/core/modules/node/lib/Drupal/node/Tests/SummaryLengthTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/SummaryLengthTest.php @@ -50,7 +50,7 @@ function testSummaryLength() { $display = entity_get_display('node', $node->getType(), 'teaser'); $display_options = $display->getComponent('body'); $display_options['settings']['trim_length'] = 200; - $display->setComponent('body', $display_options) + $display->setComponent('body', 'field', $display_options) ->save(); // Render the node as a teaser again and check that the summary is now only diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php index ba67aca..100e16e 100644 --- a/core/modules/node/node.api.php +++ b/core/modules/node/node.api.php @@ -801,7 +801,7 @@ function hook_node_view(\Drupal\Core\Entity\EntityInterface $node, \Drupal\entit // Only do the extra work if the component is configured to be displayed. // This assumes a 'mymodule_addition' extra field has been defined for the // node type in hook_field_extra_fields(). - if ($display->getComponent('mymodule_addition')) { + if ($display->getComponent('mymodule_addition', 'extra_field')) { $node->content['mymodule_addition'] = array( '#markup' => mymodule_addition($node), '#theme' => 'mymodule_my_additional_field', diff --git a/core/modules/node/node.module b/core/modules/node/node.module index a860f3f..d4aa4a4 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -193,11 +193,9 @@ function node_entity_bundle_info() { function node_entity_display_alter(EntityDisplay $display, $context) { // Hide field labels in search index. if ($context['entity_type'] == 'node' && $context['view_mode'] == 'search_index') { - foreach ($display->getComponents() as $name => $options) { - if (isset($options['label'])) { - $options['label'] = 'hidden'; - $display->setComponent($name, $options); - } + foreach ($display->getComponents('field') as $name => $options) { + $options['label'] = 'hidden'; + $display->setComponent($name, 'field', $options); } } } @@ -415,20 +413,20 @@ function node_add_body_field(NodeTypeInterface $type, $label = 'Body') { // Assign widget settings for the 'default' form mode. entity_get_form_display('node', $type->type, 'default') - ->setComponent('body', array( + ->setComponent('body', 'field', array( 'type' => 'text_textarea_with_summary', )) ->save(); // Assign display settings for the 'default' and 'teaser' view modes. entity_get_display('node', $type->type, 'default') - ->setComponent('body', array( + ->setComponent('body', 'field', array( 'label' => 'hidden', 'type' => 'text_default', )) ->save(); entity_get_display('node', $type->type, 'teaser') - ->setComponent('body', array( + ->setComponent('body', 'field', array( 'label' => 'hidden', 'type' => 'text_summary_or_trimmed', )) diff --git a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php index 8a1d9b2..f964319 100644 --- a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php +++ b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php @@ -78,7 +78,7 @@ function testNumberDecimalField() { ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'number', 'settings' => array( 'placeholder' => '0.00' @@ -86,7 +86,7 @@ function testNumberDecimalField() { )) ->save(); entity_get_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'number_decimal', )) ->save(); diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php index 6607332..0ff9cbb 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php @@ -48,7 +48,7 @@ function setUp() { 'required' => TRUE, ))->save(); entity_get_form_display('entity_test_rev', 'entity_test_rev', 'default') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'options_select', )) ->save(); diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php index c00cc63..12a06f3 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php @@ -88,7 +88,7 @@ function testUpdateAllowedValues() { 'bundle' => 'entity_test', ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->fieldName, array( + ->setComponent($this->fieldName, 'field', array( 'type' => 'options_buttons', )) ->save(); diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUnitTestBase.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUnitTestBase.php index 2b70634..43daefc 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUnitTestBase.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUnitTestBase.php @@ -78,7 +78,7 @@ public function setUp() { $this->instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->fieldName, array( + ->setComponent($this->fieldName, 'field', array( 'type' => 'options_buttons', )) ->save(); diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php index 877148c..bbbd1d7 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php @@ -116,7 +116,7 @@ function testRadioButtons() { )); $instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->card_1->getFieldName(), array( + ->setComponent($this->card_1->getFieldName(), 'field', array( 'type' => 'options_buttons', )) ->save(); @@ -173,7 +173,7 @@ function testCheckBoxes() { )); $instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->card_2->getFieldName(), array( + ->setComponent($this->card_2->getFieldName(), 'field', array( 'type' => 'options_buttons', )) ->save(); @@ -264,7 +264,7 @@ function testSelectListSingle() { )); $instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->card_1->getFieldName(), array( + ->setComponent($this->card_1->getFieldName(), 'field', array( 'type' => 'options_select', )) ->save(); @@ -363,7 +363,7 @@ function testSelectListMultiple() { )); $instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->card_2->getFieldName(), array( + ->setComponent($this->card_2->getFieldName(), 'field', array( 'type' => 'options_select', )) ->save(); @@ -482,7 +482,7 @@ function testOnOffCheckbox() { 'bundle' => 'entity_test', ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->bool->getFieldName(), array( + ->setComponent($this->bool->getFieldName(), 'field', array( 'type' => 'options_onoff', )) ->save(); @@ -548,7 +548,7 @@ function testOnOffCheckboxLabelSetting() { ))->save(); entity_get_form_display('node', 'page', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'options_onoff', )) ->save(); diff --git a/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php b/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php index 7c11a6f..ce798d2 100644 --- a/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php +++ b/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php @@ -135,11 +135,10 @@ public function _testPictureFieldFormatters($scheme) { // Use the picture formatter linked to file formatter. $display_options = array( 'type' => 'picture', - 'module' => 'picture', 'settings' => array('image_link' => 'file'), ); $display = entity_get_display('node', 'article', 'default'); - $display->setComponent($field_name, $display_options) + $display->setComponent($field_name, 'field', $display_options) ->save(); $image = array( @@ -170,7 +169,7 @@ public function _testPictureFieldFormatters($scheme) { // Use the picture formatter with a picture mapping. $display_options['settings']['picture_mapping'] = 'mapping_one'; - $display->setComponent($field_name, $display_options) + $display->setComponent($field_name, 'field', $display_options) ->save(); // Output should contain all image styles and all breakpoints. @@ -185,7 +184,7 @@ public function _testPictureFieldFormatters($scheme) { // Test the fallback image style. $display_options['settings']['image_link'] = ''; $display_options['settings']['fallback_image_style'] = 'large'; - $display->setComponent($field_name, $display_options) + $display->setComponent($field_name, 'field', $display_options) ->save(); $large_style = entity_load('image_style', 'large'); diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/Field/FieldRdfaTestBase.php b/core/modules/rdf/lib/Drupal/rdf/Tests/Field/FieldRdfaTestBase.php index 29d4084..ec75166 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/Field/FieldRdfaTestBase.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/Field/FieldRdfaTestBase.php @@ -70,7 +70,7 @@ protected function assertFormatterRdfa($formatter, $property, $value, $object_ty // The field formatter will be rendered inside the entity. Set the field // formatter in the entity display options before rendering the entity. entity_get_display('entity_test', 'entity_test', 'default') - ->setComponent($this->fieldName, array('type' => $formatter)) + ->setComponent($this->fieldName, 'field', array('type' => $formatter)) ->save(); $build = entity_view($this->entity, 'default'); $output = drupal_render($build); diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/FileFieldAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/FileFieldAttributesTest.php index cc738e4..1ad79c3 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/FileFieldAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/FileFieldAttributesTest.php @@ -60,7 +60,7 @@ public function setUp() { // Set the teaser display to show this field. entity_get_display('node', 'article', 'teaser') - ->setComponent($this->fieldName, array('type' => 'file_default')) + ->setComponent($this->fieldName, 'field', array('type' => 'file_default')) ->save(); // Set the RDF mapping for the new field. diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/ImageFieldAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/ImageFieldAttributesTest.php index 14af8f6..78a3523 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/ImageFieldAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/ImageFieldAttributesTest.php @@ -86,7 +86,7 @@ function testNodeTeaser() { 'settings' => array('image_style' => 'medium', 'image_link' => 'content'), ); $display = entity_get_display('node', 'article', 'teaser'); - $display->setComponent($this->fieldName, $display_options) + $display->setComponent($this->fieldName, 'field', $display_options) ->save(); // Render the teaser. diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php index f19cff2..c0802d0 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php @@ -80,7 +80,7 @@ public function setUp() { function testNodeTeaser() { // Set the teaser display to show this field. entity_get_display('node', 'article', 'teaser') - ->setComponent($this->fieldName, array('type' => 'taxonomy_term_reference_link')) + ->setComponent($this->fieldName, 'field', array('type' => 'taxonomy_term_reference_link')) ->save(); // Create a term in each vocabulary. @@ -175,10 +175,10 @@ protected function createTaxonomyTermReferenceField($field_name, $vocabulary) { 'bundle' => 'article', ))->save(); entity_get_form_display('node', 'article', 'default') - ->setComponent($field_name, array('type' => 'options_select')) + ->setComponent($field_name, 'field', array('type' => 'options_select')) ->save(); entity_get_display('node', 'article', 'full') - ->setComponent($field_name, array('type' => 'taxonomy_term_reference_link')) + ->setComponent($field_name, 'field', array('type' => 'taxonomy_term_reference_link')) ->save(); } diff --git a/core/modules/system/entity.api.php b/core/modules/system/entity.api.php index 05f9e57..95d748d 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -447,7 +447,7 @@ function hook_entity_view(\Drupal\Core\Entity\EntityInterface $entity, \Drupal\e // Only do the extra work if the component is configured to be displayed. // This assumes a 'mymodule_addition' extra field has been defined for the // entity bundle in hook_field_extra_fields(). - if ($display->getComponent('mymodule_addition')) { + if ($display->getComponent('mymodule_addition', 'extra_field')) { $entity->content['mymodule_addition'] = array( '#markup' => mymodule_addition($entity), '#theme' => 'mymodule_my_additional_field', @@ -517,7 +517,7 @@ function hook_entity_prepare_view($entity_type, array $entities, array $displays // defined for the entity bundle in hook_field_extra_fields(). $ids = array(); foreach ($entities as $id => $entity) { - if ($displays[$entity->bundle()]->getComponent('mymodule_addition')) { + if ($displays[$entity->bundle()]->getComponent('mymodule_addition', 'extra_field')) { $ids[] = $id; } } @@ -563,11 +563,9 @@ function hook_entity_view_mode_alter(&$view_mode, Drupal\Core\Entity\EntityInter function hook_entity_display_alter(\Drupal\entity\Entity\EntityDisplay $display, array $context) { // Leave field labels out of the search index. if ($context['entity_type'] == 'node' && $context['view_mode'] == 'search_index') { - foreach ($display->getComponents() as $name => $options) { - if (isset($options['label'])) { - $options['label'] = 'hidden'; - $display->setComponent($name, $options); - } + foreach ($display->getComponents('field') as $name => $options) { + $options['label'] = 'hidden'; + $display->setComponent($name, 'field', $options); } } } @@ -612,7 +610,7 @@ function hook_entity_prepare_form(\Drupal\Core\Entity\EntityInterface $entity, $ function hook_entity_form_display_alter(\Drupal\entity\Entity\EntityFormDisplay $form_display, array $context) { // Hide the 'user_picture' field from the register form. if ($context['entity_type'] == 'user' && $context['form_mode'] == 'register') { - $form_display->setComponent('user_picture', array( + $form_display->setComponent('user_picture', 'field', array( 'type' => 'hidden', )); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php b/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php index 1e3dbd3..cfa6f0d 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php @@ -48,7 +48,7 @@ function setUp() { 'bundle' => 'page', ))->save(); entity_get_form_display('node', 'page', 'default') - ->setComponent($field_name, array('type' => 'text_default')) + ->setComponent($field_name, 'field', array('type' => 'text_default')) ->save(); // Login a user who can create 'page' nodes. diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityViewControllerTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityViewControllerTest.php index 8adf8ef..5caf89f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityViewControllerTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityViewControllerTest.php @@ -75,7 +75,7 @@ function testEntityViewController() { public function testFieldItemAttributes() { // Make sure the test field will be rendered. entity_get_display('entity_test', 'entity_test', 'default') - ->setComponent('field_test_text', array('type' => 'text_default')) + ->setComponent('field_test_text', 'field', array('type' => 'text_default')) ->save(); // Create an entity and save test value in field_test_text. diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/ArbitraryRebuildTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/ArbitraryRebuildTest.php index b09fc9b..9513773 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Form/ArbitraryRebuildTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Form/ArbitraryRebuildTest.php @@ -47,7 +47,7 @@ function setUp() { 'label' => 'Test a multiple valued field', ))->save(); entity_get_form_display('user', 'user', 'register') - ->setComponent('test_multiple', array( + ->setComponent('test_multiple', 'field', array( 'type' => 'text_textfield', 'weight' => 0, )) diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/RebuildTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/RebuildTest.php index a05e684..de1a205 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Form/RebuildTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Form/RebuildTest.php @@ -86,7 +86,7 @@ function testPreserveFormActionAfterAJAX() { ); entity_create('field_instance', $instance)->save(); entity_get_form_display('node', 'page', 'default') - ->setComponent($field_name, array('type' => 'text_test')) + ->setComponent($field_name, 'field', array('type' => 'text_test')) ->save(); // Log in a user who can create 'page' nodes. diff --git a/core/modules/system/tests/modules/entity_test/entity_test.install b/core/modules/system/tests/modules/entity_test/entity_test.install index a03acf0..a5ffa50 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.install +++ b/core/modules/system/tests/modules/entity_test/entity_test.install @@ -32,7 +32,7 @@ function entity_test_install() { ))->save(); entity_get_form_display($entity_type, $entity_type, 'default') - ->setComponent('field_test_text', array('type' => 'text_text')) + ->setComponent('field_test_text', 'field', array('type' => 'text_text')) ->save(); } } diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index 2350766..fbb9be4 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -195,7 +195,7 @@ function entity_test_entity_form_mode_info_alter(&$form_modes) { * Implements hook_field_extra_fields(). */ function entity_test_field_extra_fields() { - $extra['entity_test']['entity_test'] = array( + $extra['entity_test']['bundle_with_extra_fields'] = array( 'display' => array( // Note: those extra fields do not currently display anything, they are // just used in \Drupal\entity\Tests\EntityDisplayTest to test the @@ -428,7 +428,7 @@ function entity_test_entity_form_display_alter(EntityFormDisplay $form_display, if ($context['entity_type'] == 'entity_test') { if ($component_options = $form_display->getComponent('field_test_text')) { $component_options['settings']['size'] = 42; - $form_display->setComponent('field_test_text', $component_options); + $form_display->setComponent('field_test_text', 'field', $component_options); } } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermViewBuilder.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermViewBuilder.php index b33dbfd..367fd2d 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermViewBuilder.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermViewBuilder.php @@ -25,7 +25,7 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang foreach ($entities as $entity) { // Add the description if enabled. $display = $displays[$entity->bundle()]; - if (!empty($entity->description->value) && $display->getComponent('description')) { + if (!empty($entity->description->value) && $display->getComponent('description', 'extra_field')) { $entity->content['description'] = array( '#markup' => check_markup($entity->description->value, $entity->format->value, '', TRUE), '#prefix' => '
', diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php index e89c531..ee55a48 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php @@ -58,12 +58,12 @@ function setUp() { 'entity_type' => 'node', ))->save(); entity_get_form_display('node', 'article', 'default') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'options_select', )) ->save(); entity_get_display('node', 'article', 'default') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'taxonomy_term_reference_link', )) ->save(); @@ -88,7 +88,7 @@ function testTaxonomyRss() { // Change the format to 'RSS category'. $this->drupalGet("admin/structure/types/manage/article/display/rss"); $edit = array( - "fields[taxonomy_" . $this->vocabulary->id() . "][type]" => 'taxonomy_term_reference_rss_category', + 'fields[taxonomy_' . $this->vocabulary->id() . '][type]' => 'taxonomy_term_reference_rss_category', ); $this->drupalPostForm(NULL, $edit, t('Save')); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyImageTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyImageTest.php index db00705..d75ef55 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyImageTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyImageTest.php @@ -59,13 +59,13 @@ public function setUp() { 'settings' => array(), ))->save(); entity_get_display($entity_type, $this->vocabulary->id(), 'default') - ->setComponent($name, array( + ->setComponent($name, 'field', array( 'type' => 'image', 'settings' => array(), )) ->save(); entity_get_form_display($entity_type, $this->vocabulary->id(), 'default') - ->setComponent($name, array( + ->setComponent($name, 'field', array( 'type' => 'image_image', 'settings' => array(), )) diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php index 8007b30..db11fe9 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php @@ -66,12 +66,12 @@ function setUp() { 'bundle' => 'entity_test', ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'options_select', )) ->save(); entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'taxonomy_term_reference_link', )) ->save(); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php index 34250d6..b82f8d6 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php @@ -63,12 +63,12 @@ function setUp() { 'bundle' => 'entity_test', ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'options_select', )) ->save(); entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'taxonomy_term_reference_link', )) ->save(); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php index c7abc5c..f21bb20 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php @@ -53,12 +53,12 @@ function setUp() { 'entity_type' => 'node', ))->save(); entity_get_form_display('node', 'article', 'default') - ->setComponent($this->field_name_1, array( + ->setComponent($this->field_name_1, 'field', array( 'type' => 'options_select', )) ->save(); entity_get_display('node', 'article', 'default') - ->setComponent($this->field_name_1, array( + ->setComponent($this->field_name_1, 'field', array( 'type' => 'taxonomy_term_reference_link', )) ->save(); @@ -84,12 +84,12 @@ function setUp() { 'entity_type' => 'node', ))->save(); entity_get_form_display('node', 'article', 'default') - ->setComponent($this->field_name_2, array( + ->setComponent($this->field_name_2, 'field', array( 'type' => 'options_select', )) ->save(); entity_get_display('node', 'article', 'default') - ->setComponent($this->field_name_2, array( + ->setComponent($this->field_name_2, 'field', array( 'type' => 'taxonomy_term_reference_link', )) ->save(); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php index dcae350..7c6ceb6 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php @@ -52,12 +52,12 @@ function setUp() { )); $this->instance->save(); entity_get_form_display('node', 'article', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'options_select', )) ->save(); entity_get_display('node', 'article', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, 'field', array( 'type' => 'taxonomy_term_reference_link', )) ->save(); @@ -148,7 +148,7 @@ function testNodeTermCreationAndDeletion() { // Enable tags in the vocabulary. $instance = $this->instance; entity_get_form_display($instance->entity_type, $instance->bundle, 'default') - ->setComponent($instance->getFieldName(), array( + ->setComponent($instance->getFieldName(), 'field', array( 'type' => 'taxonomy_autocomplete', 'settings' => array( 'placeholder' => 'Start typing here.', @@ -518,7 +518,7 @@ function testReSavingTags() { // Enable tags in the vocabulary. $instance = $this->instance; entity_get_form_display($instance->entity_type, $instance->bundle, 'default') - ->setComponent($instance->getFieldName(), array( + ->setComponent($instance->getFieldName(), 'field', array( 'type' => 'taxonomy_autocomplete', )) ->save(); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php index be4ed53..0abfa2c 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php @@ -50,12 +50,12 @@ function setUp() { 'entity_type' => 'node', ))->save(); entity_get_form_display('node', 'article', 'default') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'options_select', )) ->save(); entity_get_display('node', 'article', 'default') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'taxonomy_term_reference_link', )) ->save(); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php index b44e6c5..34d201e 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php @@ -101,20 +101,20 @@ protected function mockStandardInstall() { ))->save(); entity_get_form_display('node', 'article', 'default') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'taxonomy_autocomplete', 'weight' => -4, )) ->save(); entity_get_display('node', 'article', 'default') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'taxonomy_term_reference_link', 'weight' => 10, )) ->save(); entity_get_display('node', 'article', 'teaser') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => 'taxonomy_term_reference_link', 'weight' => 10, )) diff --git a/core/modules/taxonomy/taxonomy.api.php b/core/modules/taxonomy/taxonomy.api.php index 8de2d33..fb3b3ac 100644 --- a/core/modules/taxonomy/taxonomy.api.php +++ b/core/modules/taxonomy/taxonomy.api.php @@ -263,7 +263,7 @@ function hook_taxonomy_term_view(\Drupal\taxonomy\Entity\Term $term, \Drupal\ent // Only do the extra work if the component is configured to be displayed. // This assumes a 'mymodule_addition' extra field has been defined for the // vocabulary in hook_field_extra_fields(). - if ($display->getComponent('mymodule_addition')) { + if ($display->getComponent('mymodule_addition', 'extra_field')) { $term->content['mymodule_addition'] = array( '#markup' => mymodule_addition($term), '#theme' => 'mymodule_my_additional_field', diff --git a/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneFieldTest.php b/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneFieldTest.php index 1f5ab23..757e1f7 100644 --- a/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneFieldTest.php +++ b/core/modules/telephone/lib/Drupal/telephone/Tests/TelephoneFieldTest.php @@ -65,7 +65,7 @@ function testTelephoneField() { ))->save(); entity_get_form_display('node', 'article', 'default') - ->setComponent('field_telephone', array( + ->setComponent('field_telephone', 'field', array( 'type' => 'telephone_default', 'settings' => array( 'placeholder' => '123-456-7890', @@ -74,7 +74,7 @@ function testTelephoneField() { ->save(); entity_get_display('node', 'article', 'default') - ->setComponent('field_telephone', array( + ->setComponent('field_telephone', 'field', array( 'type' => 'telephone_link', 'weight' => 1, )) diff --git a/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php b/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php index 72c0fe9..0a238c0 100644 --- a/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php @@ -86,7 +86,7 @@ function setUp() { $this->view_mode = 'default'; $this->display = entity_get_display($this->entity_type, $this->bundle, $this->view_mode) - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => $this->formatter_type, 'settings' => $this->formatter_settings, )); diff --git a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php index f209a44..62b3c2c 100644 --- a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php @@ -107,7 +107,7 @@ function _testTextfieldWidgets($field_type, $widget_type) { ), ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => $widget_type, 'settings' => array( 'placeholder' => 'A placeholder on ' . $widget_type, @@ -174,7 +174,7 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) { ), ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->field_name, array( + ->setComponent($this->field_name, 'field', array( 'type' => $widget_type, )) ->save(); diff --git a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php index d952f8c..3f51f23 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php @@ -212,7 +212,7 @@ function testRegistrationWithUserFields() { )); $instance->save(); entity_get_form_display('user', 'user', 'default') - ->setComponent('test_user_field', array('type' => 'test_field_widget')) + ->setComponent('test_user_field', 'field', array('type' => 'test_field_widget')) ->save(); entity_get_form_display('user', 'user', 'register') ->save(); @@ -223,7 +223,7 @@ function testRegistrationWithUserFields() { // Have the field appear on the registration form. entity_get_form_display('user', 'user', 'register') - ->setComponent('test_user_field', array('type' => 'test_field_widget')) + ->setComponent('test_user_field', 'field', array('type' => 'test_field_widget')) ->save(); $this->drupalGet('user/register'); diff --git a/core/modules/user/user.api.php b/core/modules/user/user.api.php index 6533c0e..a1ff50e 100644 --- a/core/modules/user/user.api.php +++ b/core/modules/user/user.api.php @@ -328,7 +328,7 @@ function hook_user_view(\Drupal\user\UserInterface $account, \Drupal\entity\Enti // Only do the extra work if the component is configured to be displayed. // This assumes a 'mymodule_addition' extra field has been defined for the // user entity type in hook_field_extra_fields(). - if ($display->getComponent('mymodule_addition')) { + if ($display->getComponent('mymodule_addition', 'extra_field')) { $account->content['mymodule_addition'] = array( '#markup' => mymodule_addition($account), '#theme' => 'mymodule_my_additional_field', diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 8f6cbe2..a02bd20 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -659,6 +659,7 @@ function user_update_8011() { // Assign form settings for the 'default' form mode. $form_display = _update_8000_entity_get_form_display('user', 'user', 'default', TRUE); $form_display->set('content.user_picture', array( + 'handler_type' => 'field', 'type' => $widget, 'settings' => array( 'progress_indicator' => 'throbber', @@ -672,6 +673,7 @@ function user_update_8011() { // Assign display settings for the 'default' and 'compact' view modes. $display = _update_8000_entity_get_display('user', 'user', 'default'); $display->set('content.user_picture', array( + 'handler_type' => 'field', 'label' => 'hidden', 'type' => $formatter, 'settings' => array( @@ -685,6 +687,7 @@ function user_update_8011() { $display = _update_8000_entity_get_display('user', 'user', 'compact'); $display->set('content.user_picture', array( + 'handler_type' => 'extra_field', 'label' => 'hidden', 'type' => $formatter, 'settings' => array( diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 5751f02..925d10b 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -515,7 +515,7 @@ function user_permission() { * Implements hook_user_view(). */ function user_user_view(UserInterface $account, EntityDisplay $display) { - if ($display->getComponent('member_for')) { + if ($display->getComponent('member_for', 'extra_field')) { $account->content['member_for'] = array( '#type' => 'item', '#title' => t('Member for'), diff --git a/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php b/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php index 8a04604..6729b8d 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php @@ -81,19 +81,19 @@ function setUp() { entity_create('field_instance', $this->tag_instance)->save(); entity_get_form_display('node', $this->node_type_with_tags->type, 'default') - ->setComponent('field_views_testing_tags', array( + ->setComponent('field_views_testing_tags', 'field', array( 'type' => 'taxonomy_autocomplete', )) ->save(); - entity_get_display('node', $this->node_type_with_tags->type, 'default') - ->setComponent('field_views_testing_tags', array( + entity_get_display('field', 'node', $this->node_type_with_tags->type, 'default') + ->setComponent('field_views_testing_tags', 'field', array( 'type' => 'taxonomy_term_reference_link', 'weight' => 10, )) ->save(); - entity_get_display('node', $this->node_type_with_tags->type, 'teaser') - ->setComponent('field_views_testing_tags', array( + entity_get_display('field', 'node', $this->node_type_with_tags->type, 'teaser') + ->setComponent('field_views_testing_tags', 'field', array( 'type' => 'taxonomy_term_reference_link', 'weight' => 10, )) @@ -191,7 +191,7 @@ function testTaggedWithByNodeType() { $instance['bundle'] = $this->node_type_without_tags->type; entity_create('field_instance', $instance)->save(); entity_get_form_display('node', $this->node_type_without_tags->type, 'default') - ->setComponent('field_views_testing_tags', array( + ->setComponent('field_views_testing_tags', 'field', array( 'type' => 'taxonomy_autocomplete', )) ->save(); diff --git a/core/profiles/standard/config/entity.display.node.article.default.yml b/core/profiles/standard/config/entity.display.node.article.default.yml index 33d77f0..8492d98 100644 --- a/core/profiles/standard/config/entity.display.node.article.default.yml +++ b/core/profiles/standard/config/entity.display.node.article.default.yml @@ -6,16 +6,19 @@ mode: default status: 1 content: body: + handler_type: field label: hidden type: text_default weight: '0' settings: { } field_tags: + handler_type: field type: taxonomy_term_reference_link weight: '10' label: above settings: { } field_image: + handler_type: field label: hidden type: image settings: diff --git a/core/profiles/standard/config/entity.display.node.article.teaser.yml b/core/profiles/standard/config/entity.display.node.article.teaser.yml index a11caae..3de681b 100644 --- a/core/profiles/standard/config/entity.display.node.article.teaser.yml +++ b/core/profiles/standard/config/entity.display.node.article.teaser.yml @@ -6,17 +6,20 @@ mode: teaser status: 1 content: body: + handler_type: field label: hidden type: text_summary_or_trimmed weight: '0' settings: trim_length: '600' field_tags: + handler_type: field type: taxonomy_term_reference_link weight: '10' label: above settings: { } field_image: + handler_type: field label: hidden type: image settings: diff --git a/core/profiles/standard/config/entity.display.user.user.compact.yml b/core/profiles/standard/config/entity.display.user.user.compact.yml index d83a3dd..971f505 100644 --- a/core/profiles/standard/config/entity.display.user.user.compact.yml +++ b/core/profiles/standard/config/entity.display.user.user.compact.yml @@ -5,6 +5,7 @@ bundle: user mode: compact content: user_picture: + handler_type: field label: hidden type: image settings: diff --git a/core/profiles/standard/config/entity.display.user.user.default.yml b/core/profiles/standard/config/entity.display.user.user.default.yml index b19d602..201c5e4 100644 --- a/core/profiles/standard/config/entity.display.user.user.default.yml +++ b/core/profiles/standard/config/entity.display.user.user.default.yml @@ -5,6 +5,7 @@ bundle: user mode: default content: user_picture: + handler_type: field label: hidden type: image settings: diff --git a/core/profiles/standard/config/entity.form_display.node.article.default.yml b/core/profiles/standard/config/entity.form_display.node.article.default.yml index f3007ac..3cb39f6 100644 --- a/core/profiles/standard/config/entity.form_display.node.article.default.yml +++ b/core/profiles/standard/config/entity.form_display.node.article.default.yml @@ -6,6 +6,7 @@ mode: default status: 1 content: body: + handler_type: field type: text_textarea_with_summary weight: '0' settings: @@ -13,6 +14,7 @@ content: summary_rows: '3' placeholder: '' field_tags: + handler_type: field type: taxonomy_autocomplete weight: '-4' settings: @@ -20,6 +22,7 @@ content: autocomplete_route_name: taxonomy.autocomplete placeholder: '' field_image: + handler_type: field type: image_image settings: progress_indicator: throbber diff --git a/core/profiles/standard/config/entity.form_display.user.user.default.yml b/core/profiles/standard/config/entity.form_display.user.user.default.yml index 0758cf6..07d7c1f 100644 --- a/core/profiles/standard/config/entity.form_display.user.user.default.yml +++ b/core/profiles/standard/config/entity.form_display.user.user.default.yml @@ -5,6 +5,7 @@ bundle: user mode: default content: user_picture: + handler_type: field type: image_image settings: progress_indicator: throbber