function EditorTestHooks::entityUpdate
Implements hook_entity_update().
See also
\Drupal\Tests\editor\Kernel\EntityUpdateTest
File
-
core/
modules/ editor/ tests/ modules/ editor_test/ src/ Hook/ EditorTestHooks.php, line 23
Class
- EditorTestHooks
- Hook implementations for editor_test.
Namespace
Drupal\editor_test\HookCode
public function entityUpdate(EntityInterface $entity) {
// Only act on nodes.
if (!$entity instanceof NodeInterface) {
return;
}
// Avoid infinite loop by only going through our post save logic once.
if (!empty($entity->editor_test_updating)) {
return;
}
// Set flag for whether or not the entity needs to be resaved.
$needs_update = FALSE;
// Perform our post save logic.
if ($entity->title->value == 'test updated') {
// Change the node title.
$entity->title->value = 'test updated 2';
$needs_update = TRUE;
}
if ($needs_update) {
// Set flag on entity that our logic was already executed.
$entity->editor_test_updating = TRUE;
// And resave entity.
$entity->save();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.