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

评论 (写第一个评论)