Drupal 8 : Entreprise Applications Framework

Posted by admin on

What's new and cool with Drupal 8
PSR-4
Cache tags
Event Dispatcher
Creating new event
Dispatch event
Declare new subscriber in module.services.yml file.
Create subscriber class
Dependency Injection
Declare your service
Create service class
Load your class from  services container
HTML 5
Responsive images
REST API is built-in
Headless drupal ?
Manifesto
Sample
Demo
Twig how it will work and how it will be different from now. Does slicing changes a lot ? How we should change the process ?
Twig filters and functions
No PHP in templates
Loops
Extend base templates
slicing
Breakpoints and Responsive images
Content staging
Configuration management, impacts on deploy procedures
Anything else about D8 you've found cool / painfull / new... (be as concrete as possible).
When it will be realeased?

What's new and cool with Drupal 8 
PSR-4 
(Olaresko Dmytro)

Drupal 8 uses PSR-4 class autoloading standard (in D7 we had PSR-0)
was (module views, file views.info):
http://paste.adyax.com/351b2
We needed to inform Drupal about all classes we have and where they are placed.
now (no extra file with description used, views module from the core):
http://paste.adyax.com/6991f
It just shows file structure where each class placed. Example for our custom module: http://i.imgur.com/vX7tkGC.png

Cache tags 
(Olaresko Dmytro)

