shortcut.install

Install, update and uninstall functions for the shortcut module.

File

drupal/core/modules/shortcut/shortcut.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the shortcut module.
 */
use Drupal\Component\Uuid\Uuid;

/**
 * Implements hook_uninstall().
 */
function shortcut_uninstall() {

  // Delete the menu links associated with each shortcut set.
  // @todo find a way to clean-up associated menu links.

  /*foreach (entity_load_multiple('shortcut') as $shortcut_set) {
      menu_delete_links('shortcut-' . $shortcut_set->id());
    }*/
}

/**
 * Implements hook_schema().
 */
function shortcut_schema() {
  $schema['shortcut_set_users'] = array(
    'description' => 'Maps users to shortcut sets.',
    'fields' => array(
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The {users}.uid for this set.',
      ),
      'set_name' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
        'description' => "The {shortcut_set}.set_name that will be displayed for this user.",
      ),
    ),
    'primary key' => array(
      'uid',
    ),
    'indexes' => array(
      'set_name' => array(
        'set_name',
      ),
    ),
    'foreign keys' => array(
      'set_user' => array(
        'table' => 'users',
        'columns' => array(
          'uid' => 'uid',
        ),
      ),
      'set_name' => array(
        'table' => 'shortcut_set',
        'columns' => array(
          'set_name' => 'set_name',
        ),
      ),
    ),
  );
  return $schema;
}

/**
 * @addtogroup updates-7.x-to-8.x
 * @{
 */

/**
 * Migrate shortcuts into configuration.
 */
function shortcut_update_8000() {
  $uuid = new Uuid();
  $result = db_query('SELECT * from {shortcut_set}');
  $ids = array();
  foreach ($result as $set) {

    // Save a config object.
    if ($set->set_name == 'shortcut-set-1') {

      // Change default shortcut id.
      $set->set_name = 'default';

      // Update menu links.
      db_update('menu_links')
        ->fields(array(
        'menu_name' => 'shortcut-default',
      ))
        ->condition('menu_name', 'shortcut-set-1')
        ->execute();
    }
    config('shortcut.set.' . $set->set_name)
      ->set('id', $set->set_name)
      ->set('label', $set->title)
      ->set('uuid', $uuid
      ->generate())
      ->save();
    $ids[] = $set->set_name;
  }
}

/**
 * Drop the {shortcut_set} table.
 */
function shortcut_update_8001() {
  db_drop_table('shortcut_set');
}

/**
 * @} End of "addtogroup updates-7.x-to-8.x".
 * The next series of updates should start at 9000.
 */

Functions

Namesort descending Description
shortcut_schema Implements hook_schema().
shortcut_uninstall Implements hook_uninstall().
shortcut_update_8000 Migrate shortcuts into configuration.
shortcut_update_8001 Drop the {shortcut_set} table.