.../field/formatter/DatetimeDefaultFormatter.php | 8 ++-- .../field/formatter/DatetimePlainFormatter.php | 4 +- .../edit/Access/EditEntityFieldAccessCheck.php | 5 ++- .../formatter/EntityReferenceEntityFormatter.php | 12 +++--- core/modules/field/field.api.php | 7 ++-- core/modules/field/field.module | 11 +++--- .../field/Plugin/Type/Formatter/FormatterBase.php | 40 ++++++-------------- .../Plugin/Type/Formatter/FormatterFactory.php | 4 +- .../field/Plugin/views/argument/FieldList.php | 3 +- .../field/Plugin/views/argument/ListString.php | 3 +- .../tests/modules/field_test/field_test.field.inc | 2 +- .../field/formatter/OptionsDefaultFormatter.php | 2 +- core/modules/options/options.module | 20 +++++----- core/modules/options/tests/options_test.module | 4 +- .../field/formatter/TextDefaultFormatter.php | 2 +- .../field/formatter/TextTrimmedFormatter.php | 14 +++---- 16 files changed, 64 insertions(+), 77 deletions(-) diff --git a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimeDefaultFormatter.php b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimeDefaultFormatter.php index e038471..c50d5ae 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimeDefaultFormatter.php +++ b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimeDefaultFormatter.php @@ -32,7 +32,7 @@ class DateTimeDefaultFormatter extends FormatterBase { /** - * Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements(). + * {@inheritdoc} */ public function viewElements(EntityInterface $entity, $langcode, array $items) { @@ -53,7 +53,7 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) { // The formatted output will be in local time. $date->setTimeZone(timezone_open(drupal_get_user_timezone())); - if ($this->field['settings']['datetime_type'] == 'date') { + if ($this->field_definition['settings']['datetime_type'] == 'date') { // A date without time will pick up the current time, use the default. datetime_date_default_time($date); } @@ -93,7 +93,7 @@ function dateFormat($date) { } /** - * Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm(). + * {@inheritdoc} */ public function settingsForm(array $form, array &$form_state) { @@ -119,7 +119,7 @@ public function settingsForm(array $form, array &$form_state) { } /** - * Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsSummary(). + * {@inheritdoc} */ public function settingsSummary() { diff --git a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimePlainFormatter.php b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimePlainFormatter.php index 45a85a2..55525fd 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimePlainFormatter.php +++ b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/formatter/DatetimePlainFormatter.php @@ -28,7 +28,7 @@ class DateTimePlainFormatter extends FormatterBase { /** - * Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements(). + * {@inheritdoc} */ public function viewElements(EntityInterface $entity, $langcode, array $items) { @@ -43,7 +43,7 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) { $date = $item['date']; $date->setTimeZone(timezone_open(drupal_get_user_timezone())); $format = DATETIME_DATETIME_STORAGE_FORMAT; - if ($this->field['settings']['datetime_type'] == 'date') { + if ($this->field_definition['settings']['datetime_type'] == 'date') { // A date without time will pick up the current time, use the default. datetime_date_default_time($date); $format = DATETIME_DATE_STORAGE_FORMAT; diff --git a/core/modules/edit/lib/Drupal/edit/Access/EditEntityFieldAccessCheck.php b/core/modules/edit/lib/Drupal/edit/Access/EditEntityFieldAccessCheck.php index 9eac5bc..6f933c8 100644 --- a/core/modules/edit/lib/Drupal/edit/Access/EditEntityFieldAccessCheck.php +++ b/core/modules/edit/lib/Drupal/edit/Access/EditEntityFieldAccessCheck.php @@ -42,9 +42,12 @@ public function access(Route $route, Request $request) { */ public function accessEditEntityField(EntityInterface $entity, $field_name) { $entity_type = $entity->entityType(); + $instance = field_info_instance($entity->entityType(), $field_name, $entity->bundle()); + $field = field_info_field($field_name); + $field_definition = $field->getFieldDefinition($instance); // @todo Generalize to all entity types once http://drupal.org/node/1862750 // is done. - return ($entity_type == 'node' && node_access('update', $entity) && field_access('edit', $field_name, $entity_type, $entity)); + return ($entity_type == 'node' && node_access('update', $entity) && field_access('edit', $field_definition, $entity_type, $entity)); } /** diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceEntityFormatter.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceEntityFormatter.php index d829cb2..b2f0f50 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceEntityFormatter.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceEntityFormatter.php @@ -33,10 +33,10 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase { /** - * Overrides \Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase::settingsForm(). + * {@inheritdoc} */ public function settingsForm(array $form, array &$form_state) { - $view_modes = entity_get_view_modes($this->field['settings']['target_type']); + $view_modes = entity_get_view_modes($this->field_definition['settings']['target_type']); $options = array(); foreach ($view_modes as $view_mode => $view_mode_settings) { $options[$view_mode] = $view_mode_settings['label']; @@ -60,12 +60,12 @@ public function settingsForm(array $form, array &$form_state) { } /** - * Overrides \Drupal\field\Plugin\Type\Formatter\FormatterBase::settingsSummary(). + * {@inheritdoc} */ public function settingsSummary() { $summary = array(); - $view_modes = entity_get_view_modes($this->field['settings']['target_type']); + $view_modes = entity_get_view_modes($this->field_definition['settings']['target_type']); $view_mode = $this->getSetting('view_mode'); $summary[] = t('Rendered as @mode', array('@mode' => isset($view_modes[$view_mode]['label']) ? $view_modes[$view_mode]['label'] : $view_mode)); $summary[] = $this->getSetting('links') ? t('Display links') : t('Do not display links'); @@ -74,7 +74,7 @@ public function settingsSummary() { } /** - * Overrides \Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase::viewElements(). + * {@inheritdoc} */ public function viewElements(EntityInterface $entity, $langcode, array $items) { // Remove un-accessible items. @@ -83,7 +83,7 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) { $view_mode = $this->getSetting('view_mode'); $links = $this->getSetting('links'); - $target_type = $this->field['settings']['target_type']; + $target_type = $this->field_definition['settings']['target_type']; $elements = array(); diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index 5ba15c9..5d04cc1 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -2138,8 +2138,9 @@ function hook_field_storage_purge(\Drupal\Core\Entity\EntityInterface $entity, $ * * @param $op * The operation to be performed. Possible values: 'edit', 'view'. - * @param $field - * The field on which the operation is to be performed. + * @param array $field_definition + * The field definition array for the instance of the field on which the + * operation is to be performed. * @param $entity_type * The type of $entity; for example, 'node' or 'user'. * @param $entity @@ -2150,7 +2151,7 @@ function hook_field_storage_purge(\Drupal\Core\Entity\EntityInterface $entity, $ * @return * TRUE if the operation is allowed, and FALSE if the operation is denied. */ -function hook_field_access($op, $field, $entity_type, $entity, $account) { +function hook_field_access($op, array $field_definition, $entity_type, $entity, $account) { if ($field['field_name'] == 'field_of_interest' && $op == 'edit') { return user_access('edit field of interest', $account); } diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 8f459a3..0ddb0e2 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -941,9 +941,10 @@ function field_has_data($field) { * The operation to be performed. Possible values: * - edit * - view - * @param array $field - * The full field structure array for the field on which the operation is to - * be performed. See field_info_field(). + * @param array $field_definition + * The field definition array for the instance of the field on which the + * operation is to be performed. + * See \Drupal\field\Plugin\Core\Entity\Field::getFieldDefinition(). * @param $entity_type * The type of $entity; for example, 'node' or 'user'. * @param $entity @@ -954,7 +955,7 @@ function field_has_data($field) { * @return * TRUE if the operation is allowed; FALSE if the operation is denied. */ -function field_access($op, $field, $entity_type, $entity = NULL, $account = NULL) { +function field_access($op, array $field_definition, $entity_type, $entity = NULL, $account = NULL) { global $user; if (!isset($account)) { @@ -963,7 +964,7 @@ function field_access($op, $field, $entity_type, $entity = NULL, $account = NULL foreach (module_implements('field_access') as $module) { $function = $module . '_field_access'; - $access = $function($op, $field, $entity_type, $entity, $account); + $access = $function($op, $field_definition, $entity_type, $entity, $account); if ($access === FALSE) { return FALSE; } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php index 02b0a19..d6e12cb 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterBase.php @@ -2,14 +2,13 @@ /** * @file - * Definition of Drupal\field\Plugin\Type\Formatter\FormatterBase. + * Contains \Drupal\field\Plugin\Type\Formatter\FormatterBase. */ namespace Drupal\field\Plugin\Type\Formatter; use Drupal\Core\Entity\EntityInterface; use Drupal\field\Plugin\PluginSettingsBase; -use Drupal\field\Plugin\Core\Entity\FieldInstance; /** * Base class for 'Field formatter' plugin implementations. @@ -17,20 +16,6 @@ abstract class FormatterBase extends PluginSettingsBase implements FormatterInterface { /** - * The field definition. - * - * @var array - */ - protected $field; - - /** - * The field instance definition. - * - * @var \Drupal\field\Plugin\Core\Entity\FieldInstance - */ - protected $instance; - - /** * The formatter settings. * * @var array @@ -77,12 +62,9 @@ public function __construct($plugin_id, array $plugin_definition, $field_definit } /** - * Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::view(). + * {@inheritdoc} */ public function view(EntityInterface $entity, $langcode, array $items) { - $field = $this->field; - $instance = $this->instance; - $addition = array(); $elements = $this->viewElements($entity, $langcode, $items); @@ -90,14 +72,14 @@ public function view(EntityInterface $entity, $langcode, array $items) { $entity_type = $entity->entityType(); $info = array( '#theme' => 'field', - '#title' => $instance['label'], - '#access' => field_access('view', $field, $entity->entityType(), $entity), + '#title' => $this->field_definition['label'], + '#access' => field_access('view', $this->field_definition, $entity->entityType(), $entity), '#label_display' => $this->label, '#view_mode' => $this->viewMode, '#language' => $langcode, - '#field_name' => $field['field_name'], - '#field_type' => $field['type'], - '#field_translatable' => $field['translatable'], + '#field_name' => $this->field_definition['field_name'], + '#field_type' => $this->field_definition['type'], + '#field_translatable' => $this->field_definition['translatable'], '#entity_type' => $entity_type, '#bundle' => $entity->bundle(), '#object' => $entity, @@ -105,28 +87,28 @@ public function view(EntityInterface $entity, $langcode, array $items) { '#formatter' => $this->getPluginId(), ); - $addition[$field['field_name']] = array_merge($info, $elements); + $addition[$this->field_definition['field_name']] = array_merge($info, $elements); } return $addition; } /** - * Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm(). + * {@inheritdoc} */ public function settingsForm(array $form, array &$form_state) { return array(); } /** - * Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsSummary(). + * {@inheritdoc} */ public function settingsSummary() { return ''; } /** - * Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::prepareView(). + * {@inheritdoc} */ public function prepareView(array $entities, $langcode, array &$items) { } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterFactory.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterFactory.php index c503e3c..9f7c03c 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterFactory.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterFactory.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\field\Plugin\Type\Formatter\FormatterFactory. + * Contains \Drupal\field\Plugin\Type\Formatter\FormatterFactory. */ namespace Drupal\field\Plugin\Type\Formatter; @@ -15,7 +15,7 @@ class FormatterFactory extends DefaultFactory { /** - * Overrides Drupal\Component\Plugin\Factory\DefaultFactory::createInstance(). + * {@inheritdoc} */ public function createInstance($plugin_id, array $configuration) { $plugin_definition = $this->discovery->getDefinition($plugin_id); diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/argument/FieldList.php b/core/modules/field/lib/Drupal/field/Plugin/views/argument/FieldList.php index 2176c91..a82da70 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/argument/FieldList.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/argument/FieldList.php @@ -36,7 +36,8 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o parent::init($view, $display, $options); $field = field_info_field($this->definition['field_name']); - $this->allowed_values = options_allowed_values($field); + $field_definition = $field->getFieldDefinition(); + $this->allowed_values = options_allowed_values($field_definition); } protected function defineOptions() { diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/argument/ListString.php b/core/modules/field/lib/Drupal/field/Plugin/views/argument/ListString.php index ada688f..20038cd 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/argument/ListString.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/argument/ListString.php @@ -36,7 +36,8 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o parent::init($view, $display, $options); $field = field_info_field($this->definition['field_name']); - $this->allowed_values = options_allowed_values($field); + $field_definition = $field->getFieldDefinition(); + $this->allowed_values = options_allowed_values($field_definition); } protected function defineOptions() { diff --git a/core/modules/field/tests/modules/field_test/field_test.field.inc b/core/modules/field/tests/modules/field_test/field_test.field.inc index d2f4a94..043fb4b 100644 --- a/core/modules/field/tests/modules/field_test/field_test.field.inc +++ b/core/modules/field/tests/modules/field_test/field_test.field.inc @@ -197,7 +197,7 @@ function field_test_default_value(EntityInterface $entity, $field, $instance) { /** * Implements hook_field_access(). */ -function field_test_field_access($op, $field, $entity_type, $entity, $account) { +function field_test_field_access($op, array $field_definition, $entity_type, $entity, $account) { if ($field['field_name'] == "field_no_{$op}_access") { return FALSE; } diff --git a/core/modules/options/lib/Drupal/options/Plugin/field/formatter/OptionsDefaultFormatter.php b/core/modules/options/lib/Drupal/options/Plugin/field/formatter/OptionsDefaultFormatter.php index 48268aa..2e5108c 100644 --- a/core/modules/options/lib/Drupal/options/Plugin/field/formatter/OptionsDefaultFormatter.php +++ b/core/modules/options/lib/Drupal/options/Plugin/field/formatter/OptionsDefaultFormatter.php @@ -35,7 +35,7 @@ class OptionsDefaultFormatter extends FormatterBase { public function viewElements(EntityInterface $entity, $langcode, array $items) { $elements = array(); - $allowed_values = options_allowed_values($this->field, $this->instance, $entity); + $allowed_values = options_allowed_values($this->field_definition, $entity); foreach ($items as $delta => $item) { if (isset($allowed_values[$item['value']])) { diff --git a/core/modules/options/options.module b/core/modules/options/options.module index 1062f7f..61c36d5 100644 --- a/core/modules/options/options.module +++ b/core/modules/options/options.module @@ -239,10 +239,8 @@ function options_field_update_field($field, $prior_field, $has_data) { * The strings are not safe for output. Keys and values of the array should be * sanitized through field_filter_xss() before being displayed. * - * @param $field - * The field definition. - * @param $instance - * (optional) A field instance array. Defaults to NULL. + * @param array $field_definition + * A field definition array. * @param \Drupal\Core\Entity\EntityInterface $entity * (optional) The entity object. Defaults to NULL. * @@ -250,31 +248,31 @@ function options_field_update_field($field, $prior_field, $has_data) { * The array of allowed values. Keys of the array are the raw stored values * (number or text), values of the array are the display labels. */ -function options_allowed_values($field, $instance = NULL, EntityInterface $entity = NULL) { +function options_allowed_values(array $field_definition, EntityInterface $entity = NULL) { $allowed_values = &drupal_static(__FUNCTION__, array()); - if (!isset($allowed_values[$field['uuid']])) { - $function = $field['settings']['allowed_values_function']; + if (!isset($allowed_values[$field_definition['uuid']])) { + $function = $field_definition['settings']['allowed_values_function']; // If $cacheable is FALSE, then the allowed values are not statically // cached. See options_test_dynamic_values_callback() for an example of // generating dynamic and uncached values. $cacheable = TRUE; if (!empty($function)) { - $values = $function($field, $instance, $entity, $cacheable); + $values = $function($field_definition, $entity, $cacheable); } else { - $values = $field['settings']['allowed_values']; + $values = $field_definition['settings']['allowed_values']; } if ($cacheable) { - $allowed_values[$field['uuid']] = $values; + $allowed_values[$field_definition['uuid']] = $values; } else { return $values; } } - return $allowed_values[$field['uuid']]; + return $allowed_values[$field_definition['uuid']]; } /** diff --git a/core/modules/options/tests/options_test.module b/core/modules/options/tests/options_test.module index 90f6bf1..715d3cd 100644 --- a/core/modules/options/tests/options_test.module +++ b/core/modules/options/tests/options_test.module @@ -10,7 +10,7 @@ /** * Allowed values callback. */ -function options_test_allowed_values_callback($field, $instance, $entity) { +function options_test_allowed_values_callback(array $field_definition, EntityInterface $entity) { $values = array( 'Group 1' => array( 0 => 'Zero', @@ -27,7 +27,7 @@ function options_test_allowed_values_callback($field, $instance, $entity) { /** * An entity-bound allowed values callback. */ -function options_test_dynamic_values_callback($field, $instance, EntityInterface $entity, &$cacheable) { +function options_test_dynamic_values_callback(array $field_definition, EntityInterface $entity, &$cacheable) { $cacheable = FALSE; // We need the values of the entity as keys. return drupal_map_assoc(array( diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextDefaultFormatter.php b/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextDefaultFormatter.php index 4a96cc3..8db0662 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextDefaultFormatter.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextDefaultFormatter.php @@ -38,7 +38,7 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) { $elements = array(); foreach ($items as $delta => $item) { - $output = text_sanitize($this->instance['settings']['text_processing'], $langcode, $item, 'value'); + $output = text_sanitize($this->field_definition['settings']['text_processing'], $langcode, $item, 'value'); $elements[$delta] = array('#markup' => $output); } diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextTrimmedFormatter.php b/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextTrimmedFormatter.php index ba8b417..3cf23cf 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextTrimmedFormatter.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/formatter/TextTrimmedFormatter.php @@ -3,7 +3,7 @@ /** * @file * - * Definition of Drupal\text\Plugin\field\formatter\TextTrimmedFormatter. + * Contains \Drupal\text\Plugin\field\formatter\TextTrimmedFormatter. */ namespace Drupal\text\Plugin\field\formatter; @@ -40,7 +40,7 @@ class TextTrimmedFormatter extends FormatterBase { /** - * Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsForm(). + * {@inheritdoc} */ public function settingsForm(array $form, array &$form_state) { $element['trim_length'] = array( @@ -54,7 +54,7 @@ public function settingsForm(array $form, array &$form_state) { } /** - * Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::settingsSummary(). + * {@inheritdoc} */ public function settingsSummary() { return t('Trim length: @trim_length', array( @@ -63,18 +63,18 @@ public function settingsSummary() { } /** - * Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements(). + * {@inheritdoc} */ public function viewElements(EntityInterface $entity, $langcode, array $items) { $elements = array(); foreach ($items as $delta => $item) { if ($this->getPluginId() == 'text_summary_or_trimmed' && !empty($item['summary'])) { - $output = text_sanitize($this->instance['settings']['text_processing'], $langcode, $item, 'summary'); + $output = text_sanitize($this->field_definition['settings']['text_processing'], $langcode, $item, 'summary'); } else { - $output = text_sanitize($this->instance['settings']['text_processing'], $langcode, $item, 'value'); - $output = text_summary($output, $this->instance['settings']['text_processing'] ? $item['format'] : NULL, $this->getSetting('trim_length')); + $output = text_sanitize($this->field_definition['settings']['text_processing'], $langcode, $item, 'value'); + $output = text_summary($output, $this->field_definition['settings']['text_processing'] ? $item['format'] : NULL, $this->getSetting('trim_length')); } $elements[$delta] = array('#markup' => $output); }