if (is_array($values) &&
array_key_exists('target_id',
$values) && !
isset($values['entity'
])) { $this->
onChange('target_id', FALSE
);
} elseif (is_array($values) && !
array_key_exists('target_id',
$values) &&
isset($values['entity'
])) { $this->
onChange('entity', FALSE
);
} elseif (is_array($values) &&
array_key_exists('target_id',
$values) &&
isset($values['entity'
])) { // If both properties are passed, verify the passed values match. The
// only exception we allow is when we have a new entity: in this case
// its actual id and target_id will be different, due to the new entity
// marker.
$entity_id =
$this->
get('entity'
)->
getTargetIdentifier();
// If the entity has been saved and we're trying to set both the
// target_id and the entity values with a non-null target ID, then the
// value for target_id should match the ID of the entity value. The
// entity ID as returned by $entity->id() might be a string, but the
// provided target_id might be an integer - therefore we have to do a
// non-strict comparison.
if (!
$this->entity->
isNew() &&
$values['target_id'
] !== NULL
&& ($entity_id !=
$values['target_id'
])) { throw new \
InvalidArgumentException('The target id and entity passed to the entity reference item do not match.'
);
} } // Notify the parent if necessary.