Cache API has been changed a lot and now it supports tags that brings new level of caching management. For example:
http://paste.adyax.com/7ffbf
We made custom cache that contains array with case studies (title, nid and logo image), but we need to invalidate our custom cache when any case study node is updated, or node with nid=5 updated (lets say, that this node displays the list of all case studies and has extra field where content editor can exclude some case studies for display), or file with id=10 is updated (for example, some background logo that will be used for display). In this case we don`t need to use old hook_node_update / delete / insert and flush our custom cache manually, Drupal will do it for us.

Event Dispatcher 
(Vadim Tokarchuk)

Event Dispatcher is new, flexible and secure module extending system.
Event fires all its subscribers without any dependency.
Code is well structured and devided between Event and Subsctiber classes.

Creating new event
http://paste.adyax.com/2e7a9

Dispatch event
http://paste.adyax.com/5ba96

Declare new subscriber in module.services.yml file. 
Note: param tags.name = event_sunscriber is required
http://paste.adyax.com/6b4ff

Create subscriber class
Method getSubscriberEvents is required and return even_name => [callback1, callback2, ...] typed array: http://paste.adyax.com/2fffc

Dependency Injection
 (Vadim Tokarchuk)

Dependency Injection is a standalone classes dependency resolver.
In Drupal 8 dependency injection is realised through services container.

Declare your service 
(module.services.yml): http://paste.adyax.com/88e03

Create service class
 http://paste.adyax.com/25a85
As you see our service depends on different classes. And each of them can depend on other classes.
But when you pass other services names as arguments thay will be loaded automaticaly.

Load your class from  services container
 http://paste.adyax.com/8df8e

As you see you get fully configured object without passing any arguments.
And Symfony2 DependencyInjection handles all dependencies automaticaly.

HTML 5 
(Olaresko Dmytro)
There are a lot of new HTML 5 tags supported by Drupal8.
Some of them: <details>, <input type="url">, <input type="email">, <input type="tel">
Usage example: http://paste.adyax.com/6fbb6
Full list of new elements can be found here: https://api.drupal.org/api/drupal/namespace/Drupal!Core!Render!Element/8
Responsive images 
(Olaresko Dmytro)
This feature provides possibility to generate modern (responsive friendly HTML like this):
http://paste.adyax.com/56e18
To make it works developer need to add breakpoints information to his theme (<yourtheme>.breakpoints.yml file):
http://paste.adyax.com/60ceb
Then create new responsive image mapping:
http://i.imgur.com/jsAlT69.png
And change content type display settings for needed image field:
http://i.imgur.com/RmHpGxW.png
REST API is built-in 
(Ivan Tsekhmistro)
    RESTfull API is build in Drupal 8. Try it out 
curl -i -H "Accept: application/hal+json" http://d8.local/node/1

See Sample to retrieve content with AngularJS and display on site:
http://paste.adyax.com/0601a&nbsp;

See Headless Drupal.

Headless drupal ? 
(Ivan Tsekhmistro)
@Content as a service. Drupal 8 provides an API approach to content delivery, allowing content to be made available everywhere, including websites, mobile devices, native applications, digital screens, and the Internet of Things.@
Article describing idea https://www.ostraining.com/blog/drupal/what-is-headless-drupal/
Manifesto
@
We want Drupal to be the preferred back-end content management system for designers and front-end developers.
We believe that Drupal's main strengths lie in the power and flexibility of its back-end; its primary value to users is its ability to architect and display complex content models.
We believe that client-side front-end frameworks are the future of the web.
It is critically important for Drupal to be services oriented first, not HTML oriented first, or risk becoming irrelevant.
@

Sample 
of site built with AngualrJS and Headless Drupal http://www.nbc.com/the-tonight-show&nbsp;

Demo
http://dev-headless-drupal-8.gotpantheon.com/headless/angular/index.html

Twig how it will work and how it will be different from now. Does slicing changes a lot ? How we should change the process ? 
(Vadim Tokarchuk)

Twig is very simple and minimalistic template engine.
Twig filters and functions
Twig has a lot of fiters and function out of the box: http://twig.sensiolabs.org/doc/filters/index.html
http://twig.sensiolabs.org/doc/functions/index.html
Also you can easily create your own filters and functions.
Here is how Drupal core does it: http://paste.adyax.com/3be9c

No PHP in templates
In Twig you cannot put any php code. It has his own minimal code syntax.
Using twig your templates become very short and easy to read.
Here is short but clear enough PHP templating vs Twig comparison: https://www.drupal.org/node/1918824

And here is official Twig documentation with all features: http://twig.sensiolabs.org/doc/templates.html
Loops
In Twig “for” construction is very flexible. It can have different conditions and behaviors.
Here you find full documentation of loops in Twig: http://twig.sensiolabs.org/doc/tags/for.html

Extend base templates
Twig templates are well extendable and overridable. 
For example here: http://paste.adyax.com/20ddb you find print of “content” block.
And then if you extend this template in another twig: http://paste.adyax.com/08f0e it will override parent’s “content”

slicing
In Drupal 8 all assets (css and js) are moved to libraries. No more drupal_add_js and drupal_add_css.
Then you attach your libraries to renderable array with “#attached” key wherever you need them.
Each page loads libraries only that are needed. You just define dependency on libraries.
Even jQuery is not loaded by default on all pages.

The goal is to prevent loading unneeded libraries and to improve front-end performance.

Here is how to work with libraries:
Declare your library (module.libraries.yml): http://paste.adyax.com/7e5ed
Note: here you see all dependencies of library.
Attach library to your renderable array: http://paste.adyax.com/059ac (Lines 66, 98 and 121)

Here is full comparison of theming difference between Drupal 6, 7 and 8: https://www.drupal.org/node/2356951

Breakpoints and Responsive images
Breakpoints are basically screen width and height  identifiers based on media query and have additional metadata.
They are used for making your theme/module responsive.
Breakpoints can be united into groups for easier interaction.
https://www.drupal.org/documentation/modules/breakpoint
Here is how to define breakpoints (module_or_theme.breakpoints.yml): http://paste.adyax.com/72bc7

For example Drupal core includes module called Responsive Images
This module generates different image sources based on breakpoints. And then only that needed image will be displayed for client.
How it works:
Get all defined breakpoints grouped by responsive_images: http://paste.adyax.com/646e3
Generate image sources based on breakpoints: http://paste.adyax.com/38e56

Slicing process changes:
First of all, we should not put all libs and styles in slice and attach them for all site pages.
It is better to use dependencies (when some JS plugin requires jquery, then jquery should be loaded, otherwise no load needed). CSS should be separated per specific template.
It will be good to show slicers how to use twig, in this case they can apply simple frontEnd fixes without backEnd team (some class name changes, html structure, for example).
Content staging
Content staging solution provides many different use-cases, allow for replication between different systems and database, not just between Drupal sites.
Replication
The Replication Web Service module will provide the possibility to replicate content between different systems and Drupal 8
Offline applications.
Content staging solution will provide possibility to synchronise content between server and client (save in browser-based DB like PouchDB) and create offline applications.
It is based on Offline First principle.
(Vadim Tokarchuk)
http://wearepropeople.com/blog/a-content-staging-solution-for-drupal-8-…

Content staging solution provides many different use-cases, allow for replication between different systems and database, not just between Drupal sites.

Replication
The Replication Web Service module will provide the possibility to replicate content between different systems and Drupal 8

Offline applications.
Content staging solution will provide possibility to synchronise content between server and client (save in browser-based DB like PouchDB) and create offline applications.
It is based on Offline First principle.

 

Configuration management, impacts on deploy procedures
(Olaresko Dmytro)
This shit is really powerful. It provides possibility to deploy configuration changes easily between different environments. Each configuration file is a easy-reading yml like this: http://paste.adyax.com/26ebe
Developers should use configuration management system everywhere they used variable_set() in D7. 
Configuration management gives you tools to synchronize configs:
http://i.imgur.com/tMPatqT.png
And it is possible to import and export full config or some single configuration file.
The main concept is to use configuration files instead of DB dumps: database is for the content, but config gives you the way to make the whole site clone without any content but with exactly same content types, theme and modules settings, fields and displays.

helpful information about it: https://www.drupal.org/documentation/administer/config

Anything else about D8 you've found cool / painfull / new... (be as concrete as possible).

When it will be realeased?
(Ivan Tsekhmistro) 
https://drupalreleasedate.com/

@BOSTON – July 13, 2015 – Acquia today announced Drupal 8 availability on the Acquia Platform@

Drupal 8 is very expected to arrive soon, and now it is a good time to select D8 for new project with a long perspective.