diff --git a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php index fe6886a..47cd14b 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php @@ -11,6 +11,7 @@ use Drupal\Core\Annotation\Translation; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\field\FieldException; +use Drupal\Component\Utility\NestedArray; /** * Defines the Field entity. @@ -542,6 +543,32 @@ public function getBundles() { } /** + * Returns a field definition array. + * + * @return array + * An array with the following keys: + * - cache_id + * - field_name + * - type + * - label + * - translatable + * - settings + * + * @todo Figure out which additional keys are needed. + */ + public function getFieldDefinition(FieldInstance $instance = NULL) { + $field_definition = array( + 'cache_id' => $instance ? $instance->uuid() : $this->uuid(), + 'field_name' => $this->id, + 'type' => $this->type, + 'label' => $instance ? $instance->label() : $this->label(), + 'translatable' => $this->translatable, + 'settings' => $instance ? NestedArray::mergeDeep($this->settings, $instance->settings) : $this->settings, + ); + return $field_definition; + } + + /** * {@inheritdoc} */ public function offsetExists($offset) { 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 a46b465..02b0a19 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 @@ -58,8 +58,8 @@ * The plugin_id for the formatter. * @param array $plugin_definition * The plugin implementation definition. - * @param \Drupal\field\Plugin\Core\Entity\FieldInstance $instance - * The field instance to which the formatter is associated. + * @param array $field_definition + * The definition of the field to which the formatter is associated. * @param array $settings * The formatter settings. * @param string $label @@ -67,11 +67,10 @@ * @param string $view_mode * The view mode. */ - public function __construct($plugin_id, array $plugin_definition, $instance, array $settings, $label, $view_mode) { + public function __construct($plugin_id, array $plugin_definition, $field_definition, array $settings, $label, $view_mode) { parent::__construct(array(), $plugin_id, $plugin_definition); - $this->instance = $instance; - $this->field = field_info_field($instance['field_name']); + $this->field_definition = $field_definition; $this->settings = $settings; $this->label = $label; $this->viewMode = $view_mode; 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 0df5b97..c503e3c 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 @@ -20,6 +20,9 @@ class FormatterFactory extends DefaultFactory { public function createInstance($plugin_id, array $configuration) { $plugin_definition = $this->discovery->getDefinition($plugin_id); $plugin_class = static::getPluginClass($plugin_id, $plugin_definition); - return new $plugin_class($plugin_id, $plugin_definition, $configuration['instance'], $configuration['settings'], $configuration['label'], $configuration['view_mode']); + $instance = $configuration['instance']; + $field = field_info_field($instance['field_name']); + $field_definition = $field->getFieldDefinition($instance); + return new $plugin_class($plugin_id, $plugin_definition, $field_definition, $configuration['settings'], $configuration['label'], $configuration['view_mode']); } }