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小节:

评论 (写第一个评论)