Issue #2075095 by yched, amateescu: Widget / Formatter methods signatures needlessly complex.
parent
4b7a30edd0
commit
034d956906
|
@ -11,7 +11,6 @@ use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Datetime\Date;
|
use Drupal\Core\Datetime\Date;
|
||||||
use Drupal\Core\Datetime\DrupalDateTime;
|
use Drupal\Core\Datetime\DrupalDateTime;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\EntityStorageControllerInterface;
|
use Drupal\Core\Entity\EntityStorageControllerInterface;
|
||||||
use Drupal\Core\Entity\Field\FieldDefinitionInterface;
|
use Drupal\Core\Entity\Field\FieldDefinitionInterface;
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
@ -95,7 +94,7 @@ class DateTimeDefaultFormatter extends FormatterBase implements ContainerFactory
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
|
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\datetime\Plugin\field\formatter;
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\Core\Datetime\DrupalDateTime;
|
use Drupal\Core\Datetime\DrupalDateTime;
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@ class DateTimePlainFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
|
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
|
|
|
@ -9,13 +9,9 @@ namespace Drupal\datetime\Plugin\field\widget;
|
||||||
use Drupal\field\Annotation\FieldWidget;
|
use Drupal\field\Annotation\FieldWidget;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\field\Plugin\Type\Widget\WidgetBase;
|
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\FieldDefinitionInterface;
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\field\Plugin\PluginSettingsBase;
|
|
||||||
use Drupal\field\FieldInstanceInterface;
|
use Drupal\field\FieldInstanceInterface;
|
||||||
use Drupal\Core\Datetime\DrupalDateTime;
|
|
||||||
use Drupal\datetime\DateHelper;
|
use Drupal\datetime\DateHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,7 +58,7 @@ class DateTimeDatelistWidget extends WidgetBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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');
|
$date_order = $this->getSetting('date_order');
|
||||||
$time_type = $this->getSetting('time_type');
|
$time_type = $this->getSetting('time_type');
|
||||||
$increment = $this->getSetting('increment');
|
$increment = $this->getSetting('increment');
|
||||||
|
|
|
@ -9,13 +9,9 @@ namespace Drupal\datetime\Plugin\field\widget;
|
||||||
use Drupal\field\Annotation\FieldWidget;
|
use Drupal\field\Annotation\FieldWidget;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\field\Plugin\Type\Widget\WidgetBase;
|
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\FieldDefinitionInterface;
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\field\Plugin\PluginSettingsBase;
|
|
||||||
use Drupal\field\FieldInstanceInterface;
|
use Drupal\field\FieldInstanceInterface;
|
||||||
use Drupal\Core\Datetime\DrupalDateTime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin implementation of the 'datetime_default' widget.
|
* Plugin implementation of the 'datetime_default' widget.
|
||||||
|
@ -66,7 +62,7 @@ class DateTimeDefaultWidget extends WidgetBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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();
|
$format_type = datetime_default_format_type();
|
||||||
|
|
||||||
// We are nesting some sub-elements inside the parent, so we need a wrapper.
|
// We are nesting some sub-elements inside the parent, so we need a wrapper.
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\email\Plugin\field\formatter;
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,7 +28,7 @@ class MailToFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
|
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -61,7 +61,7 @@ class EmailDefaultWidget extends WidgetBase {
|
||||||
/**
|
/**
|
||||||
* Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement().
|
* 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(
|
$element['value'] = $element + array(
|
||||||
'#type' => 'email',
|
'#type' => 'email',
|
||||||
'#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL,
|
'#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL,
|
||||||
|
|
|
@ -9,7 +9,6 @@ namespace Drupal\entity_reference\Plugin\field\formatter;
|
||||||
|
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\entity_reference\RecursiveRenderingException;
|
use Drupal\entity_reference\RecursiveRenderingException;
|
||||||
use Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase;
|
use Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase;
|
||||||
|
@ -79,7 +78,7 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$view_mode = $this->getSetting('view_mode');
|
$view_mode = $this->getSetting('view_mode');
|
||||||
$links = $this->getSetting('links');
|
$links = $this->getSetting('links');
|
||||||
|
|
||||||
|
@ -96,13 +95,13 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase {
|
||||||
static $depth = 0;
|
static $depth = 0;
|
||||||
$depth++;
|
$depth++;
|
||||||
if ($depth > 20) {
|
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)) {
|
if (!empty($item->target_id)) {
|
||||||
$entity = clone $item->entity;
|
$entity = clone $item->entity;
|
||||||
unset($entity->content);
|
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'])) {
|
if (empty($links) && isset($result[$delta][$target_type][$item->target_id]['links'])) {
|
||||||
// Hide the element links.
|
// Hide the element links.
|
||||||
|
@ -111,11 +110,12 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// This is an "auto_create" item.
|
// This is an "auto_create" item.
|
||||||
$elements[$delta] = array('#markup' => $entity->label());
|
$elements[$delta] = array('#markup' => $item->entity->label());
|
||||||
}
|
}
|
||||||
$depth = 0;
|
$depth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $elements;
|
return $elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,6 @@
|
||||||
|
|
||||||
namespace Drupal\entity_reference\Plugin\field\formatter;
|
namespace Drupal\entity_reference\Plugin\field\formatter;
|
||||||
|
|
||||||
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;
|
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,13 +21,13 @@ abstract class EntityReferenceFormatterBase extends FormatterBase {
|
||||||
* values, as other may want to act on those values, even if they can
|
* values, as other may want to act on those values, even if they can
|
||||||
* not be accessed.
|
* not be accessed.
|
||||||
*/
|
*/
|
||||||
public function prepareView(array $entities, $langcode, array $items) {
|
public function prepareView(array $entities_items) {
|
||||||
$target_ids = array();
|
$target_ids = array();
|
||||||
$revision_ids = array();
|
$revision_ids = array();
|
||||||
|
|
||||||
// Collect every possible entity attached to any of the entities.
|
// Collect every possible entity attached to any of the entities.
|
||||||
foreach ($entities as $id => $entity) {
|
foreach ($entities_items as $items) {
|
||||||
foreach ($items[$id] as $item) {
|
foreach ($items as $item) {
|
||||||
if (!empty($item->revision_id)) {
|
if (!empty($item->revision_id)) {
|
||||||
$revision_ids[] = $item->revision_id;
|
$revision_ids[] = $item->revision_id;
|
||||||
}
|
}
|
||||||
|
@ -52,31 +48,30 @@ abstract class EntityReferenceFormatterBase extends FormatterBase {
|
||||||
if ($revision_ids) {
|
if ($revision_ids) {
|
||||||
// We need to load the revisions one by-one.
|
// We need to load the revisions one by-one.
|
||||||
foreach ($revision_ids as $revision_id) {
|
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.
|
// Use the revision ID in the key.
|
||||||
$identifier = $entity->id() . ':' . $revision_id;
|
$identifier = $target_entity->id() . ':' . $revision_id;
|
||||||
$target_entities[$identifier] = $entity;
|
$target_entities[$identifier] = $target_entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate through the fieldable entities again to attach the loaded data.
|
// Iterate through the fieldable entities again to attach the loaded data.
|
||||||
foreach ($entities as $id => $entity) {
|
foreach ($entities_items as $items) {
|
||||||
$rekey = FALSE;
|
$rekey = FALSE;
|
||||||
foreach ($items[$id] as $delta => $item) {
|
foreach ($items as $item) {
|
||||||
// If we have a revision ID, the key uses it as well.
|
// 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;
|
$identifier = !empty($item->revision_id) ? $item->target_id . ':' . $item->revision_id : $item->target_id;
|
||||||
if ($item->target_id !== 0) {
|
if ($item->target_id !== 0) {
|
||||||
if (!isset($target_entities[$identifier])) {
|
if (!isset($target_entities[$identifier])) {
|
||||||
// The entity no longer exists, so remove the key.
|
// The entity no longer exists, so empty the item.
|
||||||
|
$item->setValue(NULL);
|
||||||
$rekey = TRUE;
|
$rekey = TRUE;
|
||||||
unset($items[$id][$delta]);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$entity = $target_entities[$identifier];
|
$item->entity = $target_entities[$identifier];
|
||||||
$item->entity = $entity;
|
|
||||||
|
|
||||||
if (!$entity->access('view')) {
|
if (!$item->entity->access('view')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,10 +83,11 @@ abstract class EntityReferenceFormatterBase extends FormatterBase {
|
||||||
$item->access = TRUE;
|
$item->access = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rekey the items array if needed.
|
||||||
if ($rekey) {
|
if ($rekey) {
|
||||||
// Rekey the items array.
|
$items->filterEmptyValues();
|
||||||
$items[$id] = array_values($items[$id]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ namespace Drupal\entity_reference\Plugin\field\formatter;
|
||||||
|
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase;
|
use Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase;
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@ class EntityReferenceIdFormatter extends EntityReferenceFormatterBase {
|
||||||
/**
|
/**
|
||||||
* Overrides \Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase::viewElements().
|
* Overrides \Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase::viewElements().
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -9,7 +9,6 @@ namespace Drupal\entity_reference\Plugin\field\formatter;
|
||||||
|
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase;
|
use Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase;
|
||||||
|
|
||||||
|
@ -55,7 +54,7 @@ class EntityReferenceLabelFormatter extends EntityReferenceFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
@ -83,4 +82,5 @@ class EntityReferenceLabelFormatter extends EntityReferenceFormatterBase {
|
||||||
|
|
||||||
return $elements;
|
return $elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ class AutocompleteWidget extends AutocompleteWidgetBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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
|
// We let the Field API handles multiple values for us, only take care of
|
||||||
// the one matching our delta.
|
// the one matching our delta.
|
||||||
if (isset($items[$delta])) {
|
if (isset($items[$delta])) {
|
||||||
|
@ -50,7 +50,7 @@ class AutocompleteWidget extends AutocompleteWidgetBase {
|
||||||
$items->setValue(array());
|
$items->setValue(array());
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::formElement($items, $delta, $element, $langcode, $form, $form_state);
|
return parent::formElement($items, $delta, $element, $form, $form_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -70,9 +70,10 @@ abstract class AutocompleteWidgetBase extends WidgetBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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;
|
global $user;
|
||||||
$entity = $element['#entity'];
|
|
||||||
|
$entity = $items->getEntity();
|
||||||
|
|
||||||
// Prepare the autocomplete path.
|
// Prepare the autocomplete path.
|
||||||
$autocomplete_path = $this->getSetting('autocomplete_path');
|
$autocomplete_path = $this->getSetting('autocomplete_path');
|
||||||
|
|
|
@ -198,10 +198,8 @@ function hook_field_widget_info_alter(array &$info) {
|
||||||
* - form: The form structure to which widgets are being attached. This may be
|
* - 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.
|
* a full form structure, or a sub-element of a larger form.
|
||||||
* - widget: The widget plugin instance.
|
* - widget: The widget plugin instance.
|
||||||
* - field_definition: The field definition.
|
* - items: The field values, as a \Drupal\Core\Entity\Field\FieldInterface
|
||||||
* - entity: The entity.
|
* object.
|
||||||
* - langcode: The language associated with $items.
|
|
||||||
* - items: Array of default values for this field.
|
|
||||||
* - delta: The order of this item in the array of subelements (0, 1, 2, etc).
|
* - 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
|
* - default: A boolean indicating whether the form is being shown as a dummy
|
||||||
* form to set default values.
|
* form to set default values.
|
||||||
|
@ -211,7 +209,8 @@ function hook_field_widget_info_alter(array &$info) {
|
||||||
*/
|
*/
|
||||||
function hook_field_widget_form_alter(&$element, &$form_state, $context) {
|
function hook_field_widget_form_alter(&$element, &$form_state, $context) {
|
||||||
// Add a css class to widget form elements for all fields of type mytype.
|
// 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.
|
// Be sure not to overwrite existing attributes.
|
||||||
$element['#attributes']['class'][] = 'myclass';
|
$element['#attributes']['class'][] = 'myclass';
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ function field_invoke_method($method, $target_function, EntityInterface $entity,
|
||||||
$items = $entity->getTranslation($langcode)->get($field_name);
|
$items = $entity->getTranslation($langcode)->get($field_name);
|
||||||
$items->filterEmptyValues();
|
$items->filterEmptyValues();
|
||||||
|
|
||||||
$result = $target->$method($entity, $langcode, $items, $a, $b);
|
$result = $target->$method($items, $a, $b);
|
||||||
|
|
||||||
if (isset($result)) {
|
if (isset($result)) {
|
||||||
// For methods with array results, we merge results together.
|
// For methods with array results, we merge results together.
|
||||||
|
@ -187,7 +187,6 @@ function field_invoke_method_multiple($method, $target_function, array $entities
|
||||||
$options += $default_options;
|
$options += $default_options;
|
||||||
|
|
||||||
$instances = array();
|
$instances = array();
|
||||||
$grouped_entities = array();
|
|
||||||
$grouped_items = array();
|
$grouped_items = array();
|
||||||
$grouped_targets = array();
|
$grouped_targets = array();
|
||||||
$return = array();
|
$return = array();
|
||||||
|
@ -224,8 +223,7 @@ function field_invoke_method_multiple($method, $target_function, array $entities
|
||||||
$langcode = !empty($options['langcode'][$id]) ? $options['langcode'][$id] : $options['langcode'];
|
$langcode = !empty($options['langcode'][$id]) ? $options['langcode'][$id] : $options['langcode'];
|
||||||
$langcodes = _field_language_suggestion($available_langcodes, $langcode, $field_name);
|
$langcodes = _field_language_suggestion($available_langcodes, $langcode, $field_name);
|
||||||
foreach ($langcodes as $langcode) {
|
foreach ($langcodes as $langcode) {
|
||||||
// Group the entities and items corresponding to the current field.
|
// Group the items corresponding to the current field.
|
||||||
$grouped_entities[$instance_id][$langcode][$id] = $entities[$id];
|
|
||||||
$items = $entity->getTranslation($langcode)->get($field_name);
|
$items = $entity->getTranslation($langcode)->get($field_name);
|
||||||
$items->filterEmptyValues();
|
$items->filterEmptyValues();
|
||||||
$grouped_items[$instance_id][$langcode][$id] = $items;
|
$grouped_items[$instance_id][$langcode][$id] = $items;
|
||||||
|
@ -238,12 +236,9 @@ function field_invoke_method_multiple($method, $target_function, array $entities
|
||||||
|
|
||||||
// For each instance, invoke the method and collect results.
|
// For each instance, invoke the method and collect results.
|
||||||
foreach ($instances as $instance_id => $instance) {
|
foreach ($instances as $instance_id => $instance) {
|
||||||
$field_name = $instance['field_name'];
|
|
||||||
|
|
||||||
// Iterate over all the field translations.
|
// Iterate over all the field translations.
|
||||||
foreach ($grouped_items[$instance_id] as $langcode => $items) {
|
foreach ($grouped_items[$instance_id] as $langcode => $items) {
|
||||||
$entities = $grouped_entities[$instance_id][$langcode];
|
$results = $grouped_targets[$instance_id]->$method($items, $a, $b);
|
||||||
$results = $grouped_targets[$instance_id]->$method($entities, $langcode, $items, $a, $b);
|
|
||||||
|
|
||||||
if (isset($results)) {
|
if (isset($results)) {
|
||||||
// Collect results by entity.
|
// Collect results by entity.
|
||||||
|
|
|
@ -697,9 +697,8 @@ function field_view_field(EntityInterface $entity, $field_name, $display_options
|
||||||
|
|
||||||
// Invoke the formatter's prepareView() and view() methods.
|
// Invoke the formatter's prepareView() and view() methods.
|
||||||
$items = $entity->getTranslation($display_langcode)->get($field_name);
|
$items = $entity->getTranslation($display_langcode)->get($field_name);
|
||||||
$id = $entity->id();
|
$formatter->prepareView(array($entity->id() => $items));
|
||||||
$formatter->prepareView(array($id => $entity), $display_langcode, array($id => $items));
|
$result = $formatter->view($items);
|
||||||
$result = $formatter->view($entity, $display_langcode, $items);
|
|
||||||
|
|
||||||
// Invoke hook_field_attach_view_alter() to let other modules alter the
|
// Invoke hook_field_attach_view_alter() to let other modules alter the
|
||||||
// renderable array, as in a full field_attach_view() execution.
|
// renderable array, as in a full field_attach_view() execution.
|
||||||
|
|
|
@ -34,7 +34,7 @@ use Drupal\Core\Entity\EntityInterface;
|
||||||
* is attached to supports translation.
|
* is attached to supports translation.
|
||||||
*
|
*
|
||||||
* By default, field_invoke_method() processes a field in all available
|
* 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.
|
* suggestion, _field_language_suggestion() determines the languages to act on.
|
||||||
*
|
*
|
||||||
* Most field_attach_*() functions act on all available language codes, except
|
* Most field_attach_*() functions act on all available language codes, except
|
||||||
|
|
|
@ -78,11 +78,10 @@ class ConfigField extends Field implements ConfigFieldInterface {
|
||||||
*/
|
*/
|
||||||
public function defaultValuesForm(array &$form, array &$form_state) {
|
public function defaultValuesForm(array &$form, array &$form_state) {
|
||||||
if (empty($this->getFieldDefinition()->default_value_function)) {
|
if (empty($this->getFieldDefinition()->default_value_function)) {
|
||||||
$widget = $this->defaultValueWidget($form_state);
|
|
||||||
|
|
||||||
// Place the input in a separate place in the submitted values tree.
|
// 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 = array('#parents' => array('default_value_input'));
|
||||||
$element += $widget->form($this->getEntity(), $this->getLangcode(), $this, $element, $form_state);
|
$element += $widget->form($this, $element, $form_state);
|
||||||
|
|
||||||
return $element;
|
return $element;
|
||||||
}
|
}
|
||||||
|
@ -92,12 +91,9 @@ class ConfigField extends Field implements ConfigFieldInterface {
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function defaultValuesFormValidate(array $element, array &$form, array &$form_state) {
|
public function defaultValuesFormValidate(array $element, array &$form, array &$form_state) {
|
||||||
$entity = $this->getEntity();
|
|
||||||
$langcode = $this->getLangcode();
|
|
||||||
|
|
||||||
// Extract the submitted value, and validate it.
|
// Extract the submitted value, and validate it.
|
||||||
$widget = $this->defaultValueWidget($form_state);
|
$widget = $this->defaultValueWidget($form_state);
|
||||||
$widget->extractFormValues($entity, $langcode, $this, $element, $form_state);
|
$widget->extractFormValues($this, $element, $form_state);
|
||||||
$violations = $this->validate();
|
$violations = $this->validate();
|
||||||
|
|
||||||
if (count($violations)) {
|
if (count($violations)) {
|
||||||
|
@ -108,7 +104,7 @@ class ConfigField extends Field implements ConfigFieldInterface {
|
||||||
field_form_set_state($element['#parents'], $field_name, $form_state, $field_state);
|
field_form_set_state($element['#parents'], $field_name, $form_state, $field_state);
|
||||||
|
|
||||||
// Assign reported errors to the correct form element.
|
// Assign reported errors to the correct form element.
|
||||||
$widget->flagErrors($entity, $langcode, $this, $element, $form_state);
|
$widget->flagErrors($this, $element, $form_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +114,7 @@ class ConfigField extends Field implements ConfigFieldInterface {
|
||||||
public function defaultValuesFormSubmit(array $element, array &$form, array &$form_state) {
|
public function defaultValuesFormSubmit(array $element, array &$form, array &$form_state) {
|
||||||
// Extract the submitted value, and return it as an array.
|
// Extract the submitted value, and return it as an array.
|
||||||
$widget = $this->defaultValueWidget($form_state);
|
$widget = $this->defaultValueWidget($form_state);
|
||||||
$widget->extractFormValues($this->getEntity(), $this->getLangcode(), $this, $element, $form_state);
|
$widget->extractFormValues($this, $element, $form_state);
|
||||||
return $this->getValue();
|
return $this->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
namespace Drupal\field\Plugin\Type\Formatter;
|
namespace Drupal\field\Plugin\Type\Formatter;
|
||||||
|
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldDefinitionInterface;
|
use Drupal\Core\Entity\Field\FieldDefinitionInterface;
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\field\FieldInstanceInterface;
|
use Drupal\field\FieldInstanceInterface;
|
||||||
|
@ -74,11 +73,12 @@ abstract class FormatterBase extends PluginSettingsBase implements FormatterInte
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function view(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function view(FieldInterface $items) {
|
||||||
$addition = array();
|
$addition = array();
|
||||||
|
|
||||||
$elements = $this->viewElements($entity, $langcode, $items);
|
$elements = $this->viewElements($items);
|
||||||
if ($elements) {
|
if ($elements) {
|
||||||
|
$entity = $items->getEntity();
|
||||||
$entity_type = $entity->entityType();
|
$entity_type = $entity->entityType();
|
||||||
$field_name = $this->fieldDefinition->getFieldName();
|
$field_name = $this->fieldDefinition->getFieldName();
|
||||||
$info = array(
|
$info = array(
|
||||||
|
@ -87,7 +87,7 @@ abstract class FormatterBase extends PluginSettingsBase implements FormatterInte
|
||||||
'#access' => $this->checkFieldAccess('view', $entity),
|
'#access' => $this->checkFieldAccess('view', $entity),
|
||||||
'#label_display' => $this->label,
|
'#label_display' => $this->label,
|
||||||
'#view_mode' => $this->viewMode,
|
'#view_mode' => $this->viewMode,
|
||||||
'#language' => $langcode,
|
'#language' => $items->getLangcode(),
|
||||||
'#field_name' => $field_name,
|
'#field_name' => $field_name,
|
||||||
'#field_type' => $this->fieldDefinition->getFieldType(),
|
'#field_type' => $this->fieldDefinition->getFieldType(),
|
||||||
'#field_translatable' => $this->fieldDefinition->isFieldTranslatable(),
|
'#field_translatable' => $this->fieldDefinition->isFieldTranslatable(),
|
||||||
|
@ -121,7 +121,7 @@ abstract class FormatterBase extends PluginSettingsBase implements FormatterInte
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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.
|
* Returns whether the currently logged in user has access to the field.
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
namespace Drupal\field\Plugin\Type\Formatter;
|
namespace Drupal\field\Plugin\Type\Formatter;
|
||||||
|
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\field\Plugin\PluginSettingsInterface;
|
use Drupal\field\Plugin\PluginSettingsInterface;
|
||||||
|
|
||||||
|
@ -61,45 +60,33 @@ interface FormatterInterface extends PluginSettingsInterface {
|
||||||
* Changes or additions to field values are done by alterings the $items
|
* Changes or additions to field values are done by alterings the $items
|
||||||
* parameter by reference.
|
* parameter by reference.
|
||||||
*
|
*
|
||||||
* @param array $entities
|
* @param array $entities_items
|
||||||
* Array of entities being displayed, keyed by entity ID.
|
* Array of field values (Drupal\Core\Entity\Field\FieldInterface), keyed by
|
||||||
* @param string $langcode
|
* entity ID.
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
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.
|
* 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
|
* @param Drupal\Core\Entity\Field\FieldInterface $items
|
||||||
* The field value for the entity for the language.
|
* The field values to be rendered.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* A renderable array for a themed field with its label and all its values.
|
* 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.
|
* Builds a renderable array for a field value.
|
||||||
*
|
*
|
||||||
* @param Drupal\Core\Entity\EntityInterface $entity
|
* @param Drupal\Core\Entity\Field\FieldInterface $items
|
||||||
* The entity being displayed.
|
* The field values to be rendered.
|
||||||
* @param string $langcode
|
|
||||||
* The language associated with $items.
|
|
||||||
* @param array $items
|
|
||||||
* Array of values for this field.
|
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* A renderable array for $items, as an array of child elements keyed by
|
* A renderable array for $items, as an array of child elements keyed by
|
||||||
* numeric indexes starting from 0.
|
* numeric indexes starting from 0.
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items);
|
public function viewElements(FieldInterface $items);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
namespace Drupal\field\Plugin\Type\Widget;
|
namespace Drupal\field\Plugin\Type\Widget;
|
||||||
|
|
||||||
use Drupal\Component\Utility\NestedArray;
|
use Drupal\Component\Utility\NestedArray;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldDefinitionInterface;
|
use Drupal\Core\Entity\Field\FieldDefinitionInterface;
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\field\FieldInstanceInterface;
|
use Drupal\field\FieldInstanceInterface;
|
||||||
|
@ -56,7 +55,7 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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();
|
$field_name = $this->fieldDefinition->getFieldName();
|
||||||
$parents = $form['#parents'];
|
$parents = $form['#parents'];
|
||||||
|
|
||||||
|
@ -83,7 +82,7 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
|
||||||
'#title' => check_plain($this->fieldDefinition->getFieldLabel()),
|
'#title' => check_plain($this->fieldDefinition->getFieldLabel()),
|
||||||
'#description' => field_filter_xss(\Drupal::token()->replace($this->fieldDefinition->getFieldDescription())),
|
'#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 ($element) {
|
||||||
if (isset($get_delta)) {
|
if (isset($get_delta)) {
|
||||||
|
@ -102,7 +101,7 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
|
||||||
// If the widget does not handle multiple values itself, (and we are not
|
// If the widget does not handle multiple values itself, (and we are not
|
||||||
// displaying an individual element), process the multiple value form.
|
// displaying an individual element), process the multiple value form.
|
||||||
else {
|
else {
|
||||||
$elements = $this->formMultipleElements($entity, $items, $langcode, $form, $form_state);
|
$elements = $this->formMultipleElements($items, $form, $form_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate the 'array_parents' information in $form_state['field'] after
|
// Populate the 'array_parents' information in $form_state['field'] after
|
||||||
|
@ -110,8 +109,6 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
|
||||||
// in alter() hooks.
|
// in alter() hooks.
|
||||||
$elements['#after_build'][] = 'field_form_element_after_build';
|
$elements['#after_build'][] = 'field_form_element_after_build';
|
||||||
$elements['#field_name'] = $field_name;
|
$elements['#field_name'] = $field_name;
|
||||||
// @todo Not strictly needed anymore.
|
|
||||||
$elements['#language'] = $langcode;
|
|
||||||
$elements['#field_parents'] = $parents;
|
$elements['#field_parents'] = $parents;
|
||||||
// Enforce the structure of submitted values.
|
// Enforce the structure of submitted values.
|
||||||
$elements['#parents'] = array_merge($parents, array($field_name));
|
$elements['#parents'] = array_merge($parents, array($field_name));
|
||||||
|
@ -131,7 +128,7 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
|
||||||
'field-widget-' . drupal_html_class($this->getPluginId()),
|
'field-widget-' . drupal_html_class($this->getPluginId()),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'#access' => $this->checkFieldAccess('edit', $entity),
|
'#access' => $this->checkFieldAccess('edit', $items->getEntity()),
|
||||||
'widget' => $elements,
|
'widget' => $elements,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -147,7 +144,7 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
|
||||||
* - AHAH-'add more' button
|
* - AHAH-'add more' button
|
||||||
* - table display and drag-n-drop value reordering
|
* - 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();
|
$field_name = $this->fieldDefinition->getFieldName();
|
||||||
$cardinality = $this->fieldDefinition->getFieldCardinality();
|
$cardinality = $this->fieldDefinition->getFieldCardinality();
|
||||||
$parents = $form['#parents'];
|
$parents = $form['#parents'];
|
||||||
|
@ -181,7 +178,7 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
|
||||||
'#title' => $is_multiple ? '' : $title,
|
'#title' => $is_multiple ? '' : $title,
|
||||||
'#description' => $is_multiple ? '' : $description,
|
'#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) {
|
if ($element) {
|
||||||
// Input field for the delta (drag-n-drop reordering).
|
// Input field for the delta (drag-n-drop reordering).
|
||||||
|
@ -223,7 +220,7 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
|
||||||
'#name' => strtr($id_prefix, '-', '_') . '_add_more',
|
'#name' => strtr($id_prefix, '-', '_') . '_add_more',
|
||||||
'#value' => t('Add another item'),
|
'#value' => t('Add another item'),
|
||||||
'#attributes' => array('class' => array('field-add-more-submit')),
|
'#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))),
|
||||||
'#submit' => array('field_add_more_submit'),
|
'#submit' => array('field_add_more_submit'),
|
||||||
'#ajax' => array(
|
'#ajax' => array(
|
||||||
'callback' => 'field_add_more_js',
|
'callback' => 'field_add_more_js',
|
||||||
|
@ -240,13 +237,15 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
|
||||||
/**
|
/**
|
||||||
* Generates the form element for a single copy of the widget.
|
* 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->getEntity();
|
||||||
|
|
||||||
$element += array(
|
$element += array(
|
||||||
'#entity_type' => $entity->entityType(),
|
'#entity_type' => $entity->entityType(),
|
||||||
'#bundle' => $entity->bundle(),
|
'#bundle' => $entity->bundle(),
|
||||||
'#entity' => $entity,
|
'#entity' => $entity,
|
||||||
'#field_name' => $this->fieldDefinition->getFieldName(),
|
'#field_name' => $this->fieldDefinition->getFieldName(),
|
||||||
'#language' => $langcode,
|
'#language' => $items->getLangcode(),
|
||||||
'#field_parents' => $form['#parents'],
|
'#field_parents' => $form['#parents'],
|
||||||
// Only the first widget should be required.
|
// Only the first widget should be required.
|
||||||
'#required' => $delta == 0 && $this->fieldDefinition->isFieldRequired(),
|
'#required' => $delta == 0 && $this->fieldDefinition->isFieldRequired(),
|
||||||
|
@ -254,16 +253,13 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
|
||||||
'#weight' => $delta,
|
'#weight' => $delta,
|
||||||
);
|
);
|
||||||
|
|
||||||
$element = $this->formElement($items, $delta, $element, $langcode, $form, $form_state);
|
$element = $this->formElement($items, $delta, $element, $form, $form_state);
|
||||||
|
|
||||||
if ($element) {
|
if ($element) {
|
||||||
// Allow modules to alter the field widget form element.
|
// Allow modules to alter the field widget form element.
|
||||||
$context = array(
|
$context = array(
|
||||||
'form' => $form,
|
'form' => $form,
|
||||||
'widget' => $this,
|
'widget' => $this,
|
||||||
'field_definition' => $this->fieldDefinition,
|
|
||||||
'entity' => $entity,
|
|
||||||
'langcode' => $langcode,
|
|
||||||
'items' => $items,
|
'items' => $items,
|
||||||
'delta' => $delta,
|
'delta' => $delta,
|
||||||
'default' => !empty($entity->field_ui_default_value),
|
'default' => !empty($entity->field_ui_default_value),
|
||||||
|
@ -277,7 +273,7 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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();
|
$field_name = $this->fieldDefinition->getFieldName();
|
||||||
|
|
||||||
// Extract the values from $form_state['values'].
|
// Extract the values from $form_state['values'].
|
||||||
|
@ -330,7 +326,7 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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();
|
$field_name = $this->fieldDefinition->getFieldName();
|
||||||
|
|
||||||
$field_state = field_form_get_state($form['#parents'], $field_name, $form_state);
|
$field_state = field_form_get_state($form['#parents'], $field_name, $form_state);
|
||||||
|
@ -409,7 +405,7 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
|
||||||
/**
|
/**
|
||||||
* Sorts submitted field values according to drag-n-drop reordering.
|
* Sorts submitted field values according to drag-n-drop reordering.
|
||||||
*
|
*
|
||||||
* @param FieldInterface $items
|
* @param \Drupal\Core\Entity\Field\FieldInterface $items
|
||||||
* The field values.
|
* The field values.
|
||||||
*/
|
*/
|
||||||
protected function sortItems(FieldInterface $items) {
|
protected function sortItems(FieldInterface $items) {
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
namespace Drupal\field\Plugin\Type\Widget;
|
namespace Drupal\field\Plugin\Type\Widget;
|
||||||
|
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\field\Plugin\PluginSettingsInterface;
|
use Drupal\field\Plugin\PluginSettingsInterface;
|
||||||
|
|
||||||
|
@ -28,11 +27,7 @@ interface WidgetBaseInterface extends PluginSettingsInterface {
|
||||||
* TRUE), the 'default value', if any, is pre-populated. Also allows other
|
* TRUE), the 'default value', if any, is pre-populated. Also allows other
|
||||||
* modules to alter the form element by implementing their own hooks.
|
* modules to alter the form element by implementing their own hooks.
|
||||||
*
|
*
|
||||||
* @param Drupal\Core\Entity\EntityInterface $entity
|
* @param \Drupal\Core\Entity\Field\FieldInterface $items
|
||||||
* The entity for which the widget is being built.
|
|
||||||
* @param string $langcode
|
|
||||||
* The language associated with the field.
|
|
||||||
* @param FieldInterface $items
|
|
||||||
* An array of the field values. When creating a new entity this may be NULL
|
* An array of the field values. When creating a new entity this may be NULL
|
||||||
* or an empty array to use default values.
|
* or an empty array to use default values.
|
||||||
* @param array $form
|
* @param array $form
|
||||||
|
@ -46,16 +41,12 @@ interface WidgetBaseInterface extends PluginSettingsInterface {
|
||||||
* @return array
|
* @return array
|
||||||
* The form element array created for this field.
|
* 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.
|
* Extracts field values from submitted form values.
|
||||||
*
|
*
|
||||||
* @param Drupal\Core\Entity\EntityInterface $entity
|
* @param \Drupal\Core\Entity\Field\FieldInterface $items
|
||||||
* The entity for which the widget is being submitted.
|
|
||||||
* @param string $langcode
|
|
||||||
* The language associated to $items.
|
|
||||||
* @param FieldInterface $items
|
|
||||||
* The field values. This parameter is altered by reference to receive the
|
* The field values. This parameter is altered by reference to receive the
|
||||||
* incoming form values.
|
* incoming form values.
|
||||||
* @param array $form
|
* @param array $form
|
||||||
|
@ -64,16 +55,12 @@ interface WidgetBaseInterface extends PluginSettingsInterface {
|
||||||
* @param array $form_state
|
* @param array $form_state
|
||||||
* The 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.
|
* Reports field-level validation errors against actual form elements.
|
||||||
*
|
*
|
||||||
* @param Drupal\Core\Entity\EntityInterface $entity
|
* @param \Drupal\Core\Entity\Field\FieldInterface $items
|
||||||
* The entity for which the widget is being submitted.
|
|
||||||
* @param string $langcode
|
|
||||||
* The language associated to $items.
|
|
||||||
* @param FieldInterface $items
|
|
||||||
* The field values.
|
* The field values.
|
||||||
* @param array $form
|
* @param array $form
|
||||||
* The form structure where field elements are attached to. This might be a
|
* The form structure where field elements are attached to. This might be a
|
||||||
|
@ -81,6 +68,6 @@ interface WidgetBaseInterface extends PluginSettingsInterface {
|
||||||
* @param array $form_state
|
* @param array $form_state
|
||||||
* The 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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,6 @@
|
||||||
|
|
||||||
namespace Drupal\field\Plugin\Type\Widget;
|
namespace Drupal\field\Plugin\Type\Widget;
|
||||||
|
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\field\Entity\FieldInstance;
|
|
||||||
use Symfony\Component\Validator\ConstraintViolationInterface;
|
use Symfony\Component\Validator\ConstraintViolationInterface;
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
|
@ -75,7 +73,7 @@ interface WidgetInterface extends WidgetBaseInterface {
|
||||||
* definition and set them as ad-hoc $element['#custom'] properties, for later
|
* definition and set them as ad-hoc $element['#custom'] properties, for later
|
||||||
* use by its element callbacks.
|
* use by its element callbacks.
|
||||||
*
|
*
|
||||||
* @param FieldInterface $items
|
* @param \Drupal\Core\Entity\Field\FieldInterface $items
|
||||||
* Array of default values for this field.
|
* Array of default values for this field.
|
||||||
* @param int $delta
|
* @param int $delta
|
||||||
* The order of this item in the array of subelements (0, 1, 2, etc).
|
* The order of this item in the array of subelements (0, 1, 2, etc).
|
||||||
|
@ -101,8 +99,6 @@ interface WidgetInterface extends WidgetBaseInterface {
|
||||||
* required.
|
* required.
|
||||||
* - #delta: The order of this item in the array of subelements; see $delta
|
* - #delta: The order of this item in the array of subelements; see $delta
|
||||||
* above.
|
* above.
|
||||||
* @param string $langcode
|
|
||||||
* The language associated with $items.
|
|
||||||
* @param string $form
|
* @param string $form
|
||||||
* The form structure where widgets are being attached to. This might be a
|
* The form structure where widgets are being attached to. This might be a
|
||||||
* full form structure, or a sub-element of a larger form.
|
* full form structure, or a sub-element of a larger form.
|
||||||
|
@ -115,7 +111,7 @@ interface WidgetInterface extends WidgetBaseInterface {
|
||||||
* @see hook_field_widget_form_alter()
|
* @see hook_field_widget_form_alter()
|
||||||
* @see hook_field_widget_WIDGET_TYPE_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.
|
* Assigns a field-level validation error to the right widget sub-element.
|
||||||
|
|
|
@ -27,7 +27,7 @@ class HiddenWidget extends WidgetBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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.
|
// The purpose of this widget is to be hidden, so nothing to do here.
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,6 @@ class TranslationWebTest extends FieldTestBase {
|
||||||
$entity->save();
|
$entity->save();
|
||||||
|
|
||||||
// Create a new revision.
|
// Create a new revision.
|
||||||
$langcode = $entity->language()->id;
|
|
||||||
$edit = array(
|
$edit = array(
|
||||||
'user_id' => 1,
|
'user_id' => 1,
|
||||||
'name' => $this->randomName(),
|
'name' => $this->randomName(),
|
||||||
|
|
|
@ -153,7 +153,8 @@ function field_test_field_attach_view_alter(&$output, $context) {
|
||||||
* Implements hook_field_widget_form_alter().
|
* Implements hook_field_widget_form_alter().
|
||||||
*/
|
*/
|
||||||
function field_test_field_widget_form_alter(&$element, &$form_state, $context) {
|
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':
|
case 'alter_test_text':
|
||||||
drupal_set_message('Field size: ' . $context['widget']->getSetting('size'));
|
drupal_set_message('Field size: ' . $context['widget']->getSetting('size'));
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\field_test\Plugin\field\formatter;
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,7 +55,7 @@ class TestFieldDefaultFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -9,7 +9,6 @@ namespace Drupal\field_test\Plugin\field\formatter;
|
||||||
|
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
||||||
|
|
||||||
|
@ -32,7 +31,7 @@ class TestFieldEmptyFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
if ($items->isEmpty()) {
|
if ($items->isEmpty()) {
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\field_test\Plugin\field\formatter;
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,7 +55,7 @@ class TestFieldMultipleFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
if (!empty($items)) {
|
if (!empty($items)) {
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\field_test\Plugin\field\formatter;
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,9 +55,9 @@ class TestFieldPrepareViewFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function prepareView(array $entities, $langcode, array $items) {
|
public function prepareView(array $entities_items) {
|
||||||
foreach ($entities as $id => $entity) {
|
foreach ($entities_items as $items) {
|
||||||
foreach ($items[$id] as $delta => $item) {
|
foreach ($items as $item) {
|
||||||
// Don't add anything on empty values.
|
// Don't add anything on empty values.
|
||||||
if (!$item->isEmpty()) {
|
if (!$item->isEmpty()) {
|
||||||
$item->additional_formatter_value = $item->value + 1;
|
$item->additional_formatter_value = $item->value + 1;
|
||||||
|
@ -70,7 +69,7 @@ class TestFieldPrepareViewFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -56,7 +56,7 @@ class TestFieldWidget extends WidgetBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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(
|
$element += array(
|
||||||
'#type' => 'textfield',
|
'#type' => 'textfield',
|
||||||
'#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : '',
|
'#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : '',
|
||||||
|
|
|
@ -58,7 +58,7 @@ class TestFieldWidgetMultiple extends WidgetBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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();
|
$values = array();
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
$values[] = $item->value;
|
$values[] = $item->value;
|
||||||
|
|
|
@ -17,11 +17,11 @@ abstract class FileFormatterBase extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function prepareView(array $entities, $langcode, array $items) {
|
public function prepareView(array $entities_items) {
|
||||||
// Remove files specified to not be displayed.
|
// Remove files specified to not be displayed.
|
||||||
$fids = array();
|
$fids = array();
|
||||||
foreach ($entities as $id => $entity) {
|
foreach ($entities_items as $items) {
|
||||||
foreach ($items[$id] as $item) {
|
foreach ($items as $item) {
|
||||||
if ($this->isDisplayed($item) && !empty($item->target_id)) {
|
if ($this->isDisplayed($item) && !empty($item->target_id)) {
|
||||||
// Load the files from the files table.
|
// Load the files from the files table.
|
||||||
$fids[] = $item->target_id;
|
$fids[] = $item->target_id;
|
||||||
|
@ -32,8 +32,8 @@ abstract class FileFormatterBase extends FormatterBase {
|
||||||
if ($fids) {
|
if ($fids) {
|
||||||
$files = file_load_multiple($fids);
|
$files = file_load_multiple($fids);
|
||||||
|
|
||||||
foreach ($entities as $id => $entity) {
|
foreach ($entities_items as $items) {
|
||||||
foreach ($items[$id] as $item) {
|
foreach ($items as $item) {
|
||||||
// If the file does not exist, mark the entire item as empty.
|
// If the file does not exist, mark the entire item as empty.
|
||||||
if (!empty($item->target_id)) {
|
if (!empty($item->target_id)) {
|
||||||
$item->entity = isset($files[$item->target_id]) ? $files[$item->target_id] : NULL;
|
$item->entity = isset($files[$item->target_id]) ? $files[$item->target_id] : NULL;
|
||||||
|
|
|
@ -9,7 +9,6 @@ namespace Drupal\file\Plugin\field\formatter;
|
||||||
|
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,7 +27,7 @@ class GenericFileFormatter extends FileFormatterBase {
|
||||||
/**
|
/**
|
||||||
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
|
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -9,7 +9,6 @@ namespace Drupal\file\Plugin\field\formatter;
|
||||||
|
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,8 +27,8 @@ class RSSEnclosureFormatter extends FileFormatterBase {
|
||||||
/**
|
/**
|
||||||
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
|
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
|
$entity = $items->getEntity();
|
||||||
// Add the first file as an enclosure to the RSS item. RSS allows only one
|
// 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
|
// enclosure per item. See: http://en.wikipedia.org/wiki/RSS_enclosure
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
|
|
|
@ -9,7 +9,6 @@ namespace Drupal\file\Plugin\field\formatter;
|
||||||
|
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,7 +27,7 @@ class TableFormatter extends FileFormatterBase {
|
||||||
/**
|
/**
|
||||||
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
|
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
if (!$items->isEmpty()) {
|
if (!$items->isEmpty()) {
|
||||||
|
|
|
@ -9,7 +9,6 @@ namespace Drupal\file\Plugin\field\formatter;
|
||||||
|
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,7 +27,7 @@ class UrlPlainFormatter extends FileFormatterBase {
|
||||||
/**
|
/**
|
||||||
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
|
* Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\file\Plugin\field\widget;
|
||||||
use Drupal\field\Annotation\FieldWidget;
|
use Drupal\field\Annotation\FieldWidget;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\field\Plugin\Type\Widget\WidgetBase;
|
use Drupal\field\Plugin\Type\Widget\WidgetBase;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,9 +61,8 @@ class FileWidget extends WidgetBase {
|
||||||
*
|
*
|
||||||
* Special handling for draggable multiple widgets and 'add more' button.
|
* 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();
|
$field_name = $this->fieldDefinition->getFieldName();
|
||||||
|
|
||||||
$parents = $form['#parents'];
|
$parents = $form['#parents'];
|
||||||
|
|
||||||
// Load the items for form rebuilds from the field state as they might not be
|
// Load the items for form rebuilds from the field state as they might not be
|
||||||
|
@ -101,7 +99,7 @@ class FileWidget extends WidgetBase {
|
||||||
'#title' => $title,
|
'#title' => $title,
|
||||||
'#description' => $description,
|
'#description' => $description,
|
||||||
);
|
);
|
||||||
$element = $this->formSingleElement($entity, $items, $delta, $langcode, $element, $form, $form_state);
|
$element = $this->formSingleElement($items, $delta, $element, $form, $form_state);
|
||||||
|
|
||||||
if ($element) {
|
if ($element) {
|
||||||
// Input field for the delta (drag-n-drop reordering).
|
// Input field for the delta (drag-n-drop reordering).
|
||||||
|
@ -134,7 +132,7 @@ class FileWidget extends WidgetBase {
|
||||||
'#title' => $title,
|
'#title' => $title,
|
||||||
'#description' => $description,
|
'#description' => $description,
|
||||||
);
|
);
|
||||||
$element = $this->formSingleElement($entity, $items, $delta, $langcode, $element, $form, $form_state);
|
$element = $this->formSingleElement($items, $delta, $element, $form, $form_state);
|
||||||
if ($element) {
|
if ($element) {
|
||||||
$element['#required'] = ($element['#required'] && $delta == 0);
|
$element['#required'] = ($element['#required'] && $delta == 0);
|
||||||
$elements[$delta] = $element;
|
$elements[$delta] = $element;
|
||||||
|
@ -174,7 +172,7 @@ class FileWidget extends WidgetBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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();
|
$field_settings = $this->getFieldSettings();
|
||||||
|
|
||||||
// The field settings include defaults for the field type. However, this
|
// The field settings include defaults for the field type. However, this
|
||||||
|
|
|
@ -9,7 +9,6 @@ namespace Drupal\image\Plugin\field\formatter;
|
||||||
|
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,13 +91,13 @@ class ImageFormatter extends ImageFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
$image_link_setting = $this->getSetting('image_link');
|
$image_link_setting = $this->getSetting('image_link');
|
||||||
// Check if the formatter involves a link.
|
// Check if the formatter involves a link.
|
||||||
if ($image_link_setting == 'content') {
|
if ($image_link_setting == 'content') {
|
||||||
$uri = $entity->uri();
|
$uri = $items->getEntity()->uri();
|
||||||
}
|
}
|
||||||
elseif ($image_link_setting == 'file') {
|
elseif ($image_link_setting == 'file') {
|
||||||
$link_file = TRUE;
|
$link_file = TRUE;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
namespace Drupal\image\Plugin\field\formatter;
|
namespace Drupal\image\Plugin\field\formatter;
|
||||||
|
|
||||||
|
use Drupal\field\FieldInstanceInterface;
|
||||||
use Drupal\file\Plugin\field\formatter\FileFormatterBase;
|
use Drupal\file\Plugin\field\formatter\FileFormatterBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,28 +18,22 @@ abstract class ImageFormatterBase extends FileFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function prepareView(array $entities, $langcode, array $items) {
|
public function prepareView(array $entities_items) {
|
||||||
parent::prepareView($entities, $langcode, $items);
|
parent::prepareView($entities_items);
|
||||||
|
|
||||||
// If there are no files specified at all, use the default.
|
// If there are no files specified at all, use the default.
|
||||||
foreach ($entities as $id => $entity) {
|
foreach ($entities_items as $items) {
|
||||||
if ($items[$id]->isEmpty()) {
|
if ($items->isEmpty()) {
|
||||||
$fid = array();
|
// Add the default image if one is found.
|
||||||
$instance = field_info_instance($entity->entityType(), $this->fieldDefinition->getFieldName(), $entity->bundle());
|
$fid = $this->getFieldSetting('default_image');
|
||||||
// Use the default for the instance if one is available.
|
// If we are dealing with a configurable field, look in both
|
||||||
if (!empty($instance['settings']['default_image'])) {
|
// instance-level and field-level settings.
|
||||||
$fid = array($instance['settings']['default_image']);
|
if (empty($fid) && $this->fieldDefinition instanceof FieldInstanceInterface) {
|
||||||
}
|
$fid = $this->fieldDefinition->getField()->getFieldSetting('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']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the default image if one is found.
|
if ($fid && ($file = file_load($fid))) {
|
||||||
if ($fid && ($file = file_load($fid[0]))) {
|
$items->setValue(array(array(
|
||||||
$items[$id]->setValue(array(array(
|
|
||||||
'is_default' => TRUE,
|
'is_default' => TRUE,
|
||||||
'alt' => '',
|
'alt' => '',
|
||||||
'title' => '',
|
'title' => '',
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\image\Plugin\field\widget;
|
||||||
use Drupal\field\Annotation\FieldWidget;
|
use Drupal\field\Annotation\FieldWidget;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\file\Plugin\field\widget\FileWidget;
|
use Drupal\file\Plugin\field\widget\FileWidget;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,8 +77,8 @@ class ImageWidget extends FileWidget {
|
||||||
*
|
*
|
||||||
* Special handling for draggable multiple widgets and 'add more' button.
|
* 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) {
|
||||||
$elements = parent::formMultipleElements($entity, $items, $langcode, $form, $form_state);
|
$elements = parent::formMultipleElements($items, $form, $form_state);
|
||||||
|
|
||||||
$cardinality = $this->fieldDefinition->getFieldCardinality();
|
$cardinality = $this->fieldDefinition->getFieldCardinality();
|
||||||
$file_upload_help = array(
|
$file_upload_help = array(
|
||||||
|
@ -104,8 +103,8 @@ class ImageWidget extends FileWidget {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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 = parent::formElement($items, $delta, $element, $langcode, $form, $form_state);
|
$element = parent::formElement($items, $delta, $element, $form, $form_state);
|
||||||
|
|
||||||
$field_settings = $this->getFieldSettings();
|
$field_settings = $this->getFieldSettings();
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\link\Plugin\field\formatter;
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Component\Utility\Url;
|
use Drupal\Component\Utility\Url;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\Core\Entity\Field\FieldItemInterface;
|
use Drupal\Core\Entity\Field\FieldItemInterface;
|
||||||
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
||||||
|
@ -117,8 +116,9 @@ class LinkFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$element = array();
|
$element = array();
|
||||||
|
$entity = $items->getEntity();
|
||||||
$settings = $this->getSettings();
|
$settings = $this->getSettings();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -14,7 +14,6 @@ namespace Drupal\link\Plugin\field\formatter;
|
||||||
|
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,8 +37,9 @@ class LinkSeparateFormatter extends LinkFormatter {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$element = array();
|
$element = array();
|
||||||
|
$entity = $items->getEntity();
|
||||||
$settings = $this->getSettings();
|
$settings = $this->getSettings();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ class LinkWidget extends WidgetBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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(
|
$element['url'] = array(
|
||||||
'#type' => 'url',
|
'#type' => 'url',
|
||||||
'#title' => t('URL'),
|
'#title' => t('URL'),
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\number\Plugin\field\formatter;
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,7 +64,7 @@ abstract class DefaultNumberFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
$settings = $this->getFieldSettings();
|
$settings = $this->getFieldSettings();
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\number\Plugin\field\formatter;
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,7 +30,7 @@ class NumberUnformattedFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
|
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -64,7 +64,7 @@ class NumberWidget extends WidgetBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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;
|
$value = isset($items[$delta]->value) ? $items[$delta]->value : NULL;
|
||||||
$field_settings = $this->getFieldSettings();
|
$field_settings = $this->getFieldSettings();
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\options\Plugin\field\formatter;
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,9 +31,10 @@ class OptionsDefaultFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
|
$entity = $items->getEntity();
|
||||||
$allowed_values = options_allowed_values($this->fieldDefinition, $entity);
|
$allowed_values = options_allowed_values($this->fieldDefinition, $entity);
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\options\Plugin\field\formatter;
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,7 +31,7 @@ class OptionsKeyFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -31,8 +31,8 @@ class ButtonsWidget extends OptionsWidgetBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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 = parent::formElement($items, $delta, $element, $langcode, $form, $form_state);
|
$element = parent::formElement($items, $delta, $element, $form, $form_state);
|
||||||
|
|
||||||
$options = $this->getOptions($items[$delta]);
|
$options = $this->getOptions($items[$delta]);
|
||||||
$selected = $this->getSelectedOptions($items);
|
$selected = $this->getSelectedOptions($items);
|
||||||
|
|
|
@ -56,8 +56,8 @@ class OnOffWidget extends OptionsWidgetBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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 = parent::formElement($items, $delta, $element, $langcode, $form, $form_state);
|
$element = parent::formElement($items, $delta, $element, $form, $form_state);
|
||||||
|
|
||||||
$options = $this->getOptions($items[$delta]);
|
$options = $this->getOptions($items[$delta]);
|
||||||
$selected = $this->getSelectedOptions($items);
|
$selected = $this->getSelectedOptions($items);
|
||||||
|
|
|
@ -54,7 +54,7 @@ abstract class OptionsWidgetBase extends WidgetBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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
|
// Prepare some properties for the child methods to build the actual form
|
||||||
// element.
|
// element.
|
||||||
$this->required = $element['#required'];
|
$this->required = $element['#required'];
|
||||||
|
@ -163,7 +163,7 @@ abstract class OptionsWidgetBase extends WidgetBase {
|
||||||
/**
|
/**
|
||||||
* Determines selected options from the incoming field values.
|
* Determines selected options from the incoming field values.
|
||||||
*
|
*
|
||||||
* @param FieldInterface $items
|
* @param \Drupal\Core\Entity\Field\FieldInterface $items
|
||||||
* The field values.
|
* The field values.
|
||||||
* @param int $delta
|
* @param int $delta
|
||||||
* (optional) The delta of the item to get options for. Defaults to 0.
|
* (optional) The delta of the item to get options for. Defaults to 0.
|
||||||
|
|
|
@ -30,8 +30,8 @@ class SelectWidget extends OptionsWidgetBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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 = parent::formElement($items, $delta, $element, $langcode, $form, $form_state);
|
$element = parent::formElement($items, $delta, $element, $form, $form_state);
|
||||||
|
|
||||||
$element += array(
|
$element += array(
|
||||||
'#type' => 'select',
|
'#type' => 'select',
|
||||||
|
|
|
@ -9,7 +9,6 @@ namespace Drupal\picture\Plugin\field\formatter;
|
||||||
|
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\image\Plugin\field\formatter\ImageFormatterBase;
|
use Drupal\image\Plugin\field\formatter\ImageFormatterBase;
|
||||||
|
|
||||||
|
@ -115,11 +114,11 @@ class PictureFormatter extends ImageFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
// Check if the formatter involves a link.
|
// Check if the formatter involves a link.
|
||||||
if ($this->getSetting('image_link') == 'content') {
|
if ($this->getSetting('image_link') == 'content') {
|
||||||
$uri = $entity->uri();
|
$uri = $items->getEntity()->uri();
|
||||||
}
|
}
|
||||||
elseif ($this->getSetting('image_link') == 'file') {
|
elseif ($this->getSetting('image_link') == 'file') {
|
||||||
$link_file = TRUE;
|
$link_file = TRUE;
|
||||||
|
|
|
@ -9,7 +9,6 @@ namespace Drupal\taxonomy\Plugin\field\formatter;
|
||||||
|
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase;
|
use Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase;
|
||||||
|
|
||||||
|
@ -32,8 +31,9 @@ class EntityReferenceTaxonomyTermRssFormatter extends EntityReferenceFormatterBa
|
||||||
/**
|
/**
|
||||||
* Overrides Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase::viewElements().
|
* Overrides Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase::viewElements().
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
$entity = $items->getEntity();
|
||||||
|
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
$entity->rss_elements[] = array(
|
$entity->rss_elements[] = array(
|
||||||
|
|
|
@ -9,9 +9,7 @@ namespace Drupal\taxonomy\Plugin\field\formatter;
|
||||||
|
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
|
||||||
use Drupal\taxonomy\Plugin\field\formatter\TaxonomyFormatterBase;
|
use Drupal\taxonomy\Plugin\field\formatter\TaxonomyFormatterBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +28,7 @@ class LinkFormatter extends TaxonomyFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
// Terms without target_id do not exist yet, theme such terms as just their
|
// Terms without target_id do not exist yet, theme such terms as just their
|
||||||
|
|
|
@ -9,7 +9,6 @@ namespace Drupal\taxonomy\Plugin\field\formatter;
|
||||||
|
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\taxonomy\Plugin\field\formatter\TaxonomyFormatterBase;
|
use Drupal\taxonomy\Plugin\field\formatter\TaxonomyFormatterBase;
|
||||||
|
|
||||||
|
@ -29,7 +28,7 @@ class PlainFormatter extends TaxonomyFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -9,7 +9,6 @@ namespace Drupal\taxonomy\Plugin\field\formatter;
|
||||||
|
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\taxonomy\Plugin\field\formatter\TaxonomyFormatterBase;
|
use Drupal\taxonomy\Plugin\field\formatter\TaxonomyFormatterBase;
|
||||||
|
|
||||||
|
@ -29,7 +28,9 @@ class RSSCategoryFormatter extends TaxonomyFormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
|
$entity = $items->getEntity();
|
||||||
|
|
||||||
// Terms whose target_id is 'autocreate' do not exist yet and
|
// Terms whose target_id is 'autocreate' do not exist yet and
|
||||||
// $item->entity is not set. Theme such terms as just their name.
|
// $item->entity is not set. Theme such terms as just their name.
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
|
|
|
@ -9,7 +9,6 @@ namespace Drupal\taxonomy\Plugin\field\formatter;
|
||||||
|
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
||||||
|
|
||||||
|
@ -24,12 +23,12 @@ abstract class TaxonomyFormatterBase extends FormatterBase {
|
||||||
* This preloads all taxonomy terms for multiple loaded objects at once and
|
* This preloads all taxonomy terms for multiple loaded objects at once and
|
||||||
* unsets values for invalid terms that do not exist.
|
* 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();
|
$tids = array();
|
||||||
|
|
||||||
// Collect every possible term attached to any of the fieldable entities.
|
// Collect every possible term attached to any of the fieldable entities.
|
||||||
foreach ($entities as $id => $entity) {
|
foreach ($entities_items as $items) {
|
||||||
foreach ($items[$id] as $delta => $item) {
|
foreach ($items as $item) {
|
||||||
// Force the array key to prevent duplicates.
|
// Force the array key to prevent duplicates.
|
||||||
if ($item->target_id !== 0) {
|
if ($item->target_id !== 0) {
|
||||||
$tids[$item->target_id] = $item->target_id;
|
$tids[$item->target_id] = $item->target_id;
|
||||||
|
@ -41,15 +40,15 @@ abstract class TaxonomyFormatterBase extends FormatterBase {
|
||||||
|
|
||||||
// Iterate through the fieldable entities again to attach the loaded term
|
// Iterate through the fieldable entities again to attach the loaded term
|
||||||
// data.
|
// data.
|
||||||
foreach ($entities as $id => $entity) {
|
foreach ($entities_items as $items) {
|
||||||
$rekey = FALSE;
|
$rekey = FALSE;
|
||||||
|
|
||||||
foreach ($items[$id] as $delta => $item) {
|
foreach ($items as $item) {
|
||||||
// Check whether the taxonomy term field instance value could be
|
// Check whether the taxonomy term field instance value could be
|
||||||
// loaded.
|
// loaded.
|
||||||
if (isset($terms[$item->target_id])) {
|
if (isset($terms[$item->target_id])) {
|
||||||
// Replace the instance value with the term data.
|
// 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.
|
// Terms to be created are not in $terms, but are still legitimate.
|
||||||
elseif ($item->target_id === 0 && isset($item->entity)) {
|
elseif ($item->target_id === 0 && isset($item->entity)) {
|
||||||
|
@ -57,14 +56,15 @@ abstract class TaxonomyFormatterBase extends FormatterBase {
|
||||||
}
|
}
|
||||||
// Otherwise, unset the instance value, since the term does not exist.
|
// Otherwise, unset the instance value, since the term does not exist.
|
||||||
else {
|
else {
|
||||||
unset($items[$id][$delta]);
|
$item->setValue(NULL);
|
||||||
$rekey = TRUE;
|
$rekey = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rekey the items array if needed.
|
||||||
if ($rekey) {
|
if ($rekey) {
|
||||||
// Rekey the items array.
|
$items->filterEmptyValues();
|
||||||
$items[$id]->setValue(array_values($items[$id]->getValue()));
|
debug($items->getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ class TaxonomyAutocompleteWidget extends WidgetBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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();
|
$tags = array();
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
$tags[$item->target_id] = isset($item->taxonomy_term) ? $item->taxonomy_term : entity_load('taxonomy_term', $item->target_id);
|
$tags[$item->target_id] = isset($item->taxonomy_term) ? $item->taxonomy_term : entity_load('taxonomy_term', $item->target_id);
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\telephone\Plugin\field\formatter;
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,38 +61,19 @@ class TelephoneLinkFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function prepareView(array $entities, $langcode, array $items) {
|
public function viewElements(FieldInterface $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) {
|
|
||||||
$element = array();
|
$element = array();
|
||||||
|
$title_setting = $this->getSetting('title');
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
// Prepend 'tel:' to the telephone number.
|
|
||||||
$href = 'tel:' . rawurlencode(preg_replace('/\s+/', '', $item->value));
|
|
||||||
|
|
||||||
// Render each element as link.
|
// Render each element as link.
|
||||||
$element[$delta] = array(
|
$element[$delta] = array(
|
||||||
'#type' => 'link',
|
'#type' => 'link',
|
||||||
'#title' => $item->title,
|
// Use custom title if available, otherwise use the telephone number
|
||||||
'#href' => $href,
|
// 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),
|
'#options' => array('external' => TRUE),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ class TelephoneDefaultWidget extends WidgetBase {
|
||||||
/**
|
/**
|
||||||
* Implements \Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement().
|
* 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(
|
$element['value'] = $element + array(
|
||||||
'#type' => 'tel',
|
'#type' => 'tel',
|
||||||
'#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL,
|
'#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL,
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\text\Plugin\field\formatter;
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +33,7 @@ class TextDefaultFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\text\Plugin\field\formatter;
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +33,7 @@ class TextPlainFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
|
* Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
foreach ($items as $delta => $item) {
|
foreach ($items as $delta => $item) {
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\text\Plugin\field\formatter;
|
||||||
use Drupal\field\Annotation\FieldFormatter;
|
use Drupal\field\Annotation\FieldFormatter;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
|
||||||
use Drupal\Core\Entity\Field\FieldInterface;
|
use Drupal\Core\Entity\Field\FieldInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,7 +64,7 @@ class TextTrimmedFormatter extends FormatterBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function viewElements(EntityInterface $entity, $langcode, FieldInterface $items) {
|
public function viewElements(FieldInterface $items) {
|
||||||
$elements = array();
|
$elements = array();
|
||||||
|
|
||||||
$text_processing = $this->getFieldSetting('text_processing');
|
$text_processing = $this->getFieldSetting('text_processing');
|
||||||
|
|
|
@ -68,7 +68,7 @@ class TextareaWidget extends WidgetBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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(
|
$main_widget = $element + array(
|
||||||
'#type' => 'textarea',
|
'#type' => 'textarea',
|
||||||
'#default_value' => $items[$delta]->value,
|
'#default_value' => $items[$delta]->value,
|
||||||
|
|
|
@ -59,8 +59,8 @@ class TextareaWithSummaryWidget extends TextareaWidget {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
function formElement(FieldInterface $items, $delta, array $element, $langcode, array &$form, array &$form_state) {
|
function formElement(FieldInterface $items, $delta, array $element, array &$form, array &$form_state) {
|
||||||
$element = parent::formElement($items, $delta, $element, $langcode, $form, $form_state);
|
$element = parent::formElement($items, $delta, $element, $form, $form_state);
|
||||||
|
|
||||||
$display_summary = $items[$delta]->summary || $this->getFieldSetting('display_summary');
|
$display_summary = $items[$delta]->summary || $this->getFieldSetting('display_summary');
|
||||||
$element['summary'] = array(
|
$element['summary'] = array(
|
||||||
|
|
|
@ -68,7 +68,7 @@ class TextfieldWidget extends WidgetBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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(
|
$main_widget = $element + array(
|
||||||
'#type' => 'textfield',
|
'#type' => 'textfield',
|
||||||
'#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL,
|
'#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL,
|
||||||
|
|
Loading…
Reference in New Issue