You are here

changed_fields_basic_usage.module in Changed Fields API 7

File

examples/changed_fields_basic_usage/changed_fields_basic_usage.module
View source
<?php

/**
 * @file
 * changed_fields_basic_usage.module file.
 */

/**
 * Implements hook_node_presave().
 */
function changed_fields_basic_usage_node_presave(stdClass $node) {

  // Enlist node types with their fields for watching.
  $notifySettings = array(
    'article' => array(
      'title',
      'body',
    ),
  );

  // Create CFNodeSubject object that will check node fields by CFDefaultFieldComparator.
  $nodeSubject = new CFNodeSubject($node, $notifySettings, new CFDefaultFieldComparator());

  // Add your observer object to CFNodeSubject.
  // See includes/changed_fields_basic_usage.observer.inc file.
  $nodeSubject
    ->addObserver(new BasicUsageObserver('test_observer'));

  // Check if node fields have been changed.
  $nodeSubject
    ->checkNodeFields();
}

Functions