Mediacurrent Knowledge Share
4 . 14 . 2015
with your host, Derek DeRaps!
#DCFL
+
D8 Training
#DCFL
+
D8 Training
Take-aways: Drupal theming sucks (hear Zack cheer). Use REST to deliver data to the front-end. Writing actual HTML markup > template preprocessors and all that junk.
I like the idea of presentations on stuff like this that represents a big part of our day. Cue Alex for recap.
I only saw the first half of this two-session presentation. It was great. Adam Hoenich (phenaproxima) is a mad scientist/genius, and he worked with Angie to write the Module Upgrader.
Brought to you by yours truly and the traitorous but still brilliant Kendall Totten.
Did not see it, but just plugging as a potential path for our Vagrant project. Kalabox 2.0 already uses Docker, just saying.
A pretty tasty session.
Simpletest dies. Rise of the PHP Unit. But Behat?? This is going to be tough.
A plug for our overlords to watch.
Presented by the usual suspects.
Code Sprint
Migrate in Core (Mike Anello is a facilitator for the initiative). Matt Davis worked with Doug Green, Adam, and Mike to fix a migration script. Had signoff by Chx before the end of the day. I stacktraced some issues in Benjy's iFrame Migrate Example module.
#DCFL
+
D8 Training
The Setting.
Routes,
Controllers, Services,OhMy!
The Setting.
Routes,
Controllers, Services,OhMy!
Strongbox West
Swanky co-working digs on the up-and-coming Atlanta Westside.
Ryan Weaver
Symfony Core Team Member. US Office Head & Trainer for KnpLabs, Co-author of the Symfony2 documentation and "More with Symfony." Brilliant instructor.
Ormsby's
After-party with good food and beers. Was great to see folks I’ve never met before. I lost pool four times to Matt Davis and then we “lost” once to Dave and Paul.
The Setting.
Routes,
Controllers, Services,OhMy!
What is a route?
A yaml version of hook_menu().
What is a Controller?
A page callback.
What do Controllers do?
Same thing as page callbacks. They perform some fancy logic (invented by you) and return markup, render arrays, etc.*
What do Controllers do?
They translate and sanitize text, create links, log messages, query the database, etc. They depend on the services provided by functions such as: t(), l(), watchdog(), db_*(), etc.
Ruhroh
"But," you say, "most of those old functional programming methods are gone! What are we to do?"
The services they provided to us (translation, sanitization, link handling, logging etc.) are replaced with objects whose methods do the same thing.
TIMEOUT
OO Lesson 101
Two types of classes:
Actions vs. Data
(Services vs. Entities)
Time In
The Setting.
Routes,
Controllers,
Services,OhMy!
So what exactly is a "service"?
It’s a useful object. Collections of related methods to accomplish tasks that we all use a regular basis.
How do we use a Service?
So far, we know that our controllers depend on these new things called Services… how do we go about using them?
Enter: The Service Container
We reach into a big bag of all the available Services (aka the Service Container) and select it by name.
The Service Container is just collection of the useful objects we need to do our job.
Setting up the scene.
In the Controller’s create() method, we accept the Service Container as an argument. We use it to grab all the services we will need later on (in the actual page callback) and assign to class variables for later use.
Dependency Injection
Guess what you just did: You took your Controller and injected some of Services (useful objects) that it depends on. Dependency Injection isn’t so scary!
Question
Why go through the hassle of injecting?
Why not just query the Services Container directly in our Controller's page callback when it’s time to use a given Service?
DI in D7
$conf['mail_system'] = array('default-system' => 'DevelMailLog');
$conf['cache_default_class'] = 'MemCacheDrupal';
The Setting.
Routes,
Controllers,
Services,OhMy!
Drupal App Console
The Drupal Console is a suite of tools that you run on a command line interface (CLI) to generate boilerplate code and interact with a Drupal 8 installation.
drupal list
- drupal generate:module
- drupal generate:block
- drupal container:debug
- drupal cache:rebuild
- drupal router:rebuild
Composer
composer install vs.
composer update
You can update just a single project instead of the whole project.
E.g., composer update symfony/symfony
To add a project easily: composer require guzzlehttp/guzzle
~2.6.2 vs. 2.6.*
Namespaces and Autoloading
Makes our life easier, and adds more magic into IDEs like PHPStorm.
Demo!
Twig
PHPStorm
Profiler
Questions?
deck
By Hawkeye Tenderwolf
deck
- 1,197