function PathTestMiscHooks::nodePresave
Implements hook_ENTITY_TYPE_presave() for node entities.
This is invoked from testAliasDuplicationPrevention.
Attributes
#[Hook('node_presave')]
File
-
core/
modules/ path/ tests/ modules/ path_test_misc/ src/ Hook/ PathTestMiscHooks.php, line 20
Class
- PathTestMiscHooks
- Hook implementations for path_test_misc.
Namespace
Drupal\path_test_misc\HookCode
public function nodePresave(NodeInterface $node) : void {
if ($node->getTitle() !== 'path duplication test') {
return;
}
// Update the title to be able to check that this code ran.
$node->setTitle('path duplication test ran');
// Create a path alias that has the same values as the one in
// PathItem::postSave.
$path = \Drupal::entityTypeManager()->getStorage('path_alias')
->create([
'path' => '/node/1',
'alias' => '/my-alias',
'langcode' => 'en',
]);
$path->save();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.