system.install

Same filename and directory in other branches
  1. 11.x core/modules/system/system.install
  2. 10 core/modules/system/system.install
  3. 9 core/modules/system/system.install
  4. 8.9.x core/modules/system/system.install
  5. 7.x modules/system/system.install

Install, update and uninstall functions for the system module.

File

core/modules/system/system.install

View source
<?php


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

use Drupal\Component\Utility\Crypt;
use Drupal\Core\Config\Entity\ConfigEntityType;
use Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Update\EquivalentUpdate;

/**
 * Implements hook_install().
 */
function system_install() : void {
  // Populate the cron key state variable.
  $cron_key = Crypt::randomBytesBase64(55);
  \Drupal::state()->set('system.cron_key', $cron_key);
  // Populate the site UUID and default name (if not set).
  $site = \Drupal::configFactory()->getEditable('system.site');
  $site->set('uuid', \Drupal::service('uuid')->generate());
  if (!$site->get('name')) {
    $site->set('name', 'Drupal');
  }
  $site->save();
  // Populate the dummy query string added to all CSS and JavaScript files.
  \Drupal::service('asset.query_string')->reset();
}

/**
 * Implements hook_update_last_removed().
 */
function system_update_last_removed() : int {
  return 11300;
}

/**
 * Moved to search_update_11401().
 */
function system_update_11400() : void {
}

/**
 * Moved to search_update_11402().
 */
function system_update_11401() : void {
}

/**
 * Remove the deprecated sequences table.
 */
function system_update_12000() : void {
  $schema = \Drupal::database()->schema();
  if ($schema->tableExists('sequences')) {
    $schema->dropTable('sequences');
  }
}

/**
 * Equivalent update to 11102.
 */
function system_update_12001() : TranslatableMarkup|null {
  // This is a no-op that exists to prevent an upgrade from 11.4+ to 12.0. That
  // path is actually a downgrade.
  $equivalent_update = \Drupal::service('update.update_hook_registry')->getEquivalentUpdate();
  if ($equivalent_update instanceof EquivalentUpdate) {
    return $equivalent_update->toSkipMessage();
  }
  return NULL;
}

/**
 * Install new design token entity type.
 */
function system_update_12002() : void {
  $entityDefinitionUpdateManager = \Drupal::entityDefinitionUpdateManager();
  $changeList = $entityDefinitionUpdateManager->getChangeList();
  if (isset($changeList['design_token']['entity_type']) && $changeList['design_token']['entity_type'] == EntityDefinitionUpdateManagerInterface::DEFINITION_CREATED) {
    $designTokenEntityType = new ConfigEntityType([
      'id' => 'design_token',
      'label' => new TranslatableMarkup('Design token'),
      'entity_keys' => [
        'id' => 'id',
        'label' => 'id',
      ],
      'admin_permission' => 'administer design tokens',
      'constraints' => [
        'ImmutableProperties' => [
          'properties' => [
            'id',
            'path',
            'type',
          ],
        ],
      ],
      'config_export' => [
        'id',
        'path',
        'type',
        'scopes',
      ],
    ]);
    $entityDefinitionUpdateManager->installEntityType($designTokenEntityType);
  }
}

Functions

Title Deprecated Summary
system_install Implements hook_install().
system_update_11400 Moved to search_update_11401().
system_update_11401 Moved to search_update_11402().
system_update_12000 Remove the deprecated sequences table.
system_update_12001 Equivalent update to 11102.
system_update_12002 Install new design token entity type.
system_update_last_removed Implements hook_update_last_removed().

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