Drupal 8 Vocab Lesson
-
Upload
mediacurrent -
Category
Technology
-
view
1.943 -
download
2
description
Transcript of Drupal 8 Vocab Lesson
Drupal 8 vocab lessonMediacurrent Team Knowledge ShareDerek DeRaps2013-07-30
Agenda
● YAML
● Composer
● PSR-0
● Dependency Injection
● Service Containers
● Routing
define:
“yammel”
YAML
● “Yet Another Markup Language”
● “YAML Ain't Markup Language”
● Used to define .info files and other configuration
● Hands-on:
○ Let’s create a .info file for our error_notifier module
define:
Composer
Composer
● “Composer is a tool for dependency management in PHP. It allows you to
declare the dependent libraries your project needs and it will install them in your project for you.”
● In Drupal-speak: Does the work formerly handled by the Libraries
module (and much more).
● Important links:
○ https://getcomposer.org/installer○ http://packagist.org
● Hands-on:
○ Let’s add the Swiftmailer library to our project.
define:
PSR-0
PSR-0
● A standard for autoloading classes.
● No more includes() and requires() (for the most part).
● Classes’ namespaces correspond to their location on disk.
○ Your classes’ namespaces always start with Drupal\your_module\○ On disk, that looks like○ docroot/modules/custom/your_module/lib/Drupal/your_module/Your
Class.php
● Class names correspond to filename
○ class MyClass { … } resides in MyClass.php
● Hands-on
○ Let’s declare a namespace and use other classes in our demo.
define:
Dependency Injection
Dependency Injection● “Declaratively express dependencies in the class definition rather than
instantiating them in the class itself.”
● E.g., pass a TransportInterface to the Mailer class; it doesn't need to
know whether it’s using SMTP, Sendmail, etc.
● “The less your code knows, the more reusable it is.”
○ (Sometimes, being ignorant is a good thing.)
● DI aims to help make our code:
○ Clutter-free, Reusable, Testable
● Awesome DrupalCon session by Kat Bailey:
● https://portland2013.drupal.org/session/dependency-injection-drupal-8
define:
Service Containers
Service Containers
● Service
○ any PHP object that performs some sort of "global" task
● Service Container (aka dependency injection container)
○ a PHP object that manages the instantiation of services (i.e. objects).
● Examples:
○ EventSubscriber (“listens” for events … “Observer” OO pattern)
● Hands-on:
○ Let’s create an EventSubscriber service to send mail on 404 errors.
○ This might replace logic in (D7) hook_page_delivery_callback_alter
define:
Routing
Routing
● Think: hook_menu (which is still available FYI).
● Hands-on
○ Let’s declare a route and then implement its Controller.
Thank You!
Questions