diff --git a/core/lib/Drupal/Core/Entity/Display/EntityViewDisplayInterface.php b/core/lib/Drupal/Core/Entity/Display/EntityViewDisplayInterface.php index 5fefc54..40f0472 100644 --- a/core/lib/Drupal/Core/Entity/Display/EntityViewDisplayInterface.php +++ b/core/lib/Drupal/Core/Entity/Display/EntityViewDisplayInterface.php @@ -21,9 +21,9 @@ * that is not automatically loaded during entity loading. It accepts an array * of entities to allow query optimization when displaying lists of entities. * - * prepareFields() and attachFields() are two halves of the same operation. It + * prepareFields() and viewFields() are two halves of the same operation. It * is safe to call prepareFields() multiple times on the same entity before - * calling attachFields() on it, but calling any Field API operation on an + * calling viewFields() on it, but calling any Field API operation on an * entity between passing that entity to these two methods may yield incorrect * results. * @@ -35,9 +35,9 @@ public function prepareFields(array $entities); /** * Returns a renderable array for the fields on an entity. * - * prepareFields() and attachFields() are two halves of the same operation. It + * prepareFields() and viewFields() are two halves of the same operation. It * is safe to call prepareFields() multiple times on the same entity before - * calling attachFields() on it, but calling any Field API operation on an + * calling viewFields() on it, but calling any Field API operation on an * entity between passing that entity to these two methods may yield incorrect * results. * @@ -47,7 +47,7 @@ public function prepareFields(array $entities); * @return array * A renderable array for the field values. */ - public function attachFields(EntityInterface $entity); + public function viewFields(EntityInterface $entity); } diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index 74fb67a..73668e5 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -120,9 +120,9 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang // Invoke hook_entity_prepare_view(). module_invoke_all('entity_prepare_view', $this->entityType, $entities, $displays, $view_mode); - // Build the field formatters. + // Let the formatters render the fields. foreach ($entities as $entity) { - $entity->content += $displays[$entity->bundle()]->attachFields($entity); + $entity->content += $displays[$entity->bundle()]->viewFields($entity); } } diff --git a/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php b/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php index ce9be8d..2b99baa 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php +++ b/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php @@ -457,7 +457,7 @@ protected function renderTestEntity($id, $view_mode = 'full', $reset = TRUE) { $entity = entity_load('entity_test', $id); $display = entity_get_display('entity_test', $entity->bundle(), 'full'); $display->prepareFields(array($entity->id() => $entity)); - $entity->content = $display->attachFields($entity); + $entity->content = $display->viewFields($entity); $output = drupal_render($entity->content); $this->drupalSetContent($output); diff --git a/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php b/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php index 9e8616b..ef919e2 100644 --- a/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php +++ b/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php @@ -111,7 +111,7 @@ function testEmailField() { // Verify that a mailto link is displayed. $entity = entity_load('entity_test', $id); $display = entity_get_display($entity->entityType(), $entity->bundle(), 'full'); - $entity->content = $display->attachFields($entity); + $entity->content = $display->viewFields($entity); $this->drupalSetContent(drupal_render($entity->content)); $this->assertLinkByHref('mailto:test@example.com'); } diff --git a/core/modules/entity/lib/Drupal/entity/Entity/EntityDisplay.php b/core/modules/entity/lib/Drupal/entity/Entity/EntityDisplay.php index 03cfcdb..50f89c0 100644 --- a/core/modules/entity/lib/Drupal/entity/Entity/EntityDisplay.php +++ b/core/modules/entity/lib/Drupal/entity/Entity/EntityDisplay.php @@ -95,7 +95,7 @@ public function prepareFields(array $entities) { /** * {@inheritdoc} */ - public function attachFields(EntityInterface $entity) { + public function viewFields(EntityInterface $entity) { $build = array(); foreach ($this->getFieldDefinitions() as $field_name => $definition) { if ($formatter = $this->getRenderer($field_name)) { @@ -111,8 +111,7 @@ public function attachFields(EntityInterface $entity) { 'view_mode' => $this->originalMode, 'display' => $this, ); - // @todo Better name for the hook ? - \Drupal::moduleHandler()->alter('field_attach_view', $build, $context); + \Drupal::moduleHandler()->alter('fields_view', $build, $context); return $build; } diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index b030af5..d7a91bb 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -360,8 +360,6 @@ function hook_field_attach_extract_form_values(\Drupal\Core\Entity\EntityInterfa /** * Perform alterations on fields being rendered in an entity. * - * This hook is invoked after the field module has performed the operation. - * * @param $output * The structured content array tree for all of the entity's fields. * @param $context @@ -370,7 +368,7 @@ function hook_field_attach_extract_form_values(\Drupal\Core\Entity\EntityInterfa * - view_mode: The view mode; for example, 'full' or 'teaser'. * - display: The EntityDisplay holding the display options. */ -function hook_field_attach_view_alter(&$output, $context) { +function field_test_fields_view_alter(&$output, $context) { // Append RDF term mappings on displayed taxonomy links. foreach (element_children($output) as $field_name) { $element = &$output[$field_name]; diff --git a/core/modules/field/field.module b/core/modules/field/field.module index a67c8c2..b4a2494 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -376,7 +376,7 @@ function field_view_value(EntityInterface $entity, $field_name, $item, $display * - Do not use inside node (or any other entity) templates; use * render($content[FIELD_NAME]) instead. * - Do not use to display all fields in an entity; use - * EntityDisplay::prepareFields() and EntityDisplay::attachFields() instead. + * EntityDisplay::prepareFields() and EntityDisplay::viewFields() instead. * - The field_view_value() function can be used to output a single formatted * field value, without label or wrapping field markup. * @@ -446,7 +446,7 @@ function field_view_field(ContentEntityInterface $entity, $field_name, $display_ } $display->prepareFields(array($entity->id() => $entity)); - $build = $display->attachFields($entity); + $build = $display->viewFields($entity); if (isset($build[$field_name])) { $output = $build[$field_name]; diff --git a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php index 02fff37..5bd5fe2 100644 --- a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php @@ -142,7 +142,7 @@ function testFieldViewField() { $this->content = drupal_render($output); $setting = $display['settings']['test_formatter_setting_multiple']; $this->assertNoText($this->label, 'Label was not displayed.'); - $this->assertText('field_test_field_attach_view_alter', 'Alter fired, display passed.'); + $this->assertText('field_test_fields_view_alter', 'Alter fired, display passed.'); $this->assertText('entity language is ' . Language::LANGCODE_NOT_SPECIFIED, 'Language is placed onto the context.'); $array = array(); foreach ($this->values as $delta => $value) { @@ -163,7 +163,7 @@ function testFieldViewField() { $this->content = $view; $setting = $display['settings']['test_formatter_setting_additional']; $this->assertNoText($this->label, 'Label was not displayed.'); - $this->assertNoText('field_test_field_attach_view_alter', 'Alter not fired.'); + $this->assertNoText('field_test_fields_view_alter', 'Alter not fired.'); foreach ($this->values as $delta => $value) { $this->assertText($setting . '|' . $value['value'] . '|' . ($value['value'] + 1), format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta))); } diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php index 3f21d2b..4679be4 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php @@ -42,7 +42,7 @@ public function setUp() { } /** - * Test EntityDisplay prepareFields() and attachFields() methods. + * Test EntityDisplay prepareFields() and viewFields() methods. */ function testFieldAttachView() { $this->createFieldWithInstance('_2'); @@ -82,7 +82,7 @@ function testFieldAttachView() { // View all fields. $display->prepareFields(array($entity->id() => $entity)); - $content = $display->attachFields($entity); + $content = $display->viewFields($entity); $output = drupal_render($content); $this->content = $output; $this->assertRaw($this->instance->getLabel(), "First field's label is displayed."); @@ -101,7 +101,7 @@ function testFieldAttachView() { $display_options['label'] = 'hidden'; $display->setComponent($this->field->getName(), $display_options); $display->prepareFields(array($entity->id() => $entity)); - $entity->content = $display->attachFields($entity); + $entity->content = $display->viewFields($entity); $output = drupal_render($entity->content); $this->content = $output; $this->assertNoRaw($this->instance->getLabel(), "Hidden label: label is not displayed."); @@ -110,7 +110,7 @@ function testFieldAttachView() { $entity = clone($entity_init); $display->removeComponent($this->field->getName()); $display->prepareFields(array($entity->id() => $entity)); - $entity->content = $display->attachFields($entity); + $entity->content = $display->viewFields($entity); $output = drupal_render($entity->content); $this->content = $output; $this->assertNoRaw($this->instance->getLabel(), "Hidden field: label is not displayed."); @@ -129,13 +129,12 @@ function testFieldAttachView() { ), )); $display->prepareFields(array($entity->id() => $entity)); - $entity->content = $display->attachFields($entity); - $output = drupal_render($entity->content); + $entity->content = $display->viewFields($entity); + $this->content = drupal_render($entity->content); $expected_output = $formatter_setting; foreach ($values as $delta => $value) { $expected_output .= "|$delta:{$value['value']}"; } - $this->content = $output; $this->assertRaw($expected_output, "Multiple formatter: all values are displayed, formatter settings are applied."); // Test a formatter that uses hook_field_formatter_prepare_view(). @@ -149,9 +148,8 @@ function testFieldAttachView() { ), )); $display->prepareFields(array($entity->id() => $entity)); - $entity->content = $display->attachFields($entity); - $output = drupal_render($entity->content); - $this->content = $output; + $entity->content = $display->viewFields($entity); + $this->content = drupal_render($entity->content); foreach ($values as $delta => $value) { $expected = $formatter_setting . '|' . $value['value'] . '|' . ($value['value'] + 1); $this->assertRaw($expected, "Value $delta is displayed, formatter settings are applied."); diff --git a/core/modules/field/tests/modules/field_test/field_test.module b/core/modules/field/tests/modules/field_test/field_test.module index a67aa4c..c942025 100644 --- a/core/modules/field/tests/modules/field_test/field_test.module +++ b/core/modules/field/tests/modules/field_test/field_test.module @@ -112,12 +112,12 @@ function field_test_field_entity_create(FieldInterface $field) { } /** - * Implements hook_field_attach_view_alter(). + * Implements hook_fields_view_alter(). */ -function field_test_field_attach_view_alter(&$output, $context) { +function field_test_fields_view_alter(&$output, $context) { $display_options = $context['display']->getComponent('test_field'); if (isset($display_options['settings']['alter'])) { - $output['test_field'][] = array('#markup' => 'field_test_field_attach_view_alter'); + $output['test_field'][] = array('#markup' => 'field_test_fields_view_alter'); } if (isset($output['test_field'])) { diff --git a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php index 0204231..1747987 100644 --- a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php +++ b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php @@ -517,7 +517,7 @@ protected function renderTestEntity($id, $view_mode = 'full', $reset = TRUE) { $entity = entity_load('entity_test', $id); $display = entity_get_display($entity->entityType(), $entity->bundle(), $view_mode); $display->prepareFields(array($entity->id() => $entity)); - $entity->content = $display->attachFields($entity); + $entity->content = $display->viewFields($entity); $output = drupal_render($entity->content); $this->drupalSetContent($output); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php index f44e120..9bd8931 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php @@ -102,7 +102,7 @@ function testTaxonomyTermFieldMultipleVocabularies() { $entity = entity_load('entity_test', $id); $display = entity_get_display($entity->entityType(), $entity->bundle(), 'full'); $display->prepareFields(array($entity->id() => $entity)); - $entity->content = $display->attachFields($entity); + $entity->content = $display->viewFields($entity); $this->content = drupal_render($entity->content); $this->assertText($term1->label(), 'Term 1 name is displayed.'); $this->assertText($term2->label(), 'Term 2 name is displayed.'); @@ -114,7 +114,7 @@ function testTaxonomyTermFieldMultipleVocabularies() { $entity = entity_load('entity_test', $id); $display = entity_get_display($entity->entityType(), $entity->bundle(), 'full'); $display->prepareFields(array($entity->id() => $entity)); - $entity->content = $display->attachFields($entity); + $entity->content = $display->viewFields($entity); $this->plainTextContent = FALSE; $this->content = drupal_render($entity->content); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php index ace8773..7908843 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php @@ -119,7 +119,7 @@ function testTaxonomyTermFieldWidgets() { $entity = entity_load('entity_test', $id); $display = entity_get_display($entity->entityType(), $entity->bundle(), 'full'); $display->prepareFields(array($entity->id() => $entity)); - $entity->content = $display->attachFields($entity); + $entity->content = $display->viewFields($entity); $this->content = drupal_render($entity->content); $this->assertText($term->label(), 'Term label is displayed.'); 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 797adef..be0f72b 100644 --- a/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php @@ -122,7 +122,7 @@ protected function createEntity($values = array()) { * The display to render the fields in. */ protected function renderEntityFields(EntityInterface $entity, EntityViewDisplayInterface $display) { - $content = $display->attachFields($entity); + $content = $display->viewFields($entity); $this->content = drupal_render($content); return $this->content; } diff --git a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php index 77de96a..3f42fba 100644 --- a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php @@ -139,7 +139,7 @@ function _testTextfieldWidgets($field_type, $widget_type) { // Display the entity. $entity = entity_load('entity_test', $id); $display = entity_get_display($entity->entityType(), $entity->bundle(), 'full'); - $entity->content = $display->attachFields($entity); + $entity->content = $display->viewFields($entity); $this->drupalSetContent(drupal_render($entity->content)); $this->assertText($value, 'Filtered tags are not displayed'); } @@ -212,7 +212,7 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) { // Display the entity. $entity = entity_load('entity_test', $id); $display = entity_get_display($entity->entityType(), $entity->bundle(), 'full'); - $entity->content = $display->attachFields($entity); + $entity->content = $display->viewFields($entity); $this->content = drupal_render($entity->content); $this->assertNoRaw($value, 'HTML tags are not displayed.'); $this->assertRaw(check_plain($value), 'Escaped HTML is displayed correctly.'); @@ -254,7 +254,7 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) { $this->container->get('entity.manager')->getStorageController('entity_test')->resetCache(array($id)); $entity = entity_load('entity_test', $id); $display = entity_get_display($entity->entityType(), $entity->bundle(), 'full'); - $entity->content = $display->attachFields($entity); + $entity->content = $display->viewFields($entity); $this->content = drupal_render($entity->content); $this->assertRaw($value, 'Value is displayed unfiltered'); }