0

我正在编写一个 drupal 7 安装配置文件,并且无法让它为工具栏设置一些默认快捷方式,因为我没有找到其中的内容之一。

在 .install 文件中,我有以下代码:

// Set Up Shortcuts
$shortcut_set = shortcut_set_load(SHORTCUT_DEFAULT_SET_NAME);
$shortcut_set->links = array(
array(
  'link_path' => 'node/add',
  'link_title' => st('Add content'),
  'weight' => -20,
),
array(
  'link_path' => 'admin/existing-content',
  'link_title' => st('Existing content'),
  'weight' => -19,
),
array(
  'link_path' => 'admin/structure/menu/manage/main-menu',
  'link_title' => st('Menu'),
  'weight' => -18,
),
);
shortcut_set_save($shortcut_set);

如何让它覆盖默认值?

4

1 回答 1

0

在安装过程中,创建一个新集合并将集合名称保存在一个变量中。

// Create new short-cut set
$set = new stdClass();
$set->title = 'My Shortcuts';
$set->links = array(
  array(
    'link_path' => 'node/add',
    'link_title' => st('Add content'),
    'weight' => 1,
  )
);

// Save short-cut set
shortcut_set_save($set);
variable_set('my_shortcuts', $set->set_name);

然后在一个模块中,实现“shortcut_default_set”钩子。

function mymodule_short_default_set($account)
{
  return variable_get('my_shortcuts');
}
于 2012-08-07T16:18:34.247 回答