SlideShare a Scribd company logo
Drupal 8: Routing & moreDrupal 8: Routing & more
Routing, Controllers, Menu Items, Access ControlRouting, Controllers, Menu Items, Access Control
Drupal Meetup StuttgartDrupal Meetup Stuttgart
04/02/2015
1. Once upon a time,1. Once upon a time,
in Drupal 7...in Drupal 7...
function forum_menu() {
...
$items['admin/structure/forum/add/container'] = array(
'title' => 'Add container',
'page callback' => 'forum_form_main',
'page arguments' => array('container'),
'access arguments' => array('administer forums'),
'type' => MENU_LOCAL_ACTION,
'parent' => 'admin/structure/forum',
'file' => 'forum.admin.inc',
);
...
}
Example from D7 (forum.module)
function forum_menu() {
...
$items['admin/structure/forum/add/container'] = array(
'title' => 'Add container',
'page callback' => 'forum_form_main',
'page arguments' => array('container'),
'access arguments' => array('administer forums'),
'type' => MENU_LOCAL_ACTION,
'parent' => 'admin/structure/forum',
'file' => 'forum.admin.inc',
);
...
}
Nice, but...
Routing +
access control +
menu item +
...
Separation of concerns?
2. D8: Routing &2. D8: Routing &
ControllersControllers
~ path / url ~ callback
...
forum.add_container:
path: '/admin/structure/forum/add/container'
defaults:
_controller: 'DrupalforumControllerForumController::addContainer'
_title: 'Add container'
requirements:
_permission: 'administer forums'
...
forum.routing.yml
namespace DrupalforumController;
use ...
class ForumController extends ControllerBase {
...
/**
* Returns add container entity form.
*
* @return array
* Render array for the add form.
*/
public function addContainer() {
$vid = $this->config('forum.settings')->get('vocabulary');
$taxonomy_term = $this->termStorage->create(array(
'vid' => $vid,
'forum_container' => 1,
));
return $this->entityFormBuilder()->getForm($taxonomy_term, 'container');
}
...
}
ForumController.php
/admin/structure/forum/add/container
3. D8: Menu items3. D8: Menu items
Drupal 8: Routing & More
forum.index:
title: Forums
route_name: forum.index
menu_name: tools
forum.overview:
title: Forums
parent: system.admin_structure
description: 'Control forum hierarchy settings.'
route_name: forum.overview
Example: forum.links.menu.yml
forum.overview:
route_name: forum.overview
base_route: forum.overview
title: List
forum.settings:
route_name: forum.settings
base_route: forum.overview
title: Settings
weight: 100
Example: forum.links.task.yml
/admin/structure/forum
4. D8: access control4. D8: access control
function forum_permission() {
$perms = array(
'administer forums' => array(
'title' => t('Administer forums'),
),
);
return $perms;
}
administer forums:
title: 'Administer forums'
Drupal 7: hook_permission()
Drupal 8: forum.permission.yml
function forum_menu() {
...
'access callback' => 'user_access',
'access arguments' => array('administer forums'),
...
}
...
requirements:
_permission: 'administer forums'
...
Drupal 7: hook_menu()
Drupal 8: forum.routing.yml
...
requirements:
_permission: 'access content'
...
requirements:
_user_is_logged_in: 'TRUE'
...
requirements:
_role: 'administrator'
...
requirements:
_entity_access: 'node.view'
...
There's even more...
Thank You!Thank You!
http://slides.com/drubb
http://slideshare.net/drubb

More Related Content

PDF
Drupal 8 Sample Module
PDF
Drupal 8: Forms
PDF
Drupal 8: Entities
PDF
Drupal 8: Theming
PDF
The Origin of Lithium
PDF
Dependency injection in PHP 5.3/5.4
PDF
jQuery secrets
PDF
Dependency injection-zendcon-2010
Drupal 8 Sample Module
Drupal 8: Forms
Drupal 8: Entities
Drupal 8: Theming
The Origin of Lithium
Dependency injection in PHP 5.3/5.4
jQuery secrets
Dependency injection-zendcon-2010

What's hot (20)

