SlideShare a Scribd company logo
Services Drupal 8
Yuriy Gerasimov
Senior Drupal Architect
Propeople
@ygerasimov
Routing
Drupal 7 routing
● based on path only (menu_get_item($path))
● tied up with menu links (tables menu_router,
menu_links)
menu_rebuild()
● This function will clear and populate the
{menu_router} table, add entries to {menu_links}
for new router items, and then remove stale
items from {menu_links}. If called from
update.php or install.php, it will also schedule a
call to itself on the first real page load from
menu_execute_active_handler(), because the
maintenance page environment is different and
leaves stale data in the menu tables.
Drupal 7 routing
● hook_menu()
Drupal 7 routing
● hook_menu_alter()
Drupal 8 routing
Drupal 8 routing
● mymodule.routing.yml
●
●
●
{router} database table, route_set =
<modulename>
Dynamic routes
● Subscriber reacting on
RoutingEvents::DYNAMIC event
●
●
●
●
●
●
{router} table, route_set = dynamic_routes
Drupal 8 meets Symfony routing
● RouterListener subscriber (core.services.yml)
● RouterListener::onKernelRequest() sets
attributes to request object using matcher
Routing
● RouterListener::onKernelRequest()
Routing ChainRouter
router.dynamic internals
● RouteProvider – fetch all records from {router}
table filtering by pattern_outline,
● NestedMatcher:
– MimeTypeMatcher
– UrlMatcher:
● prefix
● regex (example #^/node$#s)
● host regex
● http method
● http scheme (http or https)
legacy_router internals
● NullGenerator
● LegacyUrlMatcher
– menu_get_item($path)
– Convert it to Route
● _controller is callback function name
● hook_menu 'file' got included
Routing Recap
Drupal7
● Path only
● Tied with menu links
Drupal 8
● Heavily used
Symfony
● Path
● Mime type
● Http method
● (and more)
REST in core
● New Entity API with field metadata
● REST API support can be enabled for any
entity known to the system
● Access control on the entity level
● Access control on the field level
Modules
● Serialization
● REST
● HAL
Retrieve a node (decoded)
Resource plugin
● DrupalmodulenamePluginrestresource
● Annotation with id and description
● Each http method as class method (get, post,
delete, patch ...)
Resource plugin
Serialization
Normalizers
● ImageItemNormalizer
● EntityReferenceNormalizer
● FieldItemNormalizer
● FieldNormalizer
● EntityNormalizer
Serialization
CSRF protection
● Each non-safe REST call (not GET, HEAD,
OPTIONS, TRACE methods) should be done
with 'X-CSRF-Token' header with token.
● Drupal 7 Services got SA on 6 June 13.
Services in Drupal 8 (plans)
● Own plugin (extends Resource from REST)
● Each method as own route (not tied with http
method names)
● Use annotations to describe your routes
● Validation of arguments
Services example
Authentication (in progress)
● https://drupal.org/node/1890878
● No more dependent on Cookie Session
● Authentication Providers
● Multiple authentication providers – 400 Bad
Request
● Access check if authenticaion provider allowed
Welcome to Contribute!
Guzzle. Service Description
Guzzle. Client
● Descriptions make life easier
Services Guzzle module
● Module for Drupal 7
● Includes client for testing (similar to what
services 6.x-2.x had)
Thanks
● Larry Garfield @Crell
● Lin Clark @linclark
● Klaus Purer @_klausi_
● WSCCI team
Links
● https://groups.drupal.org/wscci
● https://portland2013.drupal.org/session/rest-
and-serialization-drupal-8
● http://guzzlephp.org/
Services Drupal 8
Yuriy Gerasimov
Senior Drupal Architect
Propeople
@ygerasimov

More Related Content

Drupal 8 Routing