您在這裡

有無增加「刪除」頁籤 (tabs primary) 的模組?

chusiang's 的頭像
chusiang 在 2013-07-09 (二) 01:08 發表

一般建立篇新文章 (node) 時,會有檢視、編輯 … 等頁籤 (tabs primary),不知有無新增刪除頁籤的模組可用!?

- Make delete node a local menu task [#400510] | Drupal
- node_delete | node.module | Drupal 7 | Drupal API
- how get current node's nid? | drupal.org

我利用 hook_menu_local_tasks_alter(&$data, $router_item, $root_path)
加了一個 primary tab 如下圖
新增一個PRIMARY TAB

我的環境是 drupal 7.22 不需安裝啟用任何module
下方的程式碼是寫在 ../sites/all/themes/[sky]/template.php
其中 [sky] 是我套用的 theme 名稱,請至您使用的theme資料夾修改 template.php 檔案
如果沒有的話,就自行建立。

註:強烈建議不要直接修改 drupal core 的核心程式,以免一更新就全消失了。


function sky_menu_local_tasks_alter(&$data, $router_item, $root_path) {

if ($data['tabs'] && $router_item['tab_root_href']){
// Add a tab linking to node/add to all pages.
$data['tabs'][0]['output'][] = array(
//'access arguments' = array('access content');
'#theme' => 'menu_local_task',
'#link' => array(
'title' => t('刪除'),
'href' => $router_item['tab_root_href'] . '/delete',
'localized_options' => array(
'attributes' => array(
'title' => t('Delete this content'),
),
),
),
// Define whether this link is active. This can be omitted for implementations that add links to pages outside of the current page context.
'#active' => ($router_item['path'] == $root_path)
);
}

}

Drupal 新手
熱愛CSS