Issue #2450151 by yched: Don't try to render all fields (including hidden ones) for single entity display

8.0.x
catch 2015-03-12 10:08:35 +00:00
parent 287c6be209
commit 94fb2afd31
2 changed files with 13 additions and 12 deletions

View File

@ -154,8 +154,9 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn
$form += array('#parents' => array()); $form += array('#parents' => array());
// Let each widget generate the form elements. // Let each widget generate the form elements.
foreach ($entity as $name => $items) { foreach ($this->getComponents() as $name => $options) {
if ($widget = $this->getRenderer($name)) { if ($widget = $this->getRenderer($name)) {
$items = $entity->get($name);
$items->filterEmptyItems(); $items->filterEmptyItems();
$form[$name] = $widget->form($items, $form, $form_state); $form[$name] = $widget->form($items, $form, $form_state);
$form[$name]['#access'] = $items->access('edit'); $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 // Assign the correct weight. This duplicates the reordering done in
// processForm(), but is needed for other forms calling this method // processForm(), but is needed for other forms calling this method
// directly. // directly.
$form[$name]['#weight'] = $this->getComponent($name)['weight']; $form[$name]['#weight'] = $options['weight'];
} }
} }

View File

@ -223,32 +223,32 @@ class EntityViewDisplay extends EntityDisplayBase implements EntityViewDisplayIn
} }
// Run field formatters. // Run field formatters.
foreach ($this->getFieldDefinitions() as $field_name => $definition) { foreach ($this->getComponents() as $name => $options) {
if ($formatter = $this->getRenderer($field_name)) { if ($formatter = $this->getRenderer($name)) {
// Group items across all entities and pass them to the formatter's // Group items across all entities and pass them to the formatter's
// prepareView() method. // prepareView() method.
$grouped_items = array(); $grouped_items = array();
foreach ($entities as $id => $entity) { foreach ($entities as $id => $entity) {
$items = $entity->get($field_name); $items = $entity->get($name);
$items->filterEmptyItems(); $items->filterEmptyItems();
$grouped_items[$id] = $items; $grouped_items[$id] = $items;
} }
$formatter->prepareView($grouped_items); $formatter->prepareView($grouped_items);
// Then let the formatter build the output for each entity. // Then let the formatter build the output for each entity.
foreach ($entities as $key => $entity) { foreach ($entities as $id => $entity) {
$items = $entity->get($field_name); $items = $grouped_items[$id];
$build_list[$key][$field_name] = $formatter->view($items); $build_list[$id][$name] = $formatter->view($items);
$build_list[$key][$field_name]['#access'] = $items->access('view'); $build_list[$id][$name]['#access'] = $items->access('view');
} }
} }
} }
foreach ($entities as $key => $entity) { foreach ($entities as $id => $entity) {
// Assign the configured weights. // Assign the configured weights.
foreach ($this->getComponents() as $name => $options) { foreach ($this->getComponents() as $name => $options) {
if (isset($build_list[$key][$name])) { if (isset($build_list[$id][$name])) {
$build_list[$key][$name]['#weight'] = $options['weight']; $build_list[$id][$name]['#weight'] = $options['weight'];
} }
} }