drupal at your service
play

Drupal at your service! By Mauro Vigliotti About me Mauro - PowerPoint PPT Presentation

Drupal at your service! By Mauro Vigliotti About me Mauro Vigliotti Im from Argentina (South America) Drupal developer since 2005 Working for The Brick Factory Developer by day rocker by night 2018


  1. Drupal… at your service! By Mauro Vigliotti

  2. About me Mauro Vigliotti ● I’m from Argentina (South America) ● Drupal developer since 2005 Working for The Brick Factory ● ● Developer by day… ● … rocker by night ● 2018 DrupalCon Official guitar winner! 2

  3. About The Brick Factory The Brick Factory is a Washington, DC-based digital agency that plans and executes digital campaigns for nonprofits, trade associations, advocacy groups and brands - Digital Strategy - Digital Marketing - Design - Development - Hosting and Systems - Products 3

  4. Get ready to learn about one of Drupal 8’s greatest new features! 4

  5. What’s a Service The Service Container Service Definition Tags Overview Accessing a Service Samples: Page redirection ● Controlling user sessions ● Overriding an existing service ● Adding service using DI ● 5

  6. A good approach to D8 Services Sample code to start producing What will you get your own services, it’s so easy! from this talk? Understanding about Service Container, controller classes and the new Symfony approach on Drupal Core 6

  7. Go deeply into Symfony Provide *all* the services that are This talk is not available within the Drupal core intended to: Solve *all* your Drupal 8 problems Talk about REST (in Drupal 7, Services’ meaning is different) 7

  8. Important note! Why do I say this talk is targeted to beginners? 8

  9. Target: Drupal < 8 developers The learning curve for most of the developers we’ve been working on previous Drupal versions before can be hard, mostly because the CMS had a hook-based approach, and now is moving to an Object-Oriented Paradigm. 9

  10. Target: Drupal freshmen. If you’re brand new on Drupal, finding out there’s so many things to learn could be the first blocker, whether if you’re a content manager, a designer, a front-end or back-end developer. 10

  11. Let’s go! 11

  12. What’s a Drupal 8 Service? Let’s throw the mystery away, a Service is a PHP Class (or a bunch of classes, depending on your implementation). Decoupled reusable functionality ● ● Plugged to your Drupal 8 at any time ● Introduced in Drupal by Symfony. 12

  13. What’s a Drupal 8 Service? 13

  14. Drupal Services Out-of-the-box ● More than 100 services available. Sample services: ● ○ Accessing the current logged in user ○ Sending an email ○ Asking for a page redirection ○ Altering a http response ○ Performing a database query ○ Translating a piece of text ● Full core services list here: https://api.drupal.org/api/drupal/core%21core.services.yml/8.2.x ...or opening the core/core.services.yml file. 14

  15. The Service Container (a.k.a. Dependency Injection Container) Dependency Injection Container Service A Service X Service C.01 Service B Service C Service C 15

  16. Service definition YAML file in root of our custom module 16

  17. Service definition Service definition format Service name user.current_user_context: class: Drupal\user\ContextProvider\CurrentUserContext Designated class arguments: ['@current_user', '@entity.manager'] Arguments tags: Tags - { name: 'context_provider' } https://www.drupal.org/docs/8/api/services-and-dependency-injection/structure-of-a-service-file 17

  18. Tags ● Define a group of related services ● Some sample tag names: (remember the card deck concept) ○ access_check ○ cache.bin ● Tag properties ○ context_provider ○ event_subscriber ○ name ○ theme_negotiator ○ priority ○ global ○ alias, and many others https://www.drupal.org/docs/8/api/services-and-dependency-injection/structure-of-a-service-file 18

  19. Accessing a Service 19

  20. Accessing a Service: YAML Service file user.current_user_context: class: Drupal\user\ContextProvider\CurrentUserContext arguments: ['@current_user', '@entity.manager'] tags: - { name: 'context_provider' } 20

  21. Accessing a Service: $container object // EntityViewBuilder.php public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { return new static ( $entity_type, $container->get('entity.manager'), $container->get('language_manager'), $container->get('theme.registry') ); } 21

  22. Accessing a Service everywhere: Global \Drupal class $foobar = \Drupal::service('foo.bar'); 22

  23. Okay… enough talking… Show me the code! 23

  24. Page redirection ● Controlling user sessions ● Sample Code Overriding an existing service ● Adding service using DI ● 24

  25. Questions? 25

  26. Thank you! Get in touch if you have any questions ● Drupal.org: https://www.drupal.org/u/mauro_ptt Presentation and code ready to download at: ● Presentation: https://goo.gl/Vr8DTK ● Sample code: https://github.com/maurotbf/d8services 26

  27. 2018 The Brick Factory 27

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend