6.7 菜单说明

1龲links.menu.yml

龜龙龗hello_world.links.menu.yml龄

龀齾齽齼齹齷齴齰齯齫齨齥齡齝齚hello_world.links.menu.yml齼齗齓齯齐齍齊齇齰齅齄:

 hello_world.admin:
   title: 'Hello module settings'
   description: 'example of how to make an admin settings page link'
   parent: system.admin_config_development
   route_name: hello_world.content
   weight: 100
  • route_name: 龀routing.yml鼣鼠鼜齼鼙鼘齝鼕
  • parent: 鼔鼑齼鼐鼎鼌齼鼊鼈鼇鼎鼌龄鼃齡鼎鼌鼈鼇鼂鼁龀admin>config>development齰齫齨龄

黽黹黷黴齯黳齥齰黯黭龄

2龲links.action.yml

龀齾齽齼齹齷齴齰齯齫齨齥齡齝齚hello_world.links.action.yml齼齗齓齯齐齍齊齥齰齼齅齄:

hello_world.link_add:
  route_name: hello_world.content.add
  title: 'Add hello world'
  appears_on:
    - hello_world.hello_world
  • appears_on: 龀黣齡鼙鼘黟黝

黛默黕黑齇鼠鼜黎黋齼鼎鼌齯黊齰黈

hello_world.content.action:
  route_name: hello_world.content
  title: 'Example dynamic title action'
  weight: -20
  class: '\Drupal\hello_world\Plugin\Menu\LocalAction\CustomLocalAction'
  appears_on:
    - hello_world.content

麴麰黊齰黈

/**
 * @file
 * Contains \Drupal\hello_world\Plugin\Menu\LocalAction\CustomLocalAction.
 */

namespace Drupal\hello_world\Plugin\Menu\LocalAction;

use Drupal\Core\Menu\LocalActionDefault;

/**
 * Defines a local action plugin with a dynamic title.
 */
class CustomLocalAction extends LocalActionDefault {

  /**
   * {@inheritdoc}
   */
  public function getTitle() {
    return $this->t('My @arg action', array('@arg' => 'dynamic-title'));
  }

}

3龲links.task.yml

麆龜鼐鼠鼜tab麂麀齼鼎鼌齯黊黈

example.admin: # The first plugin ID
  title: 'Settings'
  route_name: example.admin
  base_route: example.admin

example.admin_3rd_party: # The second plugin ID
  title: 'Third party services'
  route_name: example.admin_3rd_party
  base_route: example.admin

鼃鹴鼠鼜鹳鹱齡鼎鼌齯admin鹯admin_3rd_party齯齐鹫鹧鹥黟黝admin龄

黛默黕黑齇黎黋鼠鼜黈

example.local_tasks:
  deriver: 'Drupal\example\Plugin\Derivative\DynamicLocalTasks'
  weight: 100
/**
 * @file
 * Contains \Drupal\example\Plugin\Derivative\DynamicLocalTasks.
 */

namespace Drupal\example\Plugin\Derivative;

use Drupal\Component\Plugin\Derivative\DeriverBase;

/**
 * Defines dynamic local tasks.
 */
class DynamicLocalTasks extends DeriverBase {

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    // Implement dynamic logic to provide values for the same keys as in example.links.task.yml.
    $this->derivatives['example.task_id'] = $base_plugin_definition;
    $this->derivatives['example.task_id']['title'] = "I'm a tab";
    $this->derivatives['example.task_id']['route_name'] = 'example.route';
    return $this->derivatives;
  }

}

本书共79小节:

评论 (写第一个评论)