function trousers_menu() {
$items['trousers'] = array(
'title' => 'Trousers',
'page callback' => 'trousers_page',
'access arguments' => 'view trousers',
'type' => MENU_CALLBACK,
);
}
trousers_list:
pattern: '/trousers'
defaults:
_content: '\Drupal\trousers\Controller\TrouserController::list'
requirements:
_permission: 'view trousers'
<?php
function trousers_page() { return t('List of trousers'); }
8.x
class TrouserController extends ControllerBase {
public function list(Request $request) {
return $this->t('List of trousers');
}
}
class UserPasswordForm extends FormBase { /** * {@inheritdoc} */ public function getFormID() { return 'user_pass'; }
public function buildForm(array $form, array &$form_state) { $form['name'] = $this->t('Use $this->t()'); return $form;
} public function validateForm(array &$form, array &$form_state) { // Validate stuff. } public function submitForm(array &$form, array &$form_state) { // Save stuff. } }
system_site_information_settings:
pattern: '/admin/config/system/site-information'
defaults:
_form: 'Drupal\system\Form\SiteInformationForm'
requirements:
_permission: 'administer site configuration'
paramconverter_test_node_set_parent:
pattern: '/paramconverter_test/node/{node}/set/parent/{parent}'
requirements:
_access: 'TRUE'
defaults:
_content: '\Drupal\paramconverter_test\TestControllers::testNodeSetParent'
options:
parameters:
parent:
type: 'entity:node'
paramconverter.awesome:
class: Drupal\mymodule\AwesomeConverter
tags:
- { name: paramconverter }
class EntityConverter implements ParamConverterInterface { public function convert($value, $definition, $name, array $defaults, Request $request) {
// Convert $value and return it. } public function applies($definition, $name, Route $route) { // Return TRUE if you want to upcast something for that route. }
edit_entity_save:
pattern: '/edit/entity/{entity_type}/{entity}'
defaults:
_controller: '\Drupal\edit\EditController::entitySave'
options:
_access_mode: 'ALL'
requirements:
_permission: 'access in-place editing'
_access_edit_entity: 'TRUE'
_permission: 'my permission name'
Check if a user has a role
_role: 'role1+role2' (AND)
_role: 'role1, role2' (OR)
Check if user is logged in
_user_is_logged_in: 'TRUE'
_access: 'TRUE'
We'll get to entities...
access_check.aggregator.categories:
class: Drupal\aggregator\Access\CategoriesAccessCheck
arguments: ['@database']
tags:
- { name: access_check }
class CategoriesAccessCheck implements StaticAccessCheckInterface {
public function appliesTo() {
return array('_access_aggregator_categories');
}
public function access(Route $route, Request $request) {
// Implement access logic here
}
Simple structure: link path, title, description, parent
Until that issue is committed: keep hook_menu()
function node_default_menu_links() { $links['admin.content'] = array( 'link_title' => 'Content', 'link_path' => 'admin/content', 'parent' => 'admin', 'description' => 'Find and manage content.', );
$links['admin.structure.types'] = array( 'link_title' => 'Content types', 'parent' => 'admin.structure', 'description' => 'Manage content types,...', 'route_name' => 'node_overview_types', ); $links['node.add'] = array( 'link_title' => 'Add content', 'link_path' => 'node/add', ); return $links; }
custom_block_type_add:
route_name: custom_block_type_add
title: 'Add custom block type'
appears_on:
- custom_block_type_list
custom_block_add_action:
route_name: custom_block_add_page
title: 'Add custom block'
appears_on:
- block_admin_display
views_ui_settings_tab:
route_name: views_ui.settings.basic
title: Settings
tab_root_id: views_ui_list_tab
views_ui_settings_basic_tab:
route_name: views_ui.settings.basic
title: Basic
tab_root_id: views_ui_list_tab
tab_parent_id: views_ui_settings_tab
views_ui_settings_advanced_tab:
route_name: views_ui.settings.advanced
title: Advanced
tab_root_id: views_ui_list_tab
tab_parent_id: views_ui_settings_tab
weight: 10
block_admin_add:
pattern: '/admin/structure/block/add/{plugin_id}/{theme}'
defaults:
_content: '\Drupal\block\Controller\BlockAddController::blockAddConfigureForm'
_title: 'Configure block'
requirements:
_permission: 'administer blocks'
class Test { /** * Renders a page with a title. */ public function renderTitle() { $build = array(); $build['#markup'] = 'Hello Drupal'; $build['#title'] = 'Foo: ' . \Drupal::config()->get('system.site')->get('name'); return $build; }
}
taxonomy_term_edit:
pattern: '/taxonomy/term/{taxonomy_term}/edit'
defaults:
_entity_form: 'taxonomy_term.default'
requirements:
_entity_access: 'taxonomy_term.update'
taxonomy_term_add:
pattern: '/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/add'
defaults:
_content: '\Drupal\taxonomy\Controller\TaxonomyController::addForm'
requirements:
_entity_create_access: 'taxonomy_term:{taxonomy_vocabulary}'
* "list" = "Drupal\tmgmt\Entity\Controller\TranslatorListController",
tmgmt_translator_list:
pattern: '/admin/config/regional/tmgmt_translator'
defaults:
_entity_list: 'tmgmt_translator'
requirements:
_permission: 'administer tmgmt'
entity_test_render_no_view_mode: pattern: '/entity-test-render-no-view-mode/{entity_test_render}' defaults: _entity_view: 'entity_test_render'
entity_test_render: pattern: '/entity-test-render/{entity_test_render}' defaults: _entity_view: 'entity_test_render.full'
* controllers = {
* "storage" = "Drupal\entity_test\EntityTestStorageController",
* "render" = "Drupal\entity_test\EntityTestRenderController"
* },
tmgmt_translator_add: pattern: '/admin/config/regional/tmgmt_translator/add' defaults: _entity_form: tmgmt_translator.add
tmmgt_translator_entity:
pattern: '/admin/config/regional/tmgmt_translator/manage/{tmgmt_translator}'
defaults:
_entity_form: tmgmt_translator.edit