PDF
Unit and Functional Testing with Symfony2
PDF
Building Lithium Apps
PDF
The State of Lithium
PDF
Lithium: The Framework for People Who Hate Frameworks
PPTX
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
PDF
What's New in Drupal 8: Entity Field API
KEY
Lithium Best
PDF
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
PDF
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
PDF
Php unit the-mostunknownparts
PPTX
PDF
Dependency Injection with PHP and PHP 5.3
PDF
The Beauty and the Beast
PDF
The Zen of Lithium
PPTX
Ch8(oop)
PDF
Doctrine 2
PDF
Symfony2 - OSIDays 2010
PDF
Design Patterns in PHP5
PDF
Your Entity, Your Code
PDF
Entities in drupal 7
Unit and Functional Testing with Symfony2
Building Lithium Apps
The State of Lithium
Lithium: The Framework for People Who Hate Frameworks
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
What's New in Drupal 8: Entity Field API
Lithium Best
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Php unit the-mostunknownparts
Dependency Injection with PHP and PHP 5.3
The Beauty and the Beast
The Zen of Lithium
Ch8(oop)
Doctrine 2
Symfony2 - OSIDays 2010
Design Patterns in PHP5
Your Entity, Your Code
Entities in drupal 7
Ad

Similar to Drupal 8: Routing & More (12)

PDF
[Srijan Wednesday Webinars] Routing in Drupal 8: Decoupling hook_menu
PPTX
Goodbye hook_menu() - Routing and Menus in Drupal 8
PDF
[Srijan Wednesday Webinars] Let’s Take the Best Route - Exploring Drupal 8 Ro...
PPTX
Routing in Drupal 8
PPT
DRUPAL Menu System
PPT
Drupal Menu System
PDF
The Flexibility of Drupal
ODP
Custom module and theme development in Drupal7
PDF
2007 Fsoss Drupal Under The Hood
PDF
A deep dive into Drupal 8 routing
PPT
Introduction of drupal7 by ayushi infotech
PPTX
Routing in Drupal 8
[Srijan Wednesday Webinars] Routing in Drupal 8: Decoupling hook_menu
Goodbye hook_menu() - Routing and Menus in Drupal 8
[Srijan Wednesday Webinars] Let’s Take the Best Route - Exploring Drupal 8 Ro...
Routing in Drupal 8
DRUPAL Menu System
Drupal Menu System
The Flexibility of Drupal
Custom module and theme development in Drupal7
2007 Fsoss Drupal Under The Hood
A deep dive into Drupal 8 routing
Introduction of drupal7 by ayushi infotech
Routing in Drupal 8
Ad

More from drubb (10)

PDF
Barrierefreie Webseiten
PDF
Drupal 9 Entity Bundle Classes
PDF
Drupal 8 Dependency Injection Using Traits
PDF
Closing the Drupal Hosting Gap - A Review of Wodby
PDF
Composer & Drupal
PDF
Headless Drupal
PDF
Spamschutzverfahren für Drupal
PDF
Drupal 8: TWIG Template Engine
PDF
Drupal 8: Neuerungen im Überblick
PDF
Drupal Entities
Barrierefreie Webseiten
Drupal 9 Entity Bundle Classes
Drupal 8 Dependency Injection Using Traits
Closing the Drupal Hosting Gap - A Review of Wodby
Composer & Drupal
Headless Drupal
Spamschutzverfahren für Drupal
Drupal 8: TWIG Template Engine
Drupal 8: Neuerungen im Überblick
Drupal Entities

Recently uploaded (20)

PPTX
presentation_pfe-universite-molay-seltan.pptx
PDF
Sims 4 Historia para lo sims 4 para jugar
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PDF
Paper PDF World Game (s) Great Redesign.pdf
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PPTX
Funds Management Learning Material for Beg
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PPTX
Internet___Basics___Styled_ presentation
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
presentation_pfe-universite-molay-seltan.pptx
Sims 4 Historia para lo sims 4 para jugar
Cloud-Scale Log Monitoring _ Datadog.pdf
WebRTC in SignalWire - troubleshooting media negotiation
Unit-1 introduction to cyber security discuss about how to secure a system
Module 1 - Cyber Law and Ethics 101.pptx
Introuction about WHO-FIC in ICD-10.pptx
Paper PDF World Game (s) Great Redesign.pdf
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Funds Management Learning Material for Beg
Slides PPTX World Game (s) Eco Economic Epochs.pptx
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
RPKI Status Update, presented by Makito Lay at IDNOG 10
The New Creative Director: How AI Tools for Social Media Content Creation Are...
Internet___Basics___Styled_ presentation
Slides PDF The World Game (s) Eco Economic Epochs.pdf
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
SASE Traffic Flow - ZTNA Connector-1.pdf
Introuction about ICD -10 and ICD-11 PPT.pptx

Drupal 8: Routing & More