You are here

public function NodeSubject::checkNodeFields in Changed Fields API 8

Notify all registered observers if needed.

Parameters

NodeInterface $node:

Overrides SubjectInterface::checkNodeFields

File

src/NodeSubject.php, line 76
Contains NodeSubject.php.

Class

NodeSubject
Class NodeSubject.

Namespace

Drupal\changed_fields

Code

public function checkNodeFields(NodeInterface $node) {
  foreach ($this->info as $nodeType => $fields) {
    if (!$node
      ->isNew() && $node
      ->getType() == $nodeType) {
      $changedFields = array();
      foreach ($fields as $fieldName) {
        $oldValue = $node->original
          ->get($fieldName)
          ->getValue();
        $newValue = $node
          ->get($fieldName)
          ->getValue();
        $fieldDefinition = $node
          ->get($fieldName)
          ->getFieldDefinition();
        $result = $this->fieldComparatorPlugin
          ->compareFieldValues($fieldDefinition, $oldValue, $newValue);
        if (is_array($result)) {
          $changedFields[$fieldName] = $result;
        }
      }
      if (!empty($changedFields)) {
        $this->node = $node;
        $this->changedFields = $changedFields;
        foreach ($this->observers as $observer) {
          $observer
            ->update($this);
        }
      }
    }
  }
}