Commit 4243b609 authored by alexpott's avatar alexpott

Issue #2403793 by larowlan: EntityReferenceItem uses a static, but it was most...

Issue #2403793 by larowlan: EntityReferenceItem uses a static, but it was most likely supposed to be a constant
parent 73e5bfad
......@@ -41,7 +41,7 @@ class EntityReferenceItem extends FieldItemBase {
*
* @var int
*/
protected static $NEW_ENTITY_MARKER = -1;
const NEW_ENTITY_MARKER = -1;
/**
* {@inheritdoc}
......@@ -168,7 +168,7 @@ public function setValue($values, $notify = TRUE) {
// its actual id and target_id will be different, due to the new entity
// marker.
$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.');
}
}
......@@ -201,10 +201,10 @@ public function onChange($property_name, $notify = TRUE) {
// Make sure that the target ID and the target property stay in sync.
if ($property_name == '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);
}
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);
}
parent::onChange($property_name, $notify);
......@@ -262,7 +262,7 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin
* TRUE if the item holds an unsaved entity.
*/
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) {
// Flatten options firstly, because Settable Options may contain group
// arrays.
$values = array_keys(OptGroup::flattenOptions($this->getSettableOptions($account)));
$values[] = static::$NEW_ENTITY_MARKER;
$values[] = static::NEW_ENTITY_MARKER;
return $values;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment