3 namespace Drupal\Core\TypedData;
6 * Base class for typed data references.
8 * Data types based on this base class need to be named
9 * "{TARGET_TYPE}_reference", whereas {TARGET_TYPE} is the referenced data type.
10 * For example, an entity reference data type would have to be named
12 * Beside that, implementing classes have to implement at least
13 * \Drupal\Core\TypedData\DataReferenceInterface::getTargetIdentifier().
15 * @see \Drupal\Core\TypedData\DataReferenceDefinition
17 abstract class DataReferenceBase extends TypedData implements DataReferenceInterface {
20 * The referenced data.
22 * @var \Drupal\Core\TypedData\TypedDataInterface
29 public function getTarget() {
36 public function getValue() {
37 if ($target = $this->getTarget()) {
38 return $target->getValue();
45 public function setValue($value, $notify = TRUE) {
46 $this->target = $this->getTypedDataManager()->create($this->definition->getTargetDefinition(), $value);
47 // Notify the parent of any changes.
48 if ($notify && isset($this->parent)) {
49 $this->parent->onChange($this->name);
56 public function getString() {
57 return (string) $this->getType() . ':' . $this->getTargetIdentifier();