diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php index b5b7e82397d..cecedd49ec7 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php @@ -154,8 +154,9 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn $form += array('#parents' => array()); // Let each widget generate the form elements. - foreach ($entity as $name => $items) { + foreach ($this->getComponents() as $name => $options) { if ($widget = $this->getRenderer($name)) { + $items = $entity->get($name); $items->filterEmptyItems(); $form[$name] = $widget->form($items, $form, $form_state); $form[$name]['#access'] = $items->access('edit'); @@ -163,7 +164,7 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn // Assign the correct weight. This duplicates the reordering done in // processForm(), but is needed for other forms calling this method // directly. - $form[$name]['#weight'] = $this->getComponent($name)['weight']; + $form[$name]['#weight'] = $options['weight']; } } diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php index 1d62a548f32..79c0f13d72e 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php @@ -223,32 +223,32 @@ class EntityViewDisplay extends EntityDisplayBase implements EntityViewDisplayIn } // Run field formatters. - foreach ($this->getFieldDefinitions() as $field_name => $definition) { - if ($formatter = $this->getRenderer($field_name)) { + foreach ($this->getComponents() as $name => $options) { + if ($formatter = $this->getRenderer($name)) { // Group items across all entities and pass them to the formatter's // prepareView() method. $grouped_items = array(); foreach ($entities as $id => $entity) { - $items = $entity->get($field_name); + $items = $entity->get($name); $items->filterEmptyItems(); $grouped_items[$id] = $items; } $formatter->prepareView($grouped_items); // Then let the formatter build the output for each entity. - foreach ($entities as $key => $entity) { - $items = $entity->get($field_name); - $build_list[$key][$field_name] = $formatter->view($items); - $build_list[$key][$field_name]['#access'] = $items->access('view'); + foreach ($entities as $id => $entity) { + $items = $grouped_items[$id]; + $build_list[$id][$name] = $formatter->view($items); + $build_list[$id][$name]['#access'] = $items->access('view'); } } } - foreach ($entities as $key => $entity) { + foreach ($entities as $id => $entity) { // Assign the configured weights. foreach ($this->getComponents() as $name => $options) { - if (isset($build_list[$key][$name])) { - $build_list[$key][$name]['#weight'] = $options['weight']; + if (isset($build_list[$id][$name])) { + $build_list[$id][$name]['#weight'] = $options['weight']; } }