diff --git a/core/lib/Drupal/Core/Entity/Field/Field.php b/core/lib/Drupal/Core/Entity/Field/Field.php index 0ff36d7..2e2a3bf 100644 --- a/core/lib/Drupal/Core/Entity/Field/Field.php +++ b/core/lib/Drupal/Core/Entity/Field/Field.php @@ -59,6 +59,20 @@ public function getFieldDefinition() { /** * {@inheritdoc} */ + public function getEntity() { + return $this->getParent(); + } + + /** + * {@inheritdoc} + */ + public function language() { + return $this->getEntity()->language(); + } + + /** + * {@inheritdoc} + */ public function filterEmptyValues() { if (isset($this->list)) { $this->list = array_values(array_filter($this->list, function($item) { diff --git a/core/lib/Drupal/Core/Entity/Field/FieldInterface.php b/core/lib/Drupal/Core/Entity/Field/FieldInterface.php index 0d85da3..1d02e8b 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldInterface.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldInterface.php @@ -36,6 +36,22 @@ public function getFieldDefinition(); /** + * Gets the entity that field belongs to. + * + * @return Drupal\Core\TypedData\ComplexDataInterface + * The entity object. + */ + public function getEntity(); + + /** + * Returns the field language. + * + * @return \Drupal\Core\Language\Language + * The language object. + */ + public function language(); + + /** * Filters out empty field items and re-numbers the item deltas. */ public function filterEmptyValues(); diff --git a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php index c021c57..3345f19 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php @@ -67,6 +67,20 @@ protected function getFieldSetting($setting_name) { } /** + * {@inheritdoc} + */ + public function getEntity() { + return $this->getParent()->getEntity(); + } + + /** + * {@inheritdoc} + */ + public function language() { + return $this->getParent()->language(); + } + + /** * Overrides \Drupal\Core\TypedData\TypedData::setValue(). * * @param array|null $values diff --git a/core/lib/Drupal/Core/Entity/Field/FieldItemInterface.php b/core/lib/Drupal/Core/Entity/Field/FieldItemInterface.php index e4adcdc..87b5774 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldItemInterface.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldItemInterface.php @@ -32,6 +32,22 @@ public function getFieldDefinition(); /** + * Gets the entity that field belongs to. + * + * @return Drupal\Core\TypedData\ComplexDataInterface + * The entity object. + */ + public function getEntity(); + + /** + * Returns the field language. + * + * @return \Drupal\Core\Language\Language + * The language object. + */ + public function language(); + + /** * Magic method: Gets a property value. * * @param $property_name 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..d9d4f8b 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php +++ b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigField.php @@ -39,8 +39,7 @@ public function validate() { $legacy_errors = array(); $this->legacyCallback('validate', array(&$legacy_errors)); - $entity = $this->getParent(); - $langcode = $entity->language()->id; + $langcode = $this->language()->id; if (isset($legacy_errors[$this->getInstance()->getField()->id()][$langcode])) { foreach ($legacy_errors[$this->getInstance()->getField()->id()][$langcode] as $delta => $item_errors) { @@ -105,13 +104,13 @@ protected function legacyCallback($hook, $args = array()) { $module = $definition['provider']; $callback = "{$module}_field_{$hook}"; if (function_exists($callback)) { - $entity = $this->getParent(); - $langcode = $entity->language()->id; + $entity = $this->getEntity(); + $langcode = $this->language()->id; // We need to remove the empty "prototype" item here. // @todo Revisit after http://drupal.org/node/1988492. $this->filterEmptyValues(); - // Legcacy callbacks alter $items by reference. + // Legacy callbacks alter $items by reference. $items = (array) $this->getValue(TRUE); $args = array_merge(array( $entity, 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 0bad0d0..e9f0cd9 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 @@ -86,7 +86,7 @@ public function instanceSettingsForm(array $form, array &$form_state) { */ public function prepareCache() { if ($callback = $this->getLegacyCallback('load')) { - $entity = $this->getParent()->getParent(); + $entity = $this->getEntity(); $langcode = $entity->language()->id; $entity_id = $entity->id(); diff --git a/core/modules/node/lib/Drupal/node/Plugin/Validation/Constraint/NodeChangedConstraintValidator.php b/core/modules/node/lib/Drupal/node/Plugin/Validation/Constraint/NodeChangedConstraintValidator.php index 0479e38..99a1884 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/Validation/Constraint/NodeChangedConstraintValidator.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Validation/Constraint/NodeChangedConstraintValidator.php @@ -20,9 +20,7 @@ class NodeChangedConstraintValidator extends ConstraintValidator { */ public function validate($value, Constraint $constraint) { if (isset($value)) { - // We are on the field item level, so we need to go two levels up for the - // node object. - $node = $this->context->getMetadata()->getTypedData()->getParent()->getParent(); + $node = $this->context->getMetadata()->getTypedData()->getEntity(); $id = $node->id(); $language = $node->language(); if ($id && (node_last_changed($id, $language->id) > $value)) { diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php index cf41e9d..d4305b5 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php @@ -77,7 +77,7 @@ public function prepareCache() { $text_processing = $this->getFieldSetting('text_processing'); if (!$text_processing || filter_format_allowcache($this->get('format')->getValue())) { $itemBC = $this->getValue(); - $langcode = $this->getParent()->getParent()->language()->id; + $langcode = $this->language()->id; $this->set('safe_value', text_sanitize($text_processing, $langcode, $itemBC, 'value')); if ($this->getType() == 'field_item:text_with_summary') { $this->set('safe_summary', text_sanitize($text_processing, $langcode, $itemBC, 'summary'));