diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/field_type/ConfigurableEntityReferenceItem.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/field_type/ConfigurableEntityReferenceItem.php index 786f0da..1b09365 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/field_type/ConfigurableEntityReferenceItem.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/field_type/ConfigurableEntityReferenceItem.php @@ -128,7 +128,7 @@ public function settingsForm(array $form, array &$form_state, $has_data) { * {@inheritdoc} */ public function instanceSettingsForm(array $form, array &$form_state) { - $field_definition = isset($form_state['instance']) ? $form_state['instance'] : $this->getInstance(); + $field_definition = $form_state['instance']; // Get all selection plugins for this entity type. $selection_plugins = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionGroups($this->getFieldSetting('target_type')); diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php index 77477d9..1399204 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php @@ -32,25 +32,13 @@ class ConfigEntityReferenceItemBase extends EntityReferenceItem implements Confi static $propertyDefinitions; /** - * The Field instance definition. - * - * @var \Drupal\field\Entity\FieldInstance - */ - protected $instance; - - /** * Returns the field instance definition. * - * Copied from \Drupal\field\Plugin\Type\FieldType\ConfigFieldItemBase, - * since we cannot extend it. - * - * @var \Drupal\field\Entity\FieldInstance + * @return \Drupal\field\Entity\FieldInstance + * The field instance definition. */ - public function getInstance() { - if (!isset($this->instance) && $parent = $this->getParent()) { - $this->instance = $parent->getInstance(); - } - return $this->instance; + protected function getInstance() { + return $this->getFieldDefinition(); } /** @@ -129,7 +117,7 @@ public function settingsForm(array $form, array &$form_state, $has_data) { if ($callback = $this->getLegacyCallback('settings_form')) { // hook_field_settings_form() used to receive the $instance (not actually // needed), and the value of field_has_data(). - return $callback($this->getInstance()->getField(), $this->getInstance(), $has_data); + return $callback($this->getFieldDefinition()->getField(), $this->getInstance(), $has_data); } return array(); } @@ -142,7 +130,7 @@ public function settingsForm(array $form, array &$form_state, $has_data) { */ public function instanceSettingsForm(array $form, array &$form_state) { if ($callback = $this->getLegacyCallback('instance_settings_form')) { - return $callback($this->getInstance()->getField(), $this->getInstance(), $form_state); + return $callback($this->getFieldDefinition()->getField(), $this->getInstance(), $form_state); } return array(); } @@ -161,7 +149,7 @@ public function getSettableOptions() { // We are at the field item level, so we need to go two levels up to get // to the entity object. $entity = $this->getParent()->getParent(); - return $callback($this->getInstance(), $entity); + return $callback($this->getFieldDefinition(), $entity); } } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php index 53fa2f5..6ee9553 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php @@ -36,7 +36,7 @@ public function __construct(array $definition, $name = NULL, TypedDataInterface /** * {@inheritdoc} */ - public function getInstance() { + public function getFieldDefinition() { if (!isset($this->instance) && $parent = $this->getParent()) { $instances = FieldAPI::fieldInfo()->getBundleInstances($parent->entityType(), $parent->bundle()); $this->instance = $instances[$this->getName()]; @@ -47,13 +47,6 @@ public function getInstance() { /** * {@inheritdoc} */ - public function getFieldDefinition() { - return $this->getInstance(); - } - - /** - * {@inheritdoc} - */ public function getConstraints() { $constraints = array(); // Check that the number of values doesn't exceed the field cardinality. For @@ -76,7 +69,7 @@ public function getConstraints() { * {@inheritdoc} */ protected function getDefaultValue() { - return $this->getInstance()->getFieldDefaultValue($this->getParent()); + return $this->getFieldDefinition()->getFieldDefaultValue($this->getParent()); } /** diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldInterface.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldInterface.php index 27c8b1f..2df30a9 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldInterface.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldInterface.php @@ -15,13 +15,6 @@ interface ConfigFieldInterface extends FieldInterface { /** - * Returns the field instance definition. - * - * @var \Drupal\field\Entity\FieldInstance - */ - public function getInstance(); - - /** * Returns a form for the default value input. * * Invoked from \Drupal\field_ui\Form\FieldInstanceEditForm to allow diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php index 4313b43..eb16d87 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php @@ -15,23 +15,6 @@ abstract class ConfigFieldItemBase extends FieldItemBase implements ConfigFieldItemInterface { /** - * The Field instance definition. - * - * @var \Drupal\field\Entity\FieldInstance - */ - public $instance; - - /** - * {@inheritdoc} - */ - public function getInstance() { - if (!isset($this->instance) && $parent = $this->getParent()) { - $this->instance = $parent->getInstance(); - } - return $this->instance; - } - - /** * {@inheritdoc} */ public function settingsForm(array $form, array &$form_state, $has_data) { diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemInterface.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemInterface.php index a584640..88de2ac 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemInterface.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemInterface.php @@ -16,13 +16,6 @@ interface ConfigFieldItemInterface extends FieldItemInterface { /** - * Returns the field instance definition. - * - * @var \Drupal\field\FieldInstanceInterface - */ - public function getInstance(); - - /** * Returns the schema for the field. * * This method is static, because the field schema information is needed on diff --git a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php index 31e65ca..9971fa1 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php +++ b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php @@ -27,6 +27,16 @@ class LegacyConfigField extends ConfigField { /** + * Returns the field instance definition. + * + * @return \Drupal\field\Entity\FieldInstance + * The field instance definition. + */ + protected function getInstance() { + return $this->getFieldDefinition(); + } + + /** * {@inheritdoc} */ public function validate() { @@ -41,14 +51,16 @@ public function validate() { $entity = $this->getParent(); $langcode = $entity->language()->id; + $field_name = $this->getFieldDefinition()->getFieldName(); - if (isset($legacy_errors[$this->getInstance()->getField()->id()][$langcode])) { - foreach ($legacy_errors[$this->getInstance()->getField()->id()][$langcode] as $delta => $item_errors) { + if (isset($legacy_errors[$field_name][$langcode])) { + foreach ($legacy_errors[$field_name][$langcode] as $delta => $item_errors) { foreach ($item_errors as $item_error) { // We do not have the information about which column triggered the // error, so assume the first column... - $column = key($this->getInstance()->getField()->getColumns()); - $violations->add(new ConstraintViolation($item_error['message'], $item_error['message'], array(), $this, $delta . '.' . $column, $this->offsetGet($delta)->get($column)->getValue(), NULL, $item_error['error'])); + $property_names = $this->getFieldDefinition()->getFieldPropertyNames(); + $property_name = $property_names[0]; + $violations->add(new ConstraintViolation($item_error['message'], $item_error['message'], array(), $this, $delta . '.' . $property_name, $this->offsetGet($delta)->get($property_name)->getValue(), NULL, $item_error['error'])); } } } @@ -115,7 +127,7 @@ protected function legacyCallback($hook, $args = array()) { $items = (array) $this->getValue(TRUE); $args = array_merge(array( $entity, - $this->getInstance()->getField(), + $this->getFieldDefinition()->getField(), $this->getInstance(), $langcode, &$items diff --git a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php index 8407cbf..3c6a7eb 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php +++ b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php @@ -27,6 +27,16 @@ abstract class LegacyConfigFieldItem extends ConfigFieldItemBase implements PrepareCacheInterface { /** + * Returns the field instance definition. + * + * @return \Drupal\field\Entity\FieldInstance + * The field instance definition. + */ + protected function getInstance() { + return $this->getFieldDefinition(); + } + + /** * {@inheritdoc} */ public static function schema(FieldInterface $field) { @@ -49,7 +59,7 @@ public function isEmpty() { $item = $this->getValue(TRUE); // The previous hook was never called on an empty item, but EntityNG always // creates a FieldItem element for an empty field. - return empty($item) || $callback($item, $this->getInstance()->getField()->type); + return empty($item) || $callback($item, $this->getFieldDefinition()->getFieldType()); } /** @@ -59,7 +69,7 @@ public function settingsForm(array $form, array &$form_state, $has_data) { if ($callback = $this->getLegacyCallback('settings_form')) { // hook_field_settings_form() used to receive the $instance (not actually // needed), and the value of field_has_data(). - return $callback($this->getInstance()->getField(), $this->getInstance(), $has_data); + return $callback($this->getFieldDefinition()->getField(), $this->getInstance(), $has_data); } return array(); } @@ -69,7 +79,7 @@ public function settingsForm(array $form, array &$form_state, $has_data) { */ public function instanceSettingsForm(array $form, array &$form_state) { if ($callback = $this->getLegacyCallback('instance_settings_form')) { - return $callback($this->getInstance()->getField(), $this->getInstance(), $form_state); + return $callback($this->getFieldDefinition()->getField(), $this->getInstance(), $form_state); } return array(); } @@ -96,7 +106,7 @@ public function prepareCache() { $args = array( $entity->entityType(), array($entity_id => $entity), - $this->getInstance()->getField(), + $this->getFieldDefinition()->getField(), array($entity_id => $this->getInstance()), $langcode, &$items, @@ -119,7 +129,7 @@ public function getSettableOptions() { $callback = "{$definition['provider']}_options_list"; if (function_exists($callback)) { $entity = $this->getParent()->getParent(); - return $callback($this->getInstance(), $entity); + return $callback($this->getFieldDefinition(), $entity); } }