agentleFS
edutruledutrul/drupal-ai/.claude/skills/drupal-menus/SKILL.md

drupal-menus

Skill71 starsChanged 7 months agoMITView on GitHub

Drupal menus — links.menu.yml, links.task.yml, links.action.yml, contextual links, and programmatic menu manipulation.

The file

Files
SKILL.md

Drupal Menus

Menu Links (*.links.menu.yml)

# my_module.links.menu.yml

my_module.admin:
  title: 'My Module'
  description: 'Configure My Module.'
  route_name: my_module.admin
  parent: system.admin_config
  weight: 10

my_module.admin.settings:
  title: 'Settings'
  route_name: my_module.admin.settings
  parent: my_module.admin
  weight: 0

Task Links / Tabs (*.links.task.yml)

# my_module.links.task.yml

my_module.settings_tab:
  title: 'Settings'
  route_name: my_module.admin.settings
  base_route: my_module.admin

my_module.advanced_tab:
  title: 'Advanced'
  route_name: my_module.admin.advanced
  base_route: my_module.admin
  weight: 10

Action Links (*.links.action.yml)

# my_module.links.action.yml

my_module.add_item:
  title: 'Add Item'
  route_name: my_module.add
  appears_on:
    - my_module.list

Programmatic Menu Tree

use Drupal\Core\Menu\MenuTreeParameters;

$menu_tree = \Drupal::menuTree();
$parameters = new MenuTreeParameters();
$parameters->setMaxDepth(2)->onlyEnabledLinks();

$tree = $menu_tree->load('main', $parameters);
$manipulators = [
  ['callable' => 'menu.default_tree_manipulators:checkAccess'],
  ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
];
$tree = $menu_tree->transform($tree, $manipulators);
$build = $menu_tree->build($tree);

Altering Menu Links

#[Hook('menu_links_discovered_alter')]
public function menuLinksDiscoveredAlter(array &$links): void {
  if (isset($links['my_module.some_link'])) {
    $links['my_module.some_link']['title'] = new TranslatableMarkup('New Title');
  }
}

Dynamic Menu Links (MenuLinkDefault plugin)

// src/Plugin/Menu/MyDynamicMenuLink.php
use Drupal\Core\Menu\MenuLinkDefault;

final class MyDynamicMenuLink extends MenuLinkDefault {
  public function getTitle(): string {
    return 'Dynamic Title from ' . $this->getRouteName();
  }
}

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.