2009-10-17 00:51:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Install, update and uninstall functions for the shortcut module.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-02-26 18:31:29 +00:00
|
|
|
* Implements hook_install().
|
2009-10-17 00:51:53 +00:00
|
|
|
*/
|
2010-02-26 18:31:29 +00:00
|
|
|
function shortcut_install() {
|
2009-10-17 00:51:53 +00:00
|
|
|
$t = get_t();
|
|
|
|
// Create an initial default shortcut set.
|
2010-06-17 13:16:57 +00:00
|
|
|
$shortcut_set = new stdClass();
|
2009-10-17 00:51:53 +00:00
|
|
|
$shortcut_set->title = $t('Default');
|
2012-01-08 07:14:15 +00:00
|
|
|
$shortcut_set->links = array();
|
|
|
|
if (module_exists('node')) {
|
|
|
|
$shortcut_set->links[] = array(
|
2009-10-17 00:51:53 +00:00
|
|
|
'link_path' => 'node/add',
|
|
|
|
'link_title' => $t('Add content'),
|
|
|
|
'weight' => -20,
|
2012-01-08 07:14:15 +00:00
|
|
|
);
|
|
|
|
$shortcut_set->links[] = array(
|
2009-10-17 00:51:53 +00:00
|
|
|
'link_path' => 'admin/content',
|
|
|
|
'link_title' => $t('Find content'),
|
|
|
|
'weight' => -19,
|
2012-01-08 07:14:15 +00:00
|
|
|
);
|
|
|
|
}
|
2011-07-12 03:37:27 +00:00
|
|
|
// If Drupal is being installed, rebuild the menu before saving the shortcut
|
|
|
|
// set, to make sure the links defined above can be correctly saved. (During
|
|
|
|
// installation, the menu might not have been built at all yet, or it might
|
|
|
|
// have been built but without the node module's links in it.)
|
2012-03-13 03:16:40 +00:00
|
|
|
// drupal_installation_attempted() cannot be used here, as it relies on the
|
|
|
|
// MAINTENANCE_MODE constant value, which cannot be set when running tests, so
|
|
|
|
// we check the 'install_task' variable instead, which is only "done" when
|
|
|
|
// Drupal is already installed (i.e., we are not in the installer).
|
|
|
|
// @see http://drupal.org/node/1376150
|
|
|
|
if (variable_get('install_task', '') != 'done') {
|
2012-05-03 15:09:39 +00:00
|
|
|
menu_router_rebuild();
|
2011-07-12 03:37:27 +00:00
|
|
|
}
|
2009-10-17 00:51:53 +00:00
|
|
|
shortcut_set_save($shortcut_set);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_uninstall().
|
2009-10-17 00:51:53 +00:00
|
|
|
*/
|
|
|
|
function shortcut_uninstall() {
|
2011-06-15 04:45:51 +00:00
|
|
|
drupal_load('module', 'shortcut');
|
2009-10-17 00:51:53 +00:00
|
|
|
// Delete the menu links associated with each shortcut set.
|
|
|
|
foreach (shortcut_sets() as $shortcut_set) {
|
|
|
|
menu_delete_links($shortcut_set->set_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_schema().
|
2009-10-17 00:51:53 +00:00
|
|
|
*/
|
|
|
|
function shortcut_schema() {
|
|
|
|
$schema['shortcut_set'] = array(
|
|
|
|
'description' => 'Stores information about sets of shortcuts links.',
|
|
|
|
'fields' => array(
|
|
|
|
'set_name' => array(
|
|
|
|
'type' => 'varchar',
|
|
|
|
'length' => 32,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => '',
|
|
|
|
'description' => "Primary Key: The {menu_links}.menu_name under which the set's links are stored.",
|
|
|
|
),
|
|
|
|
'title' => array(
|
|
|
|
'type' => 'varchar',
|
|
|
|
'length' => 255,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => '',
|
|
|
|
'description' => 'The title of the set.',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'primary key' => array('set_name'),
|
|
|
|
'foreign keys' => array(
|
2010-08-22 13:55:53 +00:00
|
|
|
'menu_name' => array(
|
|
|
|
'table' => 'menu_links',
|
|
|
|
'columns' => array('set_name' => 'menu_name'),
|
|
|
|
),
|
2009-10-17 00:51:53 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
$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(
|
2010-08-22 13:55:53 +00:00
|
|
|
'set_user' => array(
|
|
|
|
'table' => 'users',
|
|
|
|
'columns' => array('uid' => 'uid'),
|
|
|
|
),
|
|
|
|
'set_name' => array(
|
|
|
|
'table' => 'shortcut_set',
|
|
|
|
'columns' => array('set_name' => 'set_name'),
|
|
|
|
),
|
2009-10-17 00:51:53 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
return $schema;
|
|
|
|
}
|