public function NodeSubject::notify in Changed Fields API 8.2
File
- src/
NodeSubject.php, line 67 - Contains NodeSubject.php.
Class
- NodeSubject
- Class NodeSubject.
Namespace
Drupal\changed_fieldsCode
public function notify() {
foreach ($this->observers as $observer) {
foreach ($observer
->getInfo() as $nodeType => $fields) {
if (!$this->node
->isNew() && $this->node
->getType() == $nodeType) {
$changedFields = [];
foreach ($fields as $fieldName) {
$oldValue = $this->node->original
->get($fieldName)
->getValue();
$newValue = $this->node
->get($fieldName)
->getValue();
$fieldDefinition = $this->node
->get($fieldName)
->getFieldDefinition();
$result = $this->fieldComparatorPlugin
->compareFieldValues($fieldDefinition, $oldValue, $newValue);
if (is_array($result)) {
$changedFields[$fieldName] = $result;
}
}
if (!empty($changedFields)) {
$this->changedFields = $changedFields;
$observer
->update($this);
}
}
}
}
}