You are here

public function CFNodeSubject::checkNodeFields in Changed Fields API 7.2

Same name and namespace in other branches
  1. 7 includes/changed_fields.core.inc \CFNodeSubject::checkNodeFields()

Notify all registered observers if needed.

Overrides CFSubjectInterface::checkNodeFields

File

includes/changed_fields.core.inc, line 172
File contains core classes and interfaces.

Class

CFNodeSubject
Class CFNodeSubject.

Code

public function checkNodeFields() {
  foreach ($this->info as $nodeType => $fields) {
    if (isset($this->node->original) && $this->node->type == $nodeType) {
      $this->node->changed_fields = array();
      foreach ($fields as $fieldName) {
        if ($fieldName == 'title') {
          $oldValue = $this->node->original->{$fieldName};
          $newValue = $this->node->{$fieldName};
          $fieldInfo['field_base'] = array(
            'type' => 'title',
          );
        }
        else {
          $oldValue = field_get_items('node', $this->node->original, $fieldName);
          $newValue = field_get_items('node', $this->node, $fieldName);
          $fieldInfo['field_base'] = field_info_field($fieldName);
        }
        $fieldInfo['field_instance'] = field_info_instance('node', $fieldName, $nodeType);
        $result = $this->fieldComparator
          ->runFieldComparison($fieldInfo, $oldValue, $newValue);
        if (is_array($result)) {
          $this->node->changed_fields[$fieldName] = $result;
        }
      }
      if (!empty($this->node->changed_fields)) {
        foreach ($this->observers as $observer) {
          $observer
            ->update($this);
        }
      }
    }
  }
}