diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index ac975d1..d0b6b4c 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -315,7 +315,9 @@ protected function getTranslatedField($property_name, $langcode) { $value = $this->values[$property_name][$default_langcode]; } } - $this->fields[$property_name][$langcode] = \Drupal::typedData()->getPropertyInstance($this, $property_name, $value); + $field = \Drupal::typedData()->getPropertyInstance($this, $property_name, $value); + $field->setLangcode($langcode); + $this->fields[$property_name][$langcode] = $field; } } return $this->fields[$property_name][$langcode]; diff --git a/core/lib/Drupal/Core/Entity/Field/Field.php b/core/lib/Drupal/Core/Entity/Field/Field.php index 7cf493c..63ec28f 100644 --- a/core/lib/Drupal/Core/Entity/Field/Field.php +++ b/core/lib/Drupal/Core/Entity/Field/Field.php @@ -11,6 +11,7 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\TypedData\TypedDataInterface; use Drupal\Core\TypedData\ItemList; +use Drupal\Core\Language\Language; /** * Represents an entity field; that is, a list of field item objects. @@ -36,6 +37,8 @@ class Field extends ItemList implements FieldInterface { */ protected $list = array(); + protected $langcode = Language::LANGCODE_DEFAULT; + /** * Overrides TypedData::__construct(). */ @@ -48,6 +51,14 @@ public function __construct(array $definition, $name = NULL, TypedDataInterface $this->list[0] = $this->createItem(0); } + public function setLangcode($langcode) { + $this->langcode = $langcode; + } + + public function getLangcode() { + return $this->langcode; + } + /** * {@inheritdoc} */ diff --git a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php index c021c57..a8388e7 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php @@ -36,6 +36,10 @@ public function __construct(array $definition, $name = NULL, TypedDataInterface } } + public function getLangcode() { + return $this->parent->getLangcode(); + } + /** * {@inheritdoc} */ diff --git a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimeDefaultFormatter.php b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimeDefaultFormatter.php index a2ea342..d226dfe 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimeDefaultFormatter.php +++ b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimeDefaultFormatter.php @@ -95,7 +95,7 @@ public static function create(ContainerInterface $container, array $configuratio /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); diff --git a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimePlainFormatter.php b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimePlainFormatter.php index 2eefd13..f9c0331 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimePlainFormatter.php +++ b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimePlainFormatter.php @@ -30,7 +30,7 @@ class DateTimePlainFormatter extends FormatterBase { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); diff --git a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDatelistWidget.php b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDatelistWidget.php index b208e36..37d2c3b 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDatelistWidget.php +++ b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDatelistWidget.php @@ -9,13 +9,9 @@ use Drupal\field\Annotation\FieldWidget; use Drupal\Core\Annotation\Translation; use Drupal\field\Plugin\Type\Widget\WidgetBase; -use Drupal\Component\Plugin\Discovery\DiscoveryInterface; -use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldDefinitionInterface; use Drupal\Core\Entity\Field\FieldInterface; -use Drupal\field\Plugin\PluginSettingsBase; use Drupal\field\FieldInstanceInterface; -use Drupal\Core\Datetime\DrupalDateTime; use Drupal\datetime\DateHelper; /** @@ -62,7 +58,7 @@ public function defaultValueFunction() { /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { $date_order = $this->getSetting('date_order'); $time_type = $this->getSetting('time_type'); $increment = $this->getSetting('increment'); diff --git a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDefaultWidget.php b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDefaultWidget.php index da550c7..6628dbb 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDefaultWidget.php +++ b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/widget/DatetimeDefaultWidget.php @@ -9,13 +9,9 @@ use Drupal\field\Annotation\FieldWidget; use Drupal\Core\Annotation\Translation; use Drupal\field\Plugin\Type\Widget\WidgetBase; -use Drupal\Component\Plugin\Discovery\DiscoveryInterface; -use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldDefinitionInterface; use Drupal\Core\Entity\Field\FieldInterface; -use Drupal\field\Plugin\PluginSettingsBase; use Drupal\field\FieldInstanceInterface; -use Drupal\Core\Datetime\DrupalDateTime; /** * Plugin implementation of the 'datetime_default' widget. @@ -66,7 +62,7 @@ public function defaultValueFunction() { /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { $format_type = datetime_default_format_type(); // We are nesting some sub-elements inside the parent, so we need a wrapper. diff --git a/core/modules/email/lib/Drupal/email/Plugin/field/formatter/MailToFormatter.php b/core/modules/email/lib/Drupal/email/Plugin/field/formatter/MailToFormatter.php index 25e2945..89eef1f 100644 --- a/core/modules/email/lib/Drupal/email/Plugin/field/formatter/MailToFormatter.php +++ b/core/modules/email/lib/Drupal/email/Plugin/field/formatter/MailToFormatter.php @@ -29,7 +29,7 @@ class MailToFormatter extends FormatterBase { /** * Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements(). */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); foreach ($items as $delta => $item) { diff --git a/core/modules/email/lib/Drupal/email/Plugin/field/widget/EmailDefaultWidget.php b/core/modules/email/lib/Drupal/email/Plugin/field/widget/EmailDefaultWidget.php index 624697f..4654e17 100644 --- a/core/modules/email/lib/Drupal/email/Plugin/field/widget/EmailDefaultWidget.php +++ b/core/modules/email/lib/Drupal/email/Plugin/field/widget/EmailDefaultWidget.php @@ -61,7 +61,7 @@ public function settingsSummary() { /** * Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement(). */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { $element['value'] = $element + array( '#type' => 'email', '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL, diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceEntityFormatter.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceEntityFormatter.php index dd054f2..7e53b1d 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceEntityFormatter.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceEntityFormatter.php @@ -79,9 +79,9 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { // Remove un-accessible items. - parent::viewElements($entity, $langcode, $items); + parent::viewElements($items); $view_mode = $this->getSetting('view_mode'); $links = $this->getSetting('links'); @@ -95,13 +95,13 @@ public function viewElements(EntityInterface $entity, $langcode, FieldInterface static $depth = 0; $depth++; if ($depth > 20) { - throw new RecursiveRenderingException(format_string('Recursive rendering detected when rendering entity @entity_type(@entity_id). Aborting rendering.', array('@entity_type' => $entity_type, '@entity_id' => $item->target_id))); + throw new RecursiveRenderingException(format_string('Recursive rendering detected when rendering entity @entity_type(@entity_id). Aborting rendering.', array('@entity_type' => $item->entity->entityType(), '@entity_id' => $item->target_id))); } if (!empty($item->target_id)) { $entity = clone $item->entity; unset($entity->content); - $elements[$delta] = entity_view($entity, $view_mode, $langcode); + $elements[$delta] = entity_view($entity, $view_mode, $item->getLangcode()); if (empty($links) && isset($result[$delta][$target_type][$item->target_id]['links'])) { // Hide the element links. @@ -110,7 +110,7 @@ public function viewElements(EntityInterface $entity, $langcode, FieldInterface } else { // This is an "auto_create" item. - $elements[$delta] = array('#markup' => $entity->label()); + $elements[$delta] = array('#markup' => $item->entity->label()); } $depth = 0; } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceFormatterBase.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceFormatterBase.php index 8232700..57c846a 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceFormatterBase.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceFormatterBase.php @@ -9,7 +9,6 @@ use Drupal\field\Annotation\FieldFormatter; use Drupal\Core\Annotation\Translation; -use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldInterface; use Drupal\field\Plugin\Type\Formatter\FormatterBase; @@ -25,13 +24,13 @@ * values, as other may want to act on those values, even if they can * not be accessed. */ - public function prepareView(array $entities, $langcode, array $items) { + public function prepareView(array $entities_items) { $target_ids = array(); $revision_ids = array(); // Collect every possible entity attached to any of the entities. - foreach ($entities as $id => $entity) { - foreach ($items[$id] as $delta => $item) { + foreach ($entities_items as $entity_id => $items) { + foreach ($items as $delta => $item) { if (!empty($item->revision_id)) { $revision_ids[] = $item->revision_id; } @@ -52,31 +51,30 @@ public function prepareView(array $entities, $langcode, array $items) { if ($revision_ids) { // We need to load the revisions one by-one. foreach ($revision_ids as $revision_id) { - $entity = entity_revision_load($target_type, $revision_id); + $target_entity = entity_revision_load($target_type, $revision_id); // Use the revision ID in the key. - $identifier = $entity->id() . ':' . $revision_id; - $target_entities[$identifier] = $entity; + $identifier = $target_entity->id() . ':' . $revision_id; + $target_entities[$identifier] = $target_entity; } } // Iterate through the fieldable entities again to attach the loaded data. - foreach ($entities as $id => $entity) { + foreach ($entities_items as $entity_id => $items) { $rekey = FALSE; - foreach ($items[$id] as $delta => $item) { + foreach ($items as $delta => $item) { // If we have a revision ID, the key uses it as well. $identifier = !empty($item->revision_id) ? $item->target_id . ':' . $item->revision_id : $item->target_id; if ($item->target_id !== 0) { if (!isset($target_entities[$identifier])) { // The entity no longer exists, so remove the key. $rekey = TRUE; - unset($items[$id][$delta]); + unset($items[$delta]); continue; } - $entity = $target_entities[$identifier]; - $item->entity = $entity; + $item->entity = $target_entities[$identifier]; - if (!$entity->access('view')) { + if (!$item->entity->access('view')) { continue; } } @@ -90,7 +88,7 @@ public function prepareView(array $entities, $langcode, array $items) { if ($rekey) { // Rekey the items array. - $items[$id] = array_values($items[$id]); + $items->filterEmptyValues(); } } } @@ -100,7 +98,7 @@ public function prepareView(array $entities, $langcode, array $items) { * * @see \Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase::viewElements(). */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { // Remove un-accessible items. foreach ($items as $delta => $item) { if (empty($item->access)) { diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceIdFormatter.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceIdFormatter.php index f7402bf..ef6291f 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceIdFormatter.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceIdFormatter.php @@ -30,7 +30,7 @@ class EntityReferenceIdFormatter extends EntityReferenceFormatterBase { /** * Overrides \Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase::viewElements(). */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); foreach ($items as $delta => $item) { diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceLabelFormatter.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceLabelFormatter.php index c63dfd6..2d5ddd7 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceLabelFormatter.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceLabelFormatter.php @@ -55,9 +55,9 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { // Remove un-accessible items. - parent::viewElements($entity, $langcode, $items); + parent::viewElements($items); $elements = array(); diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php index fb2b575..b5f9d6e 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php @@ -40,7 +40,7 @@ class AutocompleteWidget extends AutocompleteWidgetBase { /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { // We let the Field API handles multiple values for us, only take care of // the one matching our delta. if (isset($items[$delta])) { @@ -50,7 +50,7 @@ public function formElement(FieldInterface $items, $delta, array $element, $lang $items->setValue(array()); } - return parent::formElement($items, $delta, $element, $langcode, $form, $form_state); + return parent::formElement($items, $delta, $element, $form, $form_state); } /** diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php index 3587046..105ac81 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php @@ -70,9 +70,9 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { global $user; - $entity = $element['#entity']; + $entity = $items->getParent(); // Prepare the autocomplete path. $autocomplete_path = $this->getSetting('autocomplete_path'); diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index 9deadaf..448e2bd 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -201,10 +201,8 @@ function hook_field_widget_info_alter(array &$info) { * - form: The form structure to which widgets are being attached. This may be * a full form structure, or a sub-element of a larger form. * - widget: The widget plugin instance. - * - field_definition: The field definition. - * - entity: The entity. - * - langcode: The language associated with $items. - * - items: Array of default values for this field. + * - items: The field values, as a \Drupal\Core\Entity\Field\FieldInterface + * object. * - delta: The order of this item in the array of subelements (0, 1, 2, etc). * - default: A boolean indicating whether the form is being shown as a dummy * form to set default values. @@ -214,7 +212,8 @@ function hook_field_widget_info_alter(array &$info) { */ function hook_field_widget_form_alter(&$element, &$form_state, $context) { // Add a css class to widget form elements for all fields of type mytype. - if ($context['field']['type'] == 'mytype') { + $field_definition = $context['items']->getFieldDefinition(); + if ($field_definition->getFieldType() == 'mytype') { // Be sure not to overwrite existing attributes. $element['#attributes']['class'][] = 'myclass'; } diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc index 3125584..58bb1a3 100644 --- a/core/modules/field/field.attach.inc +++ b/core/modules/field/field.attach.inc @@ -177,7 +177,7 @@ function field_invoke_method($method, $target_function, EntityInterface $entity, $items = $entity->getTranslation($langcode)->get($field_name); $items->filterEmptyValues(); - $result = $target->$method($entity, $langcode, $items, $a, $b); + $result = $target->$method($items, $a, $b); if (isset($result)) { // For methods with array results, we merge results together. @@ -241,7 +241,6 @@ function field_invoke_method_multiple($method, $target_function, array $entities $options += $default_options; $instances = array(); - $grouped_entities = array(); $grouped_items = array(); $grouped_targets = array(); $return = array(); @@ -278,8 +277,7 @@ function field_invoke_method_multiple($method, $target_function, array $entities $langcode = !empty($options['langcode'][$id]) ? $options['langcode'][$id] : $options['langcode']; $langcodes = _field_language_suggestion($available_langcodes, $langcode, $field_name); foreach ($langcodes as $langcode) { - // Group the entities and items corresponding to the current field. - $grouped_entities[$instance_id][$langcode][$id] = $entities[$id]; + // Group the items corresponding to the current field. $items = $entity->getTranslation($langcode)->get($field_name); $items->filterEmptyValues(); $grouped_items[$instance_id][$langcode][$id] = $items; @@ -292,12 +290,9 @@ function field_invoke_method_multiple($method, $target_function, array $entities // For each instance, invoke the method and collect results. foreach ($instances as $instance_id => $instance) { - $field_name = $instance['field_name']; - // Iterate over all the field translations. foreach ($grouped_items[$instance_id] as $langcode => $items) { - $entities = $grouped_entities[$instance_id][$langcode]; - $results = $grouped_targets[$instance_id]->$method($entities, $langcode, $items, $a, $b); + $results = $grouped_targets[$instance_id]->$method($items, $a, $b); if (isset($results)) { // Collect results by entity. diff --git a/core/modules/field/field.deprecated.inc b/core/modules/field/field.deprecated.inc index 1b1d8f9..430f719 100644 --- a/core/modules/field/field.deprecated.inc +++ b/core/modules/field/field.deprecated.inc @@ -837,7 +837,7 @@ function field_attach_form_validate(EntityInterface $entity, $form, &$form_state $has_violations = TRUE; // Place violations in $form_state. - $langcode = field_is_translatable($entity->entityType(), field_info_field($field_name)) ? $entity->language()->id : Language::LANGCODE_NOT_SPECIFIED; + $langcode = field_is_translatable($entity->entityType(), field_info_field($field_name)) ? $field->getLangcode() : Language::LANGCODE_NOT_SPECIFIED; $field_state = field_form_get_state($form['#parents'], $field_name, $langcode, $form_state); $field_state['constraint_violations'] = $field_violations; field_form_set_state($form['#parents'], $field_name, $langcode, $form_state, $field_state); diff --git a/core/modules/field/field.module b/core/modules/field/field.module index c355e67..4b790ee 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -747,9 +747,8 @@ function field_view_field(EntityInterface $entity, $field_name, $display_options // Invoke the formatter's prepareView() and view() methods. $items = $entity->getNGEntity()->getTranslation($display_langcode)->get($field_name); - $id = $entity->id(); - $formatter->prepareView(array($id => $entity), $display_langcode, array($id => $items)); - $result = $formatter->view($entity, $display_langcode, $items); + $formatter->prepareView(array($entity->id() => $items)); + $result = $formatter->view($items); // Invoke hook_field_attach_view_alter() to let other modules alter the // renderable array, as in a full field_attach_view() execution. diff --git a/core/modules/field/field.multilingual.inc b/core/modules/field/field.multilingual.inc index d02595c..61c5a41 100644 --- a/core/modules/field/field.multilingual.inc +++ b/core/modules/field/field.multilingual.inc @@ -34,7 +34,7 @@ * is attached to supports translation. * * By default, field_invoke_method() processes a field in all available - * languages, unless they are given a language code suggestion. Based on that + * languages, unless it is given a language code suggestion. Based on that * suggestion, _field_language_suggestion() determines the languages to act on. * * Most field_attach_*() functions act on all available language codes, except diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php index 53fa2f5..056f09b 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php @@ -84,12 +84,10 @@ protected function getDefaultValue() { */ public function defaultValuesForm(array &$form, array &$form_state) { if (empty($this->getInstance()->default_value_function)) { - $entity = $this->getParent(); - $widget = $this->defaultValueWidget($form_state); - // Place the input in a separate place in the submitted values tree. + $widget = $this->defaultValueWidget($form_state); $element = array('#parents' => array('default_value_input')); - $element += $widget->form($entity, $entity->language()->id, $this, $element, $form_state); + $element += $widget->form($this, $element, $form_state); return $element; } @@ -99,15 +97,13 @@ public function defaultValuesForm(array &$form, array &$form_state) { * {@inheritdoc} */ public function defaultValuesFormValidate(array $element, array &$form, array &$form_state) { - $entity = $this->getParent(); - $langcode = $entity->language()->id; - $widget = $this->defaultValueWidget($form_state); - // Extract the submitted value, and validate it. - $widget->extractFormValues($entity, $langcode, $this, $element, $form_state); + $widget = $this->defaultValueWidget($form_state); + $widget->extractFormValues($this, $element, $form_state); $violations = $this->validate(); if (count($violations)) { + $langcode = $this->getLangcode(); // Store reported errors in $form_state. $field_name = $this->getFieldDefinition()->getFieldName(); $field_state = field_form_get_state($element['#parents'], $field_name, $langcode, $form_state); @@ -115,7 +111,7 @@ public function defaultValuesFormValidate(array $element, array &$form, array &$ field_form_set_state($element['#parents'], $field_name, $langcode, $form_state, $field_state); // Assign reported errors to the correct form element. - $widget->flagErrors($entity, $langcode, $this, $element, $form_state); + $widget->flagErrors($this, $element, $form_state); } } @@ -123,12 +119,9 @@ public function defaultValuesFormValidate(array $element, array &$form, array &$ * {@inheritdoc} */ public function defaultValuesFormSubmit(array $element, array &$form, array &$form_state) { - $entity = $this->getParent(); - $langcode = $entity->language()->id; - $widget = $this->defaultValueWidget($form_state); - // Extract the submitted value, and return it as an array. - $widget->extractFormValues($entity, $langcode, $this, $element, $form_state); + $widget = $this->defaultValueWidget($form_state); + $widget->extractFormValues($this, $element, $form_state); return $this->getValue(); } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php index aa93124..6cb716f 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php @@ -7,7 +7,6 @@ namespace Drupal\field\Plugin\Type\Formatter; -use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldDefinitionInterface; use Drupal\Core\Entity\Field\FieldInterface; use Drupal\field\FieldInstanceInterface; @@ -74,11 +73,12 @@ public function __construct($plugin_id, array $plugin_definition, FieldDefinitio /** * {@inheritdoc} */ - public function view(EntityInterface $entity, $langcode, FieldInterface $items) { + public function view(FieldInterface $items) { $addition = array(); - $elements = $this->viewElements($entity, $langcode, $items); + $elements = $this->viewElements($items); if ($elements) { + $entity = $items->getParent(); $entity_type = $entity->entityType(); $field_name = $this->fieldDefinition->getFieldName(); $info = array( @@ -87,7 +87,7 @@ public function view(EntityInterface $entity, $langcode, FieldInterface $items) '#access' => $this->checkFieldAccess('view', $entity), '#label_display' => $this->label, '#view_mode' => $this->viewMode, - '#language' => $langcode, + '#language' => $items->getLangcode(), '#field_name' => $field_name, '#field_type' => $this->fieldDefinition->getFieldType(), '#field_translatable' => $this->fieldDefinition->isFieldTranslatable(), @@ -121,7 +121,7 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function prepareView(array $entities, $langcode, array $items) { } + public function prepareView(array $entities_items) { } /** * Returns whether the currently logged in user has access to the field. diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterInterface.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterInterface.php index 70bc59a..8a38c20 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterInterface.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterInterface.php @@ -7,7 +7,6 @@ namespace Drupal\field\Plugin\Type\Formatter; -use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldInterface; use Drupal\field\Plugin\PluginSettingsInterface; @@ -61,45 +60,33 @@ public function settingsSummary(); * Changes or additions to field values are done by alterings the $items * parameter by reference. * - * @param array $entities - * Array of entities being displayed, keyed by entity ID. - * @param string $langcode - * The language the field values are to be shown in. If no language is - * provided the current language is used. - * @param array $items - * Array of field values for the entities, keyed by entity ID. + * @param array $entities_items + * Array of field values (Drupal\Core\Entity\Field\FieldInterface), keyed by + * entity ID. */ - public function prepareView(array $entities, $langcode, array $items); + public function prepareView(array $entities_items); /** * Builds a renderable array for one field on one entity instance. * - * @param Drupal\Core\Entity\EntityInterface $entity - * The entity being displayed. - * @param string $langcode - * The language associated with $items. * @param Drupal\Core\Entity\Field\FieldInterface $items - * The field value for the entity for the language. + * The field values to be rendered. * * @return array * A renderable array for a themed field with its label and all its values. */ - public function view(EntityInterface $entity, $langcode, FieldInterface $items); + public function view(FieldInterface $items); /** * Builds a renderable array for a field value. * - * @param Drupal\Core\Entity\EntityInterface $entity - * The entity being displayed. - * @param string $langcode - * The language associated with $items. - * @param array $items - * Array of values for this field. + * @param Drupal\Core\Entity\Field\FieldInterface $items + * The field values to be rendered. * * @return array * A renderable array for $items, as an array of child elements keyed by * numeric indexes starting from 0. */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items); + public function viewElements(FieldInterface $items); } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php index 4cf4556..96de87f 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php @@ -8,7 +8,6 @@ namespace Drupal\field\Plugin\Type\Widget; use Drupal\Component\Utility\NestedArray; -use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldDefinitionInterface; use Drupal\Core\Entity\Field\FieldInterface; use Drupal\field\FieldInstanceInterface; @@ -56,8 +55,10 @@ public function __construct($plugin_id, array $plugin_definition, FieldDefinitio /** * {@inheritdoc} */ - public function form(EntityInterface $entity, $langcode, FieldInterface $items, array &$form, array &$form_state, $get_delta = NULL) { + public function form(FieldInterface $items, array &$form, array &$form_state, $get_delta = NULL) { $field_name = $this->fieldDefinition->getFieldName(); + $entity = $items->getParent(); + $langcode = $items->getLangcode(); $parents = $form['#parents']; @@ -88,7 +89,7 @@ public function form(EntityInterface $entity, $langcode, FieldInterface $items, '#title' => check_plain($this->fieldDefinition->getFieldLabel()), '#description' => field_filter_xss(\Drupal::token()->replace($this->fieldDefinition->getFieldDescription())), ); - $element = $this->formSingleElement($entity, $items, $delta, $langcode, $element, $form, $form_state); + $element = $this->formSingleElement($items, $delta, $element, $form, $form_state); if ($element) { if (isset($get_delta)) { @@ -107,7 +108,7 @@ public function form(EntityInterface $entity, $langcode, FieldInterface $items, // If the widget does not handle multiple values itself, (and we are not // displaying an individual element), process the multiple value form. else { - $elements = $this->formMultipleElements($entity, $items, $langcode, $form, $form_state); + $elements = $this->formMultipleElements($items, $form, $form_state); } // Also aid in theming of field widgets by rendering a classified @@ -151,7 +152,7 @@ public function form(EntityInterface $entity, $langcode, FieldInterface $items, * - AHAH-'add more' button * - table display and drag-n-drop value reordering */ - protected function formMultipleElements(EntityInterface $entity, FieldInterface $items, $langcode, array &$form, array &$form_state) { + protected function formMultipleElements(FieldInterface $items, array &$form, array &$form_state) { $field_name = $this->fieldDefinition->getFieldName(); $cardinality = $this->fieldDefinition->getFieldCardinality(); $parents = $form['#parents']; @@ -159,7 +160,7 @@ protected function formMultipleElements(EntityInterface $entity, FieldInterface // Determine the number of widgets to display. switch ($cardinality) { case FIELD_CARDINALITY_UNLIMITED: - $field_state = field_form_get_state($parents, $field_name, $langcode, $form_state); + $field_state = field_form_get_state($parents, $field_name, $items->getLangcode(), $form_state); $max = $field_state['items_count']; $is_multiple = TRUE; break; @@ -185,7 +186,7 @@ protected function formMultipleElements(EntityInterface $entity, FieldInterface '#title' => $is_multiple ? '' : $title, '#description' => $is_multiple ? '' : $description, ); - $element = $this->formSingleElement($entity, $items, $delta, $langcode, $element, $form, $form_state); + $element = $this->formSingleElement($items, $delta, $element, $form, $form_state); if ($element) { // Input field for the delta (drag-n-drop reordering). @@ -227,7 +228,7 @@ protected function formMultipleElements(EntityInterface $entity, FieldInterface '#name' => strtr($id_prefix, '-', '_') . '_add_more', '#value' => t('Add another item'), '#attributes' => array('class' => array('field-add-more-submit')), - '#limit_validation_errors' => array(array_merge($parents, array($field_name, $langcode))), + '#limit_validation_errors' => array(array_merge($parents, array($field_name, $items->getLangcode()))), '#submit' => array('field_add_more_submit'), '#ajax' => array( 'callback' => 'field_add_more_js', @@ -244,13 +245,15 @@ protected function formMultipleElements(EntityInterface $entity, FieldInterface /** * Generates the form element for a single copy of the widget. */ - protected function formSingleElement(EntityInterface $entity, FieldInterface $items, $delta, $langcode, array $element, array &$form, array &$form_state) { + protected function formSingleElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { + $entity = $items->getParent(); + $element += array( '#entity_type' => $entity->entityType(), '#bundle' => $entity->bundle(), '#entity' => $entity, '#field_name' => $this->fieldDefinition->getFieldName(), - '#language' => $langcode, + '#language' => $items->getLangcode(), '#field_parents' => $form['#parents'], // Only the first widget should be required. '#required' => $delta == 0 && $this->fieldDefinition->isFieldRequired(), @@ -258,16 +261,13 @@ protected function formSingleElement(EntityInterface $entity, FieldInterface $it '#weight' => $delta, ); - $element = $this->formElement($items, $delta, $element, $langcode, $form, $form_state); + $element = $this->formElement($items, $delta, $element, $form, $form_state); if ($element) { // Allow modules to alter the field widget form element. $context = array( 'form' => $form, 'widget' => $this, - 'field_definition' => $this->fieldDefinition, - 'entity' => $entity, - 'langcode' => $langcode, 'items' => $items, 'delta' => $delta, 'default' => !empty($entity->field_ui_default_value), @@ -281,8 +281,9 @@ protected function formSingleElement(EntityInterface $entity, FieldInterface $it /** * {@inheritdoc} */ - public function extractFormValues(EntityInterface $entity, $langcode, FieldInterface $items, array $form, array &$form_state) { + public function extractFormValues(FieldInterface $items, array $form, array &$form_state) { $field_name = $this->fieldDefinition->getFieldName(); + $langcode = $items->getLangcode(); // Extract the values from $form_state['values']. $path = array_merge($form['#parents'], array($field_name, $langcode)); @@ -334,8 +335,9 @@ public function extractFormValues(EntityInterface $entity, $langcode, FieldInter /** * {@inheritdoc} */ - public function flagErrors(EntityInterface $entity, $langcode, FieldInterface $items, array $form, array &$form_state) { + public function flagErrors(FieldInterface $items, array $form, array &$form_state) { $field_name = $this->fieldDefinition->getFieldName(); + $langcode = $items->getLangcode(); $field_state = field_form_get_state($form['#parents'], $field_name, $langcode, $form_state); @@ -413,7 +415,7 @@ public function massageFormValues(array $values, array $form, array &$form_state /** * Sorts submitted field values according to drag-n-drop reordering. * - * @param FieldInterface $items + * @param \Drupal\Core\Entity\Field\FieldInterface $items * The field values. */ protected function sortItems(FieldInterface $items) { diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBaseInterface.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBaseInterface.php index ac8c60b..d5cd015 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBaseInterface.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBaseInterface.php @@ -7,7 +7,6 @@ namespace Drupal\field\Plugin\Type\Widget; -use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldInterface; use Drupal\field\Plugin\PluginSettingsInterface; @@ -28,11 +27,7 @@ * TRUE), the 'default value', if any, is pre-populated. Also allows other * modules to alter the form element by implementing their own hooks. * - * @param Drupal\Core\Entity\EntityInterface $entity - * The entity for which the widget is being built. - * @param string $langcode - * The language associated with the field. - * @param FieldInterface $items + * @param \Drupal\Core\Entity\Field\FieldInterface $items * An array of the field values. When creating a new entity this may be NULL * or an empty array to use default values. * @param array $form @@ -46,16 +41,12 @@ * @return array * The form element array created for this field. */ - public function form(EntityInterface $entity, $langcode, FieldInterface $items, array &$form, array &$form_state, $get_delta = NULL); + public function form(FieldInterface $items, array &$form, array &$form_state, $get_delta = NULL); /** * Extracts field values from submitted form values. * - * @param Drupal\Core\Entity\EntityInterface $entity - * The entity for which the widget is being submitted. - * @param string $langcode - * The language associated to $items. - * @param FieldInterface $items + * @param \Drupal\Core\Entity\Field\FieldInterface $items * The field values. This parameter is altered by reference to receive the * incoming form values. * @param array $form @@ -64,16 +55,12 @@ public function form(EntityInterface $entity, $langcode, FieldInterface $items, * @param array $form_state * The form state. */ - public function extractFormValues(EntityInterface $entity, $langcode, FieldInterface $items, array $form, array &$form_state); + public function extractFormValues(FieldInterface $items, array $form, array &$form_state); /** * Reports field-level validation errors against actual form elements. * - * @param Drupal\Core\Entity\EntityInterface $entity - * The entity for which the widget is being submitted. - * @param string $langcode - * The language associated to $items. - * @param FieldInterface $items + * @param \Drupal\Core\Entity\Field\FieldInterface $items * The field values. * @param array $form * The form structure where field elements are attached to. This might be a @@ -81,6 +68,6 @@ public function extractFormValues(EntityInterface $entity, $langcode, FieldInter * @param array $form_state * The form state. */ - public function flagErrors(EntityInterface $entity, $langcode, FieldInterface $items, array $form, array &$form_state); + public function flagErrors(FieldInterface $items, array $form, array &$form_state); } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetInterface.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetInterface.php index e27484e..a64915c 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetInterface.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetInterface.php @@ -7,8 +7,6 @@ namespace Drupal\field\Plugin\Type\Widget; -use Drupal\Core\Entity\EntityInterface; -use Drupal\field\Entity\FieldInstance; use Symfony\Component\Validator\ConstraintViolationInterface; use Drupal\Core\Entity\Field\FieldInterface; @@ -75,7 +73,7 @@ public function settingsSummary(); * definition and set them as ad-hoc $element['#custom'] properties, for later * use by its element callbacks. * - * @param FieldInterface $items + * @param \Drupal\Core\Entity\Field\FieldInterface $items * Array of default values for this field. * @param int $delta * The order of this item in the array of subelements (0, 1, 2, etc). @@ -101,8 +99,6 @@ public function settingsSummary(); * required. * - #delta: The order of this item in the array of subelements; see $delta * above. - * @param string $langcode - * The language associated with $items. * @param string $form * The form structure where widgets are being attached to. This might be a * full form structure, or a sub-element of a larger form. @@ -115,7 +111,7 @@ public function settingsSummary(); * @see hook_field_widget_form_alter() * @see hook_field_widget_WIDGET_TYPE_form_alter() */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state); + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state); /** * Assigns a field-level validation error to the right widget sub-element. diff --git a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php index 31e65ca..6329c4f 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php +++ b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php @@ -39,8 +39,7 @@ public function validate() { $legacy_errors = array(); $this->legacyCallback('validate', array(&$legacy_errors)); - $entity = $this->getParent(); - $langcode = $entity->language()->id; + $langcode = $this->getLangcode(); if (isset($legacy_errors[$this->getInstance()->getField()->id()][$langcode])) { foreach ($legacy_errors[$this->getInstance()->getField()->id()][$langcode] as $delta => $item_errors) { @@ -105,19 +104,16 @@ protected function legacyCallback($hook, $args = array()) { $module = $definition['provider']; $callback = "{$module}_field_{$hook}"; if (function_exists($callback)) { - $entity = $this->getParent(); - $langcode = $entity->language()->id; - // We need to remove the empty "prototype" item here. // @todo Revisit after http://drupal.org/node/1988492. $this->filterEmptyValues(); // Legcacy callbacks alter $items by reference. $items = (array) $this->getValue(TRUE); $args = array_merge(array( - $entity, + $this->getParent(), $this->getInstance()->getField(), $this->getInstance(), - $langcode, + $this->getLangcode(), &$items ), $args); call_user_func_array($callback, $args); diff --git a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php index 8407cbf..08f1c273 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php +++ b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php @@ -87,7 +87,6 @@ public function instanceSettingsForm(array $form, array &$form_state) { public function prepareCache() { if ($callback = $this->getLegacyCallback('load')) { $entity = $this->getParent()->getParent(); - $langcode = $entity->language()->id; $entity_id = $entity->id(); // hook_field_attach_load() receives items keyed by entity id, and alter @@ -98,7 +97,7 @@ public function prepareCache() { array($entity_id => $entity), $this->getInstance()->getField(), array($entity_id => $this->getInstance()), - $langcode, + $this->getLangcode(), &$items, FIELD_LOAD_CURRENT, ); diff --git a/core/modules/field/lib/Drupal/field/Plugin/field/widget/HiddenWidget.php b/core/modules/field/lib/Drupal/field/Plugin/field/widget/HiddenWidget.php index 78e6010..33d7b76 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/field/widget/HiddenWidget.php +++ b/core/modules/field/lib/Drupal/field/Plugin/field/widget/HiddenWidget.php @@ -27,7 +27,7 @@ class HiddenWidget extends WidgetBase { /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { // The purpose of this widget is to be hidden, so nothing to do here. return array(); } 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 800f4d4..15ac7a2 100644 --- a/core/modules/field/tests/modules/field_test/field_test.module +++ b/core/modules/field/tests/modules/field_test/field_test.module @@ -154,7 +154,8 @@ function field_test_field_attach_view_alter(&$output, $context) { * Implements hook_field_widget_form_alter(). */ function field_test_field_widget_form_alter(&$element, &$form_state, $context) { - switch ($context['field_definition']->getFieldName()) { + $field_definition = $context['items']->getFieldDefinition(); + switch ($field_definition->getFieldName()) { case 'alter_test_text': drupal_set_message('Field size: ' . $context['widget']->getSetting('size')); break; diff --git a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldDefaultFormatter.php b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldDefaultFormatter.php index a54b2c3..c864374 100644 --- a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldDefaultFormatter.php +++ b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldDefaultFormatter.php @@ -56,7 +56,7 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); foreach ($items as $delta => $item) { diff --git a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldEmptyFormatter.php b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldEmptyFormatter.php index b8e455c..2ba0af1 100644 --- a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldEmptyFormatter.php +++ b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldEmptyFormatter.php @@ -9,7 +9,6 @@ use Drupal\field\Annotation\FieldFormatter; use Drupal\Core\Annotation\Translation; -use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldInterface; use Drupal\field\Plugin\Type\Formatter\FormatterBase; @@ -32,11 +31,11 @@ class TestFieldEmptyFormatter extends FormatterBase { /** * {@inheritdoc} */ - public function prepareView(array $entities, $langcode, array $items) { - foreach ($entities as $id => $entity) { - if ($items[$id]->isEmpty()) { + public function prepareView(array $entities_items) { + foreach ($entities_items as $entity_id => $items) { + if ($items->isEmpty()) { // For fields with no value, just add the configured "empty" value. - $items[$id][0]->value = $this->getSetting('test_empty_string'); + $items[0]->value = $this->getSetting('test_empty_string'); } } } @@ -44,7 +43,7 @@ public function prepareView(array $entities, $langcode, array $items) { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); if (!empty($items)) { diff --git a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldMultipleFormatter.php b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldMultipleFormatter.php index 5b0b63b..bd23716 100644 --- a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldMultipleFormatter.php +++ b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldMultipleFormatter.php @@ -56,7 +56,7 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); if (!empty($items)) { diff --git a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldPrepareViewFormatter.php b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldPrepareViewFormatter.php index 946797a..84c87ef 100644 --- a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldPrepareViewFormatter.php +++ b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/formatter/TestFieldPrepareViewFormatter.php @@ -10,7 +10,6 @@ use Drupal\field\Annotation\FieldFormatter; use Drupal\Core\Annotation\Translation; use Drupal\field\Plugin\Type\Formatter\FormatterBase; -use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldInterface; /** @@ -56,9 +55,9 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function prepareView(array $entities, $langcode, array $items) { - foreach ($entities as $id => $entity) { - foreach ($items[$id] as $delta => $item) { + public function prepareView(array $entities_items) { + foreach ($entities_items as $entity_id => $items) { + foreach ($items as $delta => $item) { // Don't add anything on empty values. if (!$item->isEmpty()) { $item->additional_formatter_value = $item->value + 1; @@ -70,7 +69,7 @@ public function prepareView(array $entities, $langcode, array $items) { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); foreach ($items as $delta => $item) { diff --git a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/widget/TestFieldWidget.php b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/widget/TestFieldWidget.php index ff3c593..4cfb1a2 100644 --- a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/widget/TestFieldWidget.php +++ b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/widget/TestFieldWidget.php @@ -56,7 +56,7 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { $element += array( '#type' => 'textfield', '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : '', diff --git a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/widget/TestFieldWidgetMultiple.php b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/widget/TestFieldWidgetMultiple.php index 86d7dde..a937290 100644 --- a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/widget/TestFieldWidgetMultiple.php +++ b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/field/widget/TestFieldWidgetMultiple.php @@ -58,7 +58,7 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { $values = array(); foreach ($items as $delta => $item) { $values[] = $item->value; diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/FileFormatterBase.php b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/FileFormatterBase.php index 2ef9df2..b4bd25e 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/FileFormatterBase.php +++ b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/FileFormatterBase.php @@ -17,11 +17,11 @@ /** * {@inheritdoc} */ - public function prepareView(array $entities, $langcode, array $items) { + public function prepareView(array $entities_items) { // Remove files specified to not be displayed. $fids = array(); - foreach ($entities as $id => $entity) { - foreach ($items[$id] as $delta => $item) { + foreach ($entities_items as $entity_id => $items) { + foreach ($items as $delta => $item) { if ($this->isDisplayed($item) && !empty($item->target_id)) { // Load the files from the files table. $fids[] = $item->target_id; @@ -32,8 +32,8 @@ public function prepareView(array $entities, $langcode, array $items) { if ($fids) { $files = file_load_multiple($fids); - foreach ($entities as $id => $entity) { - foreach ($items[$id] as $delta => $item) { + foreach ($entities_items as $entity_id => $items) { + foreach ($items as $delta => $item) { // If the file does not exist, mark the entire item as empty. if (!empty($item->target_id)) { $item->entity = isset($files[$item->target_id]) ? $files[$item->target_id] : NULL; diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/GenericFileFormatter.php b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/GenericFileFormatter.php index abf6e92..362ab24 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/GenericFileFormatter.php +++ b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/GenericFileFormatter.php @@ -28,7 +28,7 @@ class GenericFileFormatter extends FileFormatterBase { /** * Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements(). */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); foreach ($items as $delta => $item) { diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/RSSEnclosureFormatter.php b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/RSSEnclosureFormatter.php index d18234f..655c8ed 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/RSSEnclosureFormatter.php +++ b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/RSSEnclosureFormatter.php @@ -28,8 +28,8 @@ class RSSEnclosureFormatter extends FileFormatterBase { /** * Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements(). */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { - + public function viewElements(FieldInterface $items) { + $entity = $items->getParent(); // Add the first file as an enclosure to the RSS item. RSS allows only one // enclosure per item. See: http://en.wikipedia.org/wiki/RSS_enclosure foreach ($items as $item) { diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/TableFormatter.php b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/TableFormatter.php index dfe8f43..494b944 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/TableFormatter.php +++ b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/TableFormatter.php @@ -28,7 +28,7 @@ class TableFormatter extends FileFormatterBase { /** * Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements(). */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); if (!$items->isEmpty()) { diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/UrlPlainFormatter.php b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/UrlPlainFormatter.php index 9138a07..72d6d15 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/field/formatter/UrlPlainFormatter.php +++ b/core/modules/file/lib/Drupal/file/Plugin/field/formatter/UrlPlainFormatter.php @@ -28,7 +28,7 @@ class UrlPlainFormatter extends FileFormatterBase { /** * Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements(). */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); foreach ($items as $delta => $item) { diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php index 1e12c5b..722c224 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php +++ b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php @@ -10,7 +10,6 @@ use Drupal\field\Annotation\FieldWidget; use Drupal\Core\Annotation\Translation; use Drupal\field\Plugin\Type\Widget\WidgetBase; -use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldInterface; /** @@ -62,15 +61,14 @@ public function settingsSummary() { * * Special handling for draggable multiple widgets and 'add more' button. */ - protected function formMultipleElements(EntityInterface $entity, FieldInterface $items, $langcode, array &$form, array &$form_state) { + protected function formMultipleElements(FieldInterface $items, array &$form, array &$form_state) { $field_name = $this->fieldDefinition->getFieldName(); - $parents = $form['#parents']; // Load the items for form rebuilds from the field state as they might not be // in $form_state['values'] because of validation limitations. Also, they are // only passed in as $items when editing existing entities. - $field_state = field_form_get_state($parents, $field_name, $langcode, $form_state); + $field_state = field_form_get_state($parents, $field_name, $items->getLangcode(), $form_state); if (isset($field_state['items'])) { $items->setValue($field_state['items']); } @@ -101,7 +99,7 @@ protected function formMultipleElements(EntityInterface $entity, FieldInterface '#title' => $title, '#description' => $description, ); - $element = $this->formSingleElement($entity, $items, $delta, $langcode, $element, $form, $form_state); + $element = $this->formSingleElement($items, $delta, $element, $form, $form_state); if ($element) { // Input field for the delta (drag-n-drop reordering). @@ -134,7 +132,7 @@ protected function formMultipleElements(EntityInterface $entity, FieldInterface '#title' => $title, '#description' => $description, ); - $element = $this->formSingleElement($entity, $items, $delta, $langcode, $element, $form, $form_state); + $element = $this->formSingleElement($items, $delta, $element, $form, $form_state); if ($element) { $element['#required'] = ($element['#required'] && $delta == 0); $elements[$delta] = $element; @@ -174,7 +172,7 @@ protected function formMultipleElements(EntityInterface $entity, FieldInterface /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { $field_settings = $this->getFieldSettings(); // The field settings include defaults for the field type. However, this diff --git a/core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatter.php b/core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatter.php index 32c82ad..c1eb6d0 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatter.php +++ b/core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatter.php @@ -92,8 +92,9 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); + $entity = $items->getparent(); $image_link_setting = $this->getSetting('image_link'); // Check if the formatter involves a link. diff --git a/core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatterBase.php b/core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatterBase.php index 0ed0be4..f3afc37 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatterBase.php +++ b/core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatterBase.php @@ -17,28 +17,16 @@ /** * {@inheritdoc} */ - public function prepareView(array $entities, $langcode, array $items) { - parent::prepareView($entities, $langcode, $items); + public function prepareView(array $entities_items) { + parent::prepareView($entities_items); // If there are no files specified at all, use the default. - foreach ($entities as $id => $entity) { - if ($items[$id]->isEmpty()) { - $fid = array(); - $instance = field_info_instance($entity->entityType(), $this->fieldDefinition->getFieldName(), $entity->bundle()); - // Use the default for the instance if one is available. - if (!empty($instance['settings']['default_image'])) { - $fid = array($instance['settings']['default_image']); - } - // Otherwise, use the default for the field. - // Note, that we have to bypass getFieldSetting() as this returns the - // instance-setting default. - elseif (($field = $this->fieldDefinition->getField()) && !empty($field->settings['default_image'])) { - $fid = array($field->settings['default_image']); - } - + foreach ($entities_items as $entity_id => $items) { + if ($items->isEmpty()) { // Add the default image if one is found. - if ($fid && ($file = file_load($fid[0]))) { - $items[$id]->setValue(array(array( + $fid = $this->fieldDefinition->getFieldSetting('default_image'); + if ($fid && ($file = file_load($fid))) { + $items->setValue(array(array( 'is_default' => TRUE, 'alt' => '', 'title' => '', diff --git a/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php b/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php index 82cb4ad..99c1eca 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php +++ b/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php @@ -10,7 +10,6 @@ use Drupal\field\Annotation\FieldWidget; use Drupal\Core\Annotation\Translation; use Drupal\file\Plugin\field\widget\FileWidget; -use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldInterface; /** @@ -78,8 +77,8 @@ public function settingsSummary() { * * Special handling for draggable multiple widgets and 'add more' button. */ - protected function formMultipleElements(EntityInterface $entity, FieldInterface $items, $langcode, array &$form, array &$form_state) { - $elements = parent::formMultipleElements($entity, $items, $langcode, $form, $form_state); + protected function formMultipleElements(FieldInterface $items, array &$form, array &$form_state) { + $elements = parent::formMultipleElements($items, $form, $form_state); $cardinality = $this->fieldDefinition->getFieldCardinality(); $file_upload_help = array( @@ -104,8 +103,8 @@ protected function formMultipleElements(EntityInterface $entity, FieldInterface /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { - $element = parent::formElement($items, $delta, $element, $langcode, $form, $form_state); + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { + $element = parent::formElement($items, $delta, $element, $form, $form_state); $field_settings = $this->getFieldSettings(); diff --git a/core/modules/link/lib/Drupal/link/Plugin/field/formatter/LinkFormatter.php b/core/modules/link/lib/Drupal/link/Plugin/field/formatter/LinkFormatter.php index 29e7eb9..3ae7b57 100644 --- a/core/modules/link/lib/Drupal/link/Plugin/field/formatter/LinkFormatter.php +++ b/core/modules/link/lib/Drupal/link/Plugin/field/formatter/LinkFormatter.php @@ -117,8 +117,9 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $element = array(); + $entity = $items->getparent(); $settings = $this->getSettings(); foreach ($items as $delta => $item) { diff --git a/core/modules/link/lib/Drupal/link/Plugin/field/formatter/LinkSeparateFormatter.php b/core/modules/link/lib/Drupal/link/Plugin/field/formatter/LinkSeparateFormatter.php index f249bbe..e8e8fe0 100644 --- a/core/modules/link/lib/Drupal/link/Plugin/field/formatter/LinkSeparateFormatter.php +++ b/core/modules/link/lib/Drupal/link/Plugin/field/formatter/LinkSeparateFormatter.php @@ -38,8 +38,9 @@ class LinkSeparateFormatter extends LinkFormatter { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $element = array(); + $entity = $items->getParent(); $settings = $this->getSettings(); foreach ($items as $delta => $item) { diff --git a/core/modules/link/lib/Drupal/link/Plugin/field/widget/LinkWidget.php b/core/modules/link/lib/Drupal/link/Plugin/field/widget/LinkWidget.php index fc37e35..03b9c4d 100644 --- a/core/modules/link/lib/Drupal/link/Plugin/field/widget/LinkWidget.php +++ b/core/modules/link/lib/Drupal/link/Plugin/field/widget/LinkWidget.php @@ -32,7 +32,7 @@ class LinkWidget extends WidgetBase { /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { $element['url'] = array( '#type' => 'url', '#title' => t('URL'), diff --git a/core/modules/number/lib/Drupal/number/Plugin/field/formatter/DefaultNumberFormatter.php b/core/modules/number/lib/Drupal/number/Plugin/field/formatter/DefaultNumberFormatter.php index c639a25..cfd81b3 100644 --- a/core/modules/number/lib/Drupal/number/Plugin/field/formatter/DefaultNumberFormatter.php +++ b/core/modules/number/lib/Drupal/number/Plugin/field/formatter/DefaultNumberFormatter.php @@ -65,7 +65,7 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); $settings = $this->getFieldSettings(); diff --git a/core/modules/number/lib/Drupal/number/Plugin/field/formatter/NumberUnformattedFormatter.php b/core/modules/number/lib/Drupal/number/Plugin/field/formatter/NumberUnformattedFormatter.php index 75b6d6d..dc7c6bf 100644 --- a/core/modules/number/lib/Drupal/number/Plugin/field/formatter/NumberUnformattedFormatter.php +++ b/core/modules/number/lib/Drupal/number/Plugin/field/formatter/NumberUnformattedFormatter.php @@ -31,7 +31,7 @@ class NumberUnformattedFormatter extends FormatterBase { /** * Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements(). */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); foreach ($items as $delta => $item) { diff --git a/core/modules/number/lib/Drupal/number/Plugin/field/widget/NumberWidget.php b/core/modules/number/lib/Drupal/number/Plugin/field/widget/NumberWidget.php index c27909e..4dc9d21 100644 --- a/core/modules/number/lib/Drupal/number/Plugin/field/widget/NumberWidget.php +++ b/core/modules/number/lib/Drupal/number/Plugin/field/widget/NumberWidget.php @@ -64,7 +64,7 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { $value = isset($items[$delta]->value) ? $items[$delta]->value : NULL; $field_settings = $this->getFieldSettings(); diff --git a/core/modules/options/lib/Drupal/options/Plugin/field/formatter/OptionsDefaultFormatter.php b/core/modules/options/lib/Drupal/options/Plugin/field/formatter/OptionsDefaultFormatter.php index 312a164..e6f0165 100644 --- a/core/modules/options/lib/Drupal/options/Plugin/field/formatter/OptionsDefaultFormatter.php +++ b/core/modules/options/lib/Drupal/options/Plugin/field/formatter/OptionsDefaultFormatter.php @@ -32,9 +32,10 @@ class OptionsDefaultFormatter extends FormatterBase { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); + $entity = $items->getParent(); $allowed_values = options_allowed_values($this->fieldDefinition, $entity); foreach ($items as $delta => $item) { diff --git a/core/modules/options/lib/Drupal/options/Plugin/field/formatter/OptionsKeyFormatter.php b/core/modules/options/lib/Drupal/options/Plugin/field/formatter/OptionsKeyFormatter.php index af0fff1..06a6d27 100644 --- a/core/modules/options/lib/Drupal/options/Plugin/field/formatter/OptionsKeyFormatter.php +++ b/core/modules/options/lib/Drupal/options/Plugin/field/formatter/OptionsKeyFormatter.php @@ -32,7 +32,7 @@ class OptionsKeyFormatter extends FormatterBase { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); foreach ($items as $delta => $item) { diff --git a/core/modules/options/lib/Drupal/options/Plugin/field/widget/ButtonsWidget.php b/core/modules/options/lib/Drupal/options/Plugin/field/widget/ButtonsWidget.php index bee3e3b..2077e9c 100644 --- a/core/modules/options/lib/Drupal/options/Plugin/field/widget/ButtonsWidget.php +++ b/core/modules/options/lib/Drupal/options/Plugin/field/widget/ButtonsWidget.php @@ -31,8 +31,8 @@ class ButtonsWidget extends OptionsWidgetBase { /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { - $element = parent::formElement($items, $delta, $element, $langcode, $form, $form_state); + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { + $element = parent::formElement($items, $delta, $element, $form, $form_state); $options = $this->getOptions($items[$delta]); $selected = $this->getSelectedOptions($items); diff --git a/core/modules/options/lib/Drupal/options/Plugin/field/widget/OnOffWidget.php b/core/modules/options/lib/Drupal/options/Plugin/field/widget/OnOffWidget.php index 50cc08a..a7a94d9 100644 --- a/core/modules/options/lib/Drupal/options/Plugin/field/widget/OnOffWidget.php +++ b/core/modules/options/lib/Drupal/options/Plugin/field/widget/OnOffWidget.php @@ -56,8 +56,8 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { - $element = parent::formElement($items, $delta, $element, $langcode, $form, $form_state); + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { + $element = parent::formElement($items, $delta, $element, $form, $form_state); $options = $this->getOptions($items[$delta]); $selected = $this->getSelectedOptions($items); diff --git a/core/modules/options/lib/Drupal/options/Plugin/field/widget/OptionsWidgetBase.php b/core/modules/options/lib/Drupal/options/Plugin/field/widget/OptionsWidgetBase.php index f218438..4a6a26f 100644 --- a/core/modules/options/lib/Drupal/options/Plugin/field/widget/OptionsWidgetBase.php +++ b/core/modules/options/lib/Drupal/options/Plugin/field/widget/OptionsWidgetBase.php @@ -54,7 +54,7 @@ public function __construct($plugin_id, array $plugin_definition, FieldDefinitio /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { // Prepare some properties for the child methods to build the actual form // element. $this->required = $element['#required']; @@ -163,7 +163,7 @@ protected function getOptions(FieldItemInterface $item) { /** * Determines selected options from the incoming field values. * - * @param FieldInterface $items + * @param \Drupal\Core\Entity\Field\FieldInterface $items * The field values. * @param int $delta * (optional) The delta of the item to get options for. Defaults to 0. diff --git a/core/modules/options/lib/Drupal/options/Plugin/field/widget/SelectWidget.php b/core/modules/options/lib/Drupal/options/Plugin/field/widget/SelectWidget.php index 26fcbaf..a7c64ea 100644 --- a/core/modules/options/lib/Drupal/options/Plugin/field/widget/SelectWidget.php +++ b/core/modules/options/lib/Drupal/options/Plugin/field/widget/SelectWidget.php @@ -30,8 +30,8 @@ class SelectWidget extends OptionsWidgetBase { /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { - $element = parent::formElement($items, $delta, $element, $langcode, $form, $form_state); + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { + $element = parent::formElement($items, $delta, $element, $form, $form_state); $element += array( '#type' => 'select', diff --git a/core/modules/picture/lib/Drupal/picture/Plugin/field/formatter/PictureFormatter.php b/core/modules/picture/lib/Drupal/picture/Plugin/field/formatter/PictureFormatter.php index 9cfe0a8..5bec8a6 100644 --- a/core/modules/picture/lib/Drupal/picture/Plugin/field/formatter/PictureFormatter.php +++ b/core/modules/picture/lib/Drupal/picture/Plugin/field/formatter/PictureFormatter.php @@ -115,10 +115,11 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); // Check if the formatter involves a link. if ($this->getSetting('image_link') == 'content') { + $entity = $items->getParent(); $uri = $entity->uri(); } elseif ($this->getSetting('image_link') == 'file') { diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/EntityReferenceTaxonomyTermRssFormatter.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/EntityReferenceTaxonomyTermRssFormatter.php index de2d2fb..d52c2be 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/EntityReferenceTaxonomyTermRssFormatter.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/EntityReferenceTaxonomyTermRssFormatter.php @@ -32,8 +32,9 @@ class EntityReferenceTaxonomyTermRssFormatter extends EntityReferenceFormatterBa /** * Overrides Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase::viewElements(). */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); + $entity = $items->getParent(); foreach ($items as $delta => $item) { $entity->rss_elements[] = array( diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/LinkFormatter.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/LinkFormatter.php index 6ce9e53..3861f38 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/LinkFormatter.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/LinkFormatter.php @@ -30,7 +30,7 @@ class LinkFormatter extends TaxonomyFormatterBase { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); // Terms without target_id do not exist yet, theme such terms as just their diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/PlainFormatter.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/PlainFormatter.php index 36de426..2c76bfd 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/PlainFormatter.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/PlainFormatter.php @@ -29,7 +29,7 @@ class PlainFormatter extends TaxonomyFormatterBase { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); foreach ($items as $delta => $item) { diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/RSSCategoryFormatter.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/RSSCategoryFormatter.php index 69b0f2b..92b18f1 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/RSSCategoryFormatter.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/RSSCategoryFormatter.php @@ -29,7 +29,8 @@ class RSSCategoryFormatter extends TaxonomyFormatterBase { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { + $entity = $items->getParent(); // Terms whose target_id is 'autocreate' do not exist yet and // $item->entity is not set. Theme such terms as just their name. foreach ($items as $item) { diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/TaxonomyFormatterBase.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/TaxonomyFormatterBase.php index a0ed35f..93822b3 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/TaxonomyFormatterBase.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/TaxonomyFormatterBase.php @@ -24,12 +24,12 @@ * This preloads all taxonomy terms for multiple loaded objects at once and * unsets values for invalid terms that do not exist. */ - public function prepareView(array $entities, $langcode, array $items) { + public function prepareView(array $entities_items) { $tids = array(); // Collect every possible term attached to any of the fieldable entities. - foreach ($entities as $id => $entity) { - foreach ($items[$id] as $delta => $item) { + foreach ($entities_items as $entity_id => $items) { + foreach ($items as $delta => $item) { // Force the array key to prevent duplicates. if ($item->target_id !== 0) { $tids[$item->target_id] = $item->target_id; @@ -41,15 +41,15 @@ public function prepareView(array $entities, $langcode, array $items) { // Iterate through the fieldable entities again to attach the loaded term // data. - foreach ($entities as $id => $entity) { + foreach ($entities_items as $entity_id => $items) { $rekey = FALSE; - foreach ($items[$id] as $delta => $item) { + foreach ($items as $delta => $item) { // Check whether the taxonomy term field instance value could be // loaded. if (isset($terms[$item->target_id])) { // Replace the instance value with the term data. - $items[$id][$delta]->entity = $terms[$item->target_id]; + $item->entity = $terms[$item->target_id]; } // Terms to be created are not in $terms, but are still legitimate. elseif ($item->target_id === 0 && isset($item->entity)) { @@ -57,14 +57,14 @@ public function prepareView(array $entities, $langcode, array $items) { } // Otherwise, unset the instance value, since the term does not exist. else { - unset($items[$id][$delta]); + unset($items[$delta]); $rekey = TRUE; } } if ($rekey) { // Rekey the items array. - $items[$id]->setValue(array_values($items[$id]->getValue())); + $items->filterEmptyValues(); } } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php index b9b8b7c..bf8991a 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php @@ -65,7 +65,7 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { $tags = array(); foreach ($items as $item) { $tags[$item->target_id] = isset($item->taxonomy_term) ? $item->taxonomy_term : entity_load('taxonomy_term', $item->target_id); diff --git a/core/modules/telephone/lib/Drupal/telephone/Plugin/field/formatter/TelephoneLinkFormatter.php b/core/modules/telephone/lib/Drupal/telephone/Plugin/field/formatter/TelephoneLinkFormatter.php index d922984..2998610 100644 --- a/core/modules/telephone/lib/Drupal/telephone/Plugin/field/formatter/TelephoneLinkFormatter.php +++ b/core/modules/telephone/lib/Drupal/telephone/Plugin/field/formatter/TelephoneLinkFormatter.php @@ -62,38 +62,19 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function prepareView(array $entities, $langcode, array $items) { - $settings = $this->getSettings(); - - foreach ($entities as $id => $entity) { - foreach ($items[$id] as $item) { - // If available, set custom link text. - if (!empty($settings['title'])) { - $item->title = $settings['title']; - } - // Otherwise, use telephone number itself as title. - else { - $item->title = $item->value; - } - } - } - } - - /** - * {@inheritdoc} - */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $element = array(); + $title_setting = $this->getSetting('title'); foreach ($items as $delta => $item) { - // Prepend 'tel:' to the telephone number. - $href = 'tel:' . rawurlencode(preg_replace('/\s+/', '', $item->value)); - // Render each element as link. $element[$delta] = array( '#type' => 'link', - '#title' => $item->title, - '#href' => $href, + // Use custom title if available, otherwise use the telephone number + // itself as title. + '#title' => $title_setting ?: $item->value, + // Prepend 'tel:' to the telephone number. + '#href' => 'tel:' . rawurlencode(preg_replace('/\s+/', '', $item->value)), '#options' => array('external' => TRUE), ); } diff --git a/core/modules/telephone/lib/Drupal/telephone/Plugin/field/widget/TelephoneDefaultWidget.php b/core/modules/telephone/lib/Drupal/telephone/Plugin/field/widget/TelephoneDefaultWidget.php index e59adfc..52ee467 100644 --- a/core/modules/telephone/lib/Drupal/telephone/Plugin/field/widget/TelephoneDefaultWidget.php +++ b/core/modules/telephone/lib/Drupal/telephone/Plugin/field/widget/TelephoneDefaultWidget.php @@ -62,7 +62,7 @@ public function settingsSummary() { /** * Implements \Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement(). */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { $element['value'] = $element + array( '#type' => 'tel', '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL, diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php index 417d354..7ad122a 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php @@ -78,7 +78,6 @@ public function prepareCache() { $text_processing = $this->getFieldSetting('text_processing'); if (!$text_processing || filter_format_allowcache($this->get('format')->getValue())) { $itemBC = $this->getValue(); - $langcode = $this->getParent()->getParent()->language()->id; // The properties that need sanitizing are the ones that are the 'text // source' of a TextProcessed computed property. // @todo Clean up this mess by making the TextProcessed property type @@ -86,7 +85,7 @@ public function prepareCache() { foreach ($this->getPropertyDefinitions() as $definition) { if (isset($definition['class']) && ($definition['class'] == '\Drupal\text\TextProcessed')) { $source_property = $definition['settings']['text source']; - $this->set('safe_' . $source_property, text_sanitize($text_processing, $langcode, $itemBC, $source_property)); + $this->set('safe_' . $source_property, text_sanitize($text_processing, $this->getLangcode(), $itemBC, $source_property)); } } } diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextDefaultFormatter.php b/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextDefaultFormatter.php index dd0ee71..974d442 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextDefaultFormatter.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextDefaultFormatter.php @@ -34,14 +34,14 @@ class TextDefaultFormatter extends FormatterBase { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); foreach ($items as $delta => $item) { // @todo Convert text_sanitize() to work on an NG $item. See // https://drupal.org/node/2026339. $itemBC = $item->getValue(TRUE); - $output = text_sanitize($this->getFieldSetting('text_processing'), $langcode, $itemBC, 'value'); + $output = text_sanitize($this->getFieldSetting('text_processing'), $item->getLangcode(), $itemBC, 'value'); $elements[$delta] = array('#markup' => $output); } diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextPlainFormatter.php b/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextPlainFormatter.php index 2a95803..67daff4 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextPlainFormatter.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextPlainFormatter.php @@ -34,7 +34,7 @@ class TextPlainFormatter extends FormatterBase { /** * Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements(). */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); foreach ($items as $delta => $item) { diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextTrimmedFormatter.php b/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextTrimmedFormatter.php index f2ca9e4..d2d0b87 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextTrimmedFormatter.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextTrimmedFormatter.php @@ -65,16 +65,16 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) { + public function viewElements(FieldInterface $items) { $elements = array(); $text_processing = $this->getFieldSetting('text_processing'); foreach ($items as $delta => $item) { if ($this->getPluginId() == 'text_summary_or_trimmed' && !empty($item->summary)) { - $output = text_sanitize($text_processing, $langcode, $item->getValue(TRUE), 'summary'); + $output = text_sanitize($text_processing, $item->getLangcode(), $item->getValue(TRUE), 'summary'); } else { - $output = text_sanitize($text_processing, $langcode, $item->getValue(TRUE), 'value'); + $output = text_sanitize($text_processing, $item->getLangcode(), $item->getValue(TRUE), 'value'); $output = text_summary($output, $text_processing ? $item->format : NULL, $this->getSetting('trim_length')); } $elements[$delta] = array('#markup' => $output); diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextareaWidget.php b/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextareaWidget.php index bcddb6d..e764c60 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextareaWidget.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextareaWidget.php @@ -68,7 +68,7 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { $main_widget = $element + array( '#type' => 'textarea', '#default_value' => $items[$delta]->value, diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextareaWithSummaryWidget.php b/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextareaWithSummaryWidget.php index a6edca8..092b38f 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextareaWithSummaryWidget.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextareaWithSummaryWidget.php @@ -59,8 +59,8 @@ public function settingsSummary() { /** * {@inheritdoc} */ - function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { - $element = parent::formElement($items, $delta, $element, $langcode, $form, $form_state); + function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { + $element = parent::formElement($items, $delta, $element, $form, $form_state); $display_summary = $items[$delta]->summary || $this->getFieldSetting('display_summary'); $element['summary'] = array( diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextfieldWidget.php b/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextfieldWidget.php index 3a24d37..06e61ad 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextfieldWidget.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextfieldWidget.php @@ -68,7 +68,7 @@ public function settingsSummary() { /** * {@inheritdoc} */ - public function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) { + public function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) { $main_widget = $element + array( '#type' => 'textfield', '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL, diff --git a/core/modules/text/lib/Drupal/text/TextProcessed.php b/core/modules/text/lib/Drupal/text/TextProcessed.php index 352420d..27ea7f6 100644 --- a/core/modules/text/lib/Drupal/text/TextProcessed.php +++ b/core/modules/text/lib/Drupal/text/TextProcessed.php @@ -70,7 +70,7 @@ public function getValue($langcode = NULL) { $instance = field_info_instance($entity->entityType(), $field->getName(), $entity->bundle()); if (!empty($instance['settings']['text_processing']) && $this->format->getValue()) { - return check_markup($this->text->getValue(), $this->format->getValue(), $entity->language()->id); + return check_markup($this->text->getValue(), $this->format->getValue(), $field->getLangcode()); } else { // If no format is available, still make sure to sanitize the text.