function editor_test_entity_update
Same name in other branches
- 10 core/modules/editor/tests/modules/editor_test/editor_test.module \editor_test_entity_update()
- 11.x core/modules/editor/tests/modules/editor_test/editor_test.module \editor_test_entity_update()
Implements hook_entity_update().
See also
\Drupal\Tests\editor\Kernel\EntityUpdateTest
File
-
core/
modules/ editor/ tests/ modules/ editor_test/ editor_test.module, line 18
Code
function editor_test_entity_update(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.