function EntityReferenceItem::onChange

Same name in other branches
  1. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::onChange()
  2. 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::onChange()
  3. 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::onChange()
1 call to EntityReferenceItem::onChange()
EntityReferenceItem::setValue in core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php, line 286

Class

EntityReferenceItem
Defines the 'entity_reference' entity field type.

Namespace

Drupal\Core\Field\Plugin\Field\FieldType

Code

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() ? NULL : $property->getTargetIdentifier();
        $this->writePropertyValue('target_id', $target_id);
    }
    elseif ($property_name == 'target_id') {
        $this->writePropertyValue('entity', $this->target_id);
    }
    parent::onChange($property_name, $notify);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.