You are here

public function EntityReferenceRevisionsItem::onChange in Entity Reference Revisions 8

Parameters

bool $notify: (optional) Whether to forward the notification to the parent. Defaults to TRUE. By passing FALSE, overrides of this method can re-use the logic of parent classes without triggering notification.

Overrides EntityReferenceItem::onChange

1 call to EntityReferenceRevisionsItem::onChange()
EntityReferenceRevisionsItem::setValue in src/Plugin/Field/FieldType/EntityReferenceRevisionsItem.php
Sets the data value.

File

src/Plugin/Field/FieldType/EntityReferenceRevisionsItem.php, line 210

Class

EntityReferenceRevisionsItem
Defines the 'entity_reference_revisions' entity field type.

Namespace

Drupal\entity_reference_revisions\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);
    $this
      ->writePropertyValue('target_revision_id', $property
      ->getValue()
      ->getRevisionId());
  }
  elseif ($property_name == 'target_id' && $this->target_id != NULL && $this->target_revision_id) {
    $this
      ->writePropertyValue('entity', array(
      'target_id' => $this->target_id,
      'target_revision_id' => $this->target_revision_id,
    ));
  }
  elseif ($property_name == 'target_revision_id' && $this->target_revision_id && $this->target_id) {
    $this
      ->writePropertyValue('entity', array(
      'target_id' => $this->target_id,
      'target_revision_id' => $this->target_revision_id,
    ));
  }
  if ($notify && isset($this->parent)) {
    $this->parent
      ->onChange($this->name);
  }
}