You are here

public function CFNodeSubject::checkNodeFields in Changed Fields API 7

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

Notify all registered observers if needed.

Overrides CFSubject::checkNodeFields

File

includes/changed_fields.core.inc, line 138
changed_fields.core.inc file.

Class

CFNodeSubject
Class CFNodeSubject.

Code

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