logo

パレット - カラフルに🎨

Palette — ビジュアルページビルダー、デザインの専門知識は不要です。

ライブデモ パレットをダウンロード

Scroll

Drupal 7 の Admin menu にコンテンツ追加リンクを付ける

17/04/2025, by Ivan

新しい toolbar モジュールは、確かに admin menu より見た目が良いです。しかし、私は admin menu が好きです。というのも、好きなだけリンクを追加でき、そのすべてにマウスのワンクリックでアクセスできるからです。
だから admin menu を使いたいのです。インストールすると、文字化けが見えます……エンコーディングの問題です。
.htaccess ファイルを開いて、末尾に次の行を追加しましょう:

AddDefaultCharset UTF-8

これですべて問題なく見えるようになり、ロシア語の文字が表示されますが……「Add content(コンテンツを追加)」リンクがありません。手動で追加する必要があります。そのために、独自のモジュールを作成して次のコードを追加します:

<?php

/**
* @file
* Adds "Create Content" links to the Admin Menu, and removes "Tasks" and "Index".
*/

/**
* Implementation of hook_admin_menu_output_alter().
*
* Add "Create content" as a top level submenu in the admin menu.
*/
function custom_admin_menu_output_alter(&$content) {
  // Add a top level item for the Create content menu itself.
  $content['create_content_links'] = array(
    '#theme' => 'admin_menu_links',
    '#weight' => -99,
    '#sorted' => TRUE,
  );

  // Copy the create content submenu to our backend menu.
  $content['create_content_links']['create-content'] = array(
    '#title' => t('Create'),
    '#href' => 'node/add',
    '#weight' => -10,
  );

  foreach(node_type_get_types() as $type => $object) {
    if (node_access('create', $type)) {
      $node_type_url = str_replace('_', '-', $type);
      $content['create_content_links']['create-content'][$node_type_url] = array(
        '#title' => $object->name,
        '#href' => 'node/add/'. $node_type_url,
      );
    } // end if node_access
  } // end 'foreach'

  // Remove "Tasks" and "Index" from Admin Menu output
  $admin_menu_exclusions = array(
    t('Tasks'),
    t('Index'),
  );

  foreach($content['menu'] as $menu_key => $menu_tree) {
    if (in_array($menu_tree['#title'], $admin_menu_exclusions))
      unset($content['menu'][$menu_key]);
    }
} // end hook_admin_menu_output_alter

これらのちょっとした調整の後、私が気に入っている admin menu が表示されます。toolbar は無効にできます。