You are here

changed_fields_basic_usage.module in Changed Fields API 8.2

File

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

/**
 * @file
 * Contains changed_fields_basic_usage.module.
 */
use Drupal\changed_fields\NodeSubject;
use Drupal\changed_fields_basic_usage\BasicUsageObserver;
use Drupal\node\NodeInterface;

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

  // Create NodeSubject object that will check node fields by DefaultFieldComparator.
  $nodeSubject = new NodeSubject($node, 'default_field_comparator');

  // Add your observer object to NodeSubject.
  $nodeSubject
    ->attach(new BasicUsageObserver());

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

Functions

Namesort descending Description
changed_fields_basic_usage_node_presave Implements hook_node_presave().