menu_link_content.install

Same filename in other branches
  1. 9 core/modules/menu_link_content/menu_link_content.install
  2. 10 core/modules/menu_link_content/menu_link_content.install
  3. 11.x core/modules/menu_link_content/menu_link_content.install

Install, update and uninstall functions for the menu_link_content module.

File

core/modules/menu_link_content/menu_link_content.install

View source
<?php


/**
 * @file
 * Install, update and uninstall functions for the menu_link_content module.
 */

/**
 * Implements hook_requirements().
 */
function menu_link_content_requirements($phase) {
    $requirements = [];
    if ($phase === 'update') {
        // Check for invalid data before making links revisionable.
        
        /** @var \Drupal\Core\Update\UpdateRegistry $registry */
        $registry = \Drupal::service('update.post_update_registry');
        $update_name = 'menu_link_content_post_update_make_menu_link_content_revisionable';
        if (in_array($update_name, $registry->getPendingUpdateFunctions(), TRUE)) {
            // The 'enabled' field is non-NULL - if we get a NULL value that indicates
            // a failure to join on menu_link_content_data.
            $is_broken = \Drupal::entityQuery('menu_link_content')->condition('enabled', NULL, 'IS NULL')
                ->range(0, 1)
                ->accessCheck(FALSE)
                ->execute();
            if ($is_broken) {
                $requirements[$update_name] = [
                    'title' => t('Menu link content data'),
                    'value' => t('Integrity issues detected'),
                    'description' => t('The make_menu_link_content_revisionable database update cannot be run until the data has been fixed. See the <a href=":change_record">change record</a> for more information.', [
                        ':change_record' => 'https://www.drupal.org/node/3117753',
                    ]),
                    'severity' => REQUIREMENT_ERROR,
                ];
            }
        }
    }
    return $requirements;
}

/**
 * Add the publishing status entity key to custom menu links.
 */
function menu_link_content_update_8601() {
    $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
    $entity_type = $definition_update_manager->getEntityType('menu_link_content');
    // Add the published entity key to the menu_link_content entity type.
    $entity_keys = $entity_type->getKeys();
    $entity_keys['published'] = 'enabled';
    $entity_type->set('entity_keys', $entity_keys);
    $definition_update_manager->updateEntityType($entity_type);
    // @todo The above should be enough, since that is the only definition that
    //   changed. But \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema varies
    //   field schema by whether a field is an entity key, so invoke
    //   EntityDefinitionUpdateManagerInterface::updateFieldStorageDefinition()
    //   with an unmodified field storage definition to trigger the necessary
    //   changes. SqlContentEntityStorageSchema::onEntityTypeUpdate() should be
    //   fixed to automatically handle this.
    //   @see https://www.drupal.org/node/2554245
    $definition_update_manager->updateFieldStorageDefinition($definition_update_manager->getFieldStorageDefinition('enabled', 'menu_link_content'));
    return t('The publishing status entity key has been added to custom menu links.');
}

Functions

Title Deprecated Summary
menu_link_content_requirements Implements hook_requirements().
menu_link_content_update_8601 Add the publishing status entity key to custom menu links.

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