changed_fields_basic_usage.module in Changed Fields API 8.3
Same filename and directory in other branches
- 8 examples/changed_fields_basic_usage/changed_fields_basic_usage.module
- 8.2 examples/changed_fields_basic_usage/changed_fields_basic_usage.module
- 7.3 examples/changed_fields_basic_usage/changed_fields_basic_usage.module
- 7 examples/changed_fields_basic_usage/changed_fields_basic_usage.module
- 7.2 examples/changed_fields_basic_usage/changed_fields_basic_usage.module
This is the Changed Fields Basic Usage example module.
File
examples/changed_fields_basic_usage/changed_fields_basic_usage.moduleView source
<?php
/**
* @file
* This is the Changed Fields Basic Usage example module.
*/
use Drupal\changed_fields\EntitySubject;
use Drupal\changed_fields_basic_usage\BasicUsageObserver;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_entity_presave().
*/
function changed_fields_entity_presave(EntityInterface $entity) {
if ($entity instanceof ContentEntityInterface) {
// Create EntitySubject object that will check entity fields
// by DefaultFieldComparator.
$entity_subject = new EntitySubject($entity);
// Add your observer object to EntitySubject.
$entity_subject
->attach(new BasicUsageObserver());
// Check if entity fields have been changed.
$entity_subject
->notify();
}
}
Functions
Name![]() |
Description |
---|---|
changed_fields_entity_presave | Implements hook_entity_presave(). |