ノードページの編集タブをコンテキストメニューにしたい

カテゴリ コンテンツの管理 コアバージョン 7.38 関連モジュール Block Views node

Drupal標準では、ノード編集権を持つユーザーがノードページを表示した際、メインコンテンツとタイトルの間あたりにノード編集用のタブが表示されます。
これはこれで便利ですが、どうも見た目が未承認ユーザーで表示する場合といくらか異なり、気分が悪いです。
これをViewsやBlockのようにコンテキストメニュー(ネジアイコン)に置き換えるには?

コメント

ユーザー actbrain の写真

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>';
}
}
}
}

ページ

OTHER FAQ

Drupal開発・運用の疑問/質問の答えはここに

無料ユーザー登録すると質問できます。

カテゴリ Core Ver. 関連モジュール昇順で並び替える タイトル
Gmian 8.8.x Gmail Gmail:外部メールサーバー経由のメール送信ができなくなった場合の対処方法
コンテンツの作成 7.15 Form API Validation フォームの入力内容を細かくチェックしたい
コンテンツの作成 7.26 Form Ajax 入力フォームで#ajax使用時、#default_valueを書き換えても反映しない
サイトの構築 7.26 Field Views フォーム選択肢(プルダウンやチェックボックス、ラジオボタン)のカスタマイズ方法
コンテンツの管理 8.5.x Field File コンテンツのフィールドの表示について
テーマ 7.56 field レンダリング配列内に「ラベル非表示」を指定する方法
コンテンツの作成 7.50 Expanding Textareas Textareaフォームの行サイズを自動調整するモジュール
タクソノミー 7.15 Entity_Trarnslation Taxonomy TaxonomyのEntity Translation
コンテンツの作成 7.34 Entityreference prepopulate 新規ノード作成時のリファレンス方法
言語 7.15 Entity Translation デフォルトの言語 - Entity Translation
言語 7.15 Entity Translation 各フィールドのラベルの多言語切り替え漏れ(フィールド・ラベル)
言語 7.15 Entity Translation nodeのEntity Translation
言語 7.14 Entity Translation 各フィールドのラベルの多言語切り替え漏れ(接頭子、接尾子)
コンテンツの管理 8.4x Entity EntityをPropertyで探す(クエリする)方法
サイトの構築 7.34 ECK Entityの使い方について
Migrate 9.x drush config Upgrade source(環境) を 変更したときにやるべきこと
drush 7.54 Drush Drushでdrupalサイトをインストールする方法
PHP 8.9.x drush drush sql:cli < が機能しない場合の対処
サイトの構築 7.59 Drupal.ajax drupal 7 で Uncaught TypeError: Drupal.ajax is undefined となったときの対応方法
アップデート 7.50 Download count DOWNLOAD MODULEページでダウンロードが失敗することがある

ページ