Commit da60ebc3 authored by Dries's avatar Dries

Issue #2028175 by effulgentsia: Finish the removal of non-formatter's prepareView().

parent 74c0f3f1
......@@ -177,9 +177,4 @@ public function delete() { }
*/
public function deleteRevision() { }
/**
* {@inheritdoc}
*/
public static function prepareView(array $entities_items) { }
}
......@@ -776,21 +776,11 @@ function field_view_field(EntityInterface $entity, $field_name, $display_options
$items = \Drupal::typedData()->create($definitions[$field_name], $itemsBC, $field_name, $entity);
}
// Invoke prepare_view steps if needed.
// Invoke the formatter's prepareView() and view() methods.
$id = $entity->id();
// First let the field type do its preparation. prepareView() is a static
// method.
$type_definition = \Drupal::typedData()->getDefinition($definition['type']);
$class = $type_definition['class'];
$class::prepareView(array($id => $items), $definition);
// Then let the formatter do its own specific massaging.
$itemsBC_multi = array($id => $items->getValue());
$formatter->prepareView(array($id => $entity), $display_langcode, $itemsBC_multi);
$itemsBC = $itemsBC_multi[$id];
// Build the renderable array.
$result = $formatter->view($entity, $display_langcode, $itemsBC);
// Invoke hook_field_attach_view_alter() to let other modules alter the
......
......@@ -53,9 +53,6 @@ public function settingsSummary();
* field that displays properties of the referenced entities such as name or
* type.
*
* This method is called after the field type's implementation of
* hook_field_prepare_view().
*
* This method operates on multiple entities. The $entities and $items
* parameters are arrays keyed by entity ID. For performance reasons,
* information for all involved entities should be loaded in a single query
......
......@@ -106,50 +106,6 @@ public function prepareCache() {
}
}
/**
* {@inherotdoc}
*/
public static function prepareView(array $entities_items) {
if ($entities_items) {
// Determine the legacy callback.
$field_type_definition = current($entities_items)->getPluginDefinition();
$module = $field_type_definition['module'];
$callback = "{$module}_field_prepare_view";
if (function_exists($callback)) {
$entities = array();
$instances = array();
$itemsBC = array();
foreach ($entities_items as $id => $items) {
$entities[$id] = $items->getParent();
$instances[$id] = $items->offsetGet(0)->getInstance();
// We need to remove the empty "prototype" item here.
// @todo Revisit after http://drupal.org/node/1988492.
$items->filterEmptyValues();
$itemsBC[$id] = $items->getValue(TRUE);
}
// Determine the entity type, langcode and field.
$entity_type = current($entities)->entityType();
$langcode = current($entities)->language()->langcode;
$field = current($instances)->getField();
$args = array(
$entity_type,
$entities,
$field,
$instances,
$langcode,
&$itemsBC,
);
call_user_func_array($callback, $args);
foreach ($entities_items as $id => $items) {
$items->setValue($itemsBC[$id]);
}
}
}
}
/**
* Returns the legacy callback for a given field type "hook".
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment