function book_node_type_update

Same name in other branches
  1. 7.x modules/book/book.module \book_node_type_update()
  2. 8.9.x core/modules/book/book.module \book_node_type_update()
  3. 10 core/modules/book/book.module \book_node_type_update()
  4. 11.x 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

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();
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.