cms/drupal/modules/shortcut/shortcut.install
changeset 541 e756a8c72c3d
equal deleted inserted replaced
540:07239de796bb 541:e756a8c72c3d
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * @file
       
     5  * Install, update and uninstall functions for the shortcut module.
       
     6  */
       
     7 
       
     8 /**
       
     9  * Implements hook_install().
       
    10  */
       
    11 function shortcut_install() {
       
    12   $t = get_t();
       
    13   // Create an initial default shortcut set.
       
    14   $shortcut_set = new stdClass();
       
    15   $shortcut_set->title = $t('Default');
       
    16   $shortcut_set->links = array(
       
    17     array(
       
    18       'link_path' => 'node/add',
       
    19       'link_title' => $t('Add content'),
       
    20       'weight' => -20,
       
    21     ),
       
    22     array(
       
    23       'link_path' => 'admin/content',
       
    24       'link_title' => $t('Find content'),
       
    25       'weight' => -19,
       
    26     ),
       
    27   );
       
    28   // If Drupal is being installed, rebuild the menu before saving the shortcut
       
    29   // set, to make sure the links defined above can be correctly saved. (During
       
    30   // installation, the menu might not have been built at all yet, or it might
       
    31   // have been built but without the node module's links in it.)
       
    32   if (drupal_installation_attempted()) {
       
    33     menu_rebuild();
       
    34   }
       
    35   shortcut_set_save($shortcut_set);
       
    36 }
       
    37 
       
    38 /**
       
    39  * Implements hook_uninstall().
       
    40  */
       
    41 function shortcut_uninstall() {
       
    42   drupal_load('module', 'shortcut');
       
    43   // Delete the menu links associated with each shortcut set.
       
    44   foreach (shortcut_sets() as $shortcut_set) {
       
    45     menu_delete_links($shortcut_set->set_name);
       
    46   }
       
    47 }
       
    48 
       
    49 /**
       
    50  * Implements hook_schema().
       
    51  */
       
    52 function shortcut_schema() {
       
    53   $schema['shortcut_set'] = array(
       
    54     'description' => 'Stores information about sets of shortcuts links.',
       
    55     'fields' => array(
       
    56       'set_name' => array(
       
    57         'type' => 'varchar',
       
    58         'length' => 32,
       
    59         'not null' => TRUE,
       
    60         'default' => '',
       
    61         'description' => "Primary Key: The {menu_links}.menu_name under which the set's links are stored.",
       
    62       ),
       
    63       'title' => array(
       
    64         'type' => 'varchar',
       
    65         'length' => 255,
       
    66         'not null' => TRUE,
       
    67         'default' => '',
       
    68         'description' => 'The title of the set.',
       
    69       ),
       
    70     ),
       
    71     'primary key' => array('set_name'),
       
    72     'foreign keys' => array(
       
    73       'menu_name' => array(
       
    74         'table' => 'menu_links',
       
    75         'columns' => array('set_name' => 'menu_name'),
       
    76       ),
       
    77     ),
       
    78   );
       
    79 
       
    80   $schema['shortcut_set_users'] = array(
       
    81     'description' => 'Maps users to shortcut sets.',
       
    82     'fields' => array(
       
    83       'uid' => array(
       
    84         'type' => 'int',
       
    85         'unsigned' => TRUE,
       
    86         'not null' => TRUE,
       
    87         'default' => 0,
       
    88         'description' => 'The {users}.uid for this set.',
       
    89       ),
       
    90       'set_name' => array(
       
    91         'type' => 'varchar',
       
    92         'length' => 32,
       
    93         'not null' => TRUE,
       
    94         'default' => '',
       
    95         'description' => "The {shortcut_set}.set_name that will be displayed for this user.",
       
    96       ),
       
    97     ),
       
    98     'primary key' => array('uid'),
       
    99     'indexes' => array(
       
   100       'set_name' => array('set_name'),
       
   101     ),
       
   102     'foreign keys' => array(
       
   103       'set_user' => array(
       
   104         'table' => 'users',
       
   105         'columns' => array('uid' => 'uid'),
       
   106       ),
       
   107       'set_name' => array(
       
   108         'table' => 'shortcut_set',
       
   109         'columns' => array('set_name' => 'set_name'),
       
   110       ),
       
   111     ),
       
   112   );
       
   113 
       
   114   return $schema;
       
   115 }