Skip to content
Snippets Groups Projects
Commit 09e8ddab authored by Alex Pott's avatar Alex Pott
Browse files

Revert "Issue #2403793 by larowlan: EntityReferenceItem uses a static, but it...

Revert "Issue #2403793 by larowlan: EntityReferenceItem uses a static, but it was most likely supposed to be a constant"

This reverts commit 4243b609.
parent 33eb65ae
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -41,7 +41,7 @@ class EntityReferenceItem extends FieldItemBase { ...@@ -41,7 +41,7 @@ class EntityReferenceItem extends FieldItemBase {
* *
* @var int * @var int
*/ */
const NEW_ENTITY_MARKER = -1; protected static $NEW_ENTITY_MARKER = -1;
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -168,7 +168,7 @@ public function setValue($values, $notify = TRUE) { ...@@ -168,7 +168,7 @@ public function setValue($values, $notify = TRUE) {
// its actual id and target_id will be different, due to the new entity // its actual id and target_id will be different, due to the new entity
// marker. // marker.
$entity_id = $this->get('entity')->getTargetIdentifier(); $entity_id = $this->get('entity')->getTargetIdentifier();
if ($entity_id != $values['target_id'] && ($values['target_id'] != static::NEW_ENTITY_MARKER || !$this->entity->isNew())) { if ($entity_id != $values['target_id'] && ($values['target_id'] != static::$NEW_ENTITY_MARKER || !$this->entity->isNew())) {
throw new \InvalidArgumentException('The target id and entity passed to the entity reference item do not match.'); throw new \InvalidArgumentException('The target id and entity passed to the entity reference item do not match.');
} }
} }
...@@ -201,10 +201,10 @@ public function onChange($property_name, $notify = TRUE) { ...@@ -201,10 +201,10 @@ public function onChange($property_name, $notify = TRUE) {
// Make sure that the target ID and the target property stay in sync. // Make sure that the target ID and the target property stay in sync.
if ($property_name == 'entity') { if ($property_name == 'entity') {
$property = $this->get('entity'); $property = $this->get('entity');
$target_id = $property->isTargetNew() ? static::NEW_ENTITY_MARKER : $property->getTargetIdentifier(); $target_id = $property->isTargetNew() ? static::$NEW_ENTITY_MARKER : $property->getTargetIdentifier();
$this->writePropertyValue('target_id', $target_id); $this->writePropertyValue('target_id', $target_id);
} }
elseif ($property_name == 'target_id' && $this->target_id != static::NEW_ENTITY_MARKER) { elseif ($property_name == 'target_id' && $this->target_id != static::$NEW_ENTITY_MARKER) {
$this->writePropertyValue('entity', $this->target_id); $this->writePropertyValue('entity', $this->target_id);
} }
parent::onChange($property_name, $notify); parent::onChange($property_name, $notify);
...@@ -262,7 +262,7 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin ...@@ -262,7 +262,7 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin
* TRUE if the item holds an unsaved entity. * TRUE if the item holds an unsaved entity.
*/ */
public function hasNewEntity() { public function hasNewEntity() {
return $this->target_id === static::NEW_ENTITY_MARKER; return $this->target_id === static::$NEW_ENTITY_MARKER;
} }
/** /**
......
...@@ -69,7 +69,7 @@ public function getSettableValues(AccountInterface $account = NULL) { ...@@ -69,7 +69,7 @@ public function getSettableValues(AccountInterface $account = NULL) {
// Flatten options firstly, because Settable Options may contain group // Flatten options firstly, because Settable Options may contain group
// arrays. // arrays.
$values = array_keys(OptGroup::flattenOptions($this->getSettableOptions($account))); $values = array_keys(OptGroup::flattenOptions($this->getSettableOptions($account)));
$values[] = static::NEW_ENTITY_MARKER; $values[] = static::$NEW_ENTITY_MARKER;
return $values; return $values;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment