Same name and namespace in other branches
- 7.x modules/book/book.module \book_node_type_update()
- 8.9.x core/modules/book/book.module \book_node_type_update()
- 9 core/modules/book/book.module \book_node_type_update()
Implements hook_ENTITY_TYPE_update() for node_type entities.
Updates book.settings configuration object if the machine-readable name of a node type is changed.
File
- core/
modules/ book/ book.module, line 520 - Allows users to create and organize related content in an outline.
Code
function book_node_type_update(NodeTypeInterface $type) {
if ($type
->getOriginalId() != $type
->id()) {
$config = \Drupal::configFactory()
->getEditable('book.settings');
// Update the list of node types that are allowed to be added to books.
$allowed_types = $config
->get('allowed_types');
$old_key = array_search($type
->getOriginalId(), $allowed_types);
if ($old_key !== FALSE) {
$allowed_types[$old_key] = $type
->id();
// Ensure that the allowed_types array is sorted consistently.
// @see BookSettingsForm::submitForm()
sort($allowed_types);
$config
->set('allowed_types', $allowed_types);
}
// Update the setting for the "Add child page" link.
if ($config
->get('child_type') == $type
->getOriginalId()) {
$config
->set('child_type', $type
->id());
}
$config
->save();
}
}