Drupal標準では、ノード編集権を持つユーザーがノードページを表示した際、メインコンテンツとタイトルの間あたりにノード編集用のタブが表示されます。
これはこれで便利ですが、どうも見た目が未承認ユーザーで表示する場合といくらか異なり、気分が悪いです。
これをViewsやBlockのようにコンテキストメニュー(ネジアイコン)に置き換えるには?
ノードページの編集タブをコンテキストメニューにしたい
OTHER FAQ
カテゴリ | Core Ver. | 関連モジュール | タイトル |
---|---|---|---|
アップデート | 8.9.x | composer patch | patch を composer に 組み込む方法 |
アップデート | 8.9.x | Composer update | Composer で drupal/core-8.9.7 に更新できなくなった場合の処置 |
コンテンツの作成 | 8.9.x | CSS | キャプション付きの(右寄/左寄)画像を画像サイズを基準にきれいに表示する方法 |
アップデート | 8.9.x | PHP | CentosでPHPのバージョンアップ(例:5.3->5.6)を行う方法 |
リバースプロキシ | 8.9.x | mod_proxy mod_proxy_http mod_ssl | Apache2.4 から httpsサーバーへリバースプロキシする方法 |
テーマ | 8.9.x | Twig | Twig で 月末日を算出する方法 |
Migrate | 9.x | drush config | Upgrade source(環境) を 変更したときにやるべきこと |
コメント
hook_preprocess_page() と hook
パーマリンク Submitted by actbrain on 2015/07/01 16:00.
hook_preprocess_page() と hook_preprocess_node() を使うことで可能になります。
/**
* Implement hook_preproces_page().
*/
function モジュール名_preprocess_page(&$variables) {
if (ノード編集タブをネジアイコンにしたい) {
if (user_access('access contextual links')) {
if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2)) {
$variables['tabs'] = array('#secondary' => array()); // 標準の編集タブを削除
}
}
}
}
/**
* Imprement hook_preprocess_node().
*/
function モジュール名_preprocess_node(&$variables) {
if (ノード編集タブをネジアイコンにしたい) {
if (user_access('access contextual links')) {
$menu_local_tasks = menu_local_tasks();
if (isset($menu_local_tasks['tabs']['output'])) {
$variables['content']['#prefix'] = '<div class="contextual-links-region">'.
'<div class="contextual-links-wrapper">'.
'<ul class="contextual-links">'.
render($menu_local_tasks['tabs']['output']).
'</ul>'.
'</div>';
$variables['content']['#suffix'] = '</div>';
}
}
}
}
ページ