Drupal 8 Vocab Lesson

15
Drupal 8 vocab lesson Mediacurrent Team Knowledge Share Derek DeRaps 2013-07-30

description

When you're getting to know (and love?) Drupal 8, you might hear a lot of words that you pretend to understand. It's OK, just check in here for the down-low on those headscratchers. This lesson in Drupal 8 vocabulary covers these fun phrases... - YAML - Composer - PSR-0 - Dependency Injection - Service Containers - Routing

Transcript of Drupal 8 Vocab Lesson

Page 1: Drupal 8 Vocab Lesson

Drupal 8 vocab lessonMediacurrent Team Knowledge ShareDerek DeRaps2013-07-30

Page 2: Drupal 8 Vocab Lesson

Agenda

● YAML

● Composer

● PSR-0

● Dependency Injection

● Service Containers

● Routing

Page 3: Drupal 8 Vocab Lesson

define:

“yammel”

Page 4: Drupal 8 Vocab Lesson

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

Page 5: Drupal 8 Vocab Lesson

define:

Composer

Page 6: Drupal 8 Vocab Lesson

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.

Page 7: Drupal 8 Vocab Lesson

define:

PSR-0

Page 8: Drupal 8 Vocab Lesson

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.

Page 9: Drupal 8 Vocab Lesson

define:

Dependency Injection

Page 10: Drupal 8 Vocab Lesson

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

Page 11: Drupal 8 Vocab Lesson

define:

Service Containers

Page 12: Drupal 8 Vocab Lesson

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

Page 13: Drupal 8 Vocab Lesson

define:

Routing

Page 14: Drupal 8 Vocab Lesson

Routing

● Think: hook_menu (which is still available FYI).

● Hands-on

○ Let’s declare a route and then implement its Controller.

Page 15: Drupal 8 Vocab Lesson

Thank You!

Questions