SlideShare a Scribd company logo
Drupal 8
Core and API Changes
Shabir Ahmad
MS Software Engg. NUST
Principal Software Engineser – PHP/Drupal
engr.shabir@yahoo.com
Agenda
• What's coming in Drupal 8 for…
o End users and clients?
o Site builders?
• Designers and themers?
o Twig templates
• Developers?
o Symfony Components
o Module development
o Plugin System
• Tools and External libraries (Composer, Drush, Guzzle, DrupalAppConsole)
• API Function changes
• How can I contribute to community
End Users & Site Builders
• WYSIWYG in Core
• Better Authoring Experience
• In place editing
• Responsive in its Core (Mobile friendly admin panel)
• Responsive admin panel
• Web services and view in its core
• English no more special language. Multilingual out of the box
http://www.slideshare.net/AcquiaInc/drupal-8-preview-what-to-expect?qid=5f17d509-2207-
4521-9994-a093a776a41b&v=qf1&b=&from_search=5
Designers & Themers
Yeyyyy!!! We can use all html 5 benefits without installing any contrib modules
HTML5 Form Elements
$form['telephone'] = array(
'#type' => 'tel',
'#title' => t('Phone'),
);
$form['website'] = array(
'#type' => 'url',
'#title' => t('Website'),
);
$form['email'] = array(
'#type' => 'email',
'#title' => t('Email'),
);
$form['tickets'] = array(
'#type' => 'number',
'#title' => t('Tickets required'),
);
HTML5 Form Elements
TWIG Templates
What is TWIG??
• A PHP Template Engine to separate Presentation layer from the
Controller/Model (PHP)
• Developed by same people behind Symfony; yes, that’s in Drupal 8
Core too
But PHP was Just fine,
Why on earth to use twig!!
Common Complaints
• Mixed PHP with HTML can be just plain sloppy and hard to read
• PHP still has to scan html documents looking for all those <?php
tags amongst the HTML
• Designers have too much power and can open security bugs in the
presentation layer with PHP
• Defining a function or filtering for theming was sloppy — no real
standard way
• Php is faster but twig is safer As a developer you can’ do any php in
templates like
<?php $user = db_query(“SELECT n.nid FROM users WHERE uid = “.$_GET[‘uid’].“)”; ?>
http://twig.sensiolabs.org/doc/templates.html
Benefits
• An extendable template engine
• Secure (can enable variable output escaping globally)
• It’s Unit Tested
• Great documentation and online resources
• Not coupled to Symfony so it has its own roadmap and community
• Easy to understand clean syntax
• Once you know it, can use it in other PHP frameworks outside of
Drupal
• Syntax support in several IDEs (Sublime text,PHPStorm, Netbeans)
http://twig.sensiolabs.org/doc/templates.html
Lets understand the basics of Twig
Operation PHP (Drupal 7) Twig (Drupal 8)
Print output <?php print $something[‘key’] ?> {{ something.key }}
Comments <?php // …. Or /* ….*/ { # … #}
Filters <?php t(‘Welcome, ’ . $user[‘name’]); ?> {{ ‘Welcome, @name’|t({
‘@name’: user.name }) }}
Combining filters <?php strtoupper(t(‘Welcome, ’
.$user[‘name’]);) ?>
{{ ‘Welcome, @name’|t({
‘@name’: user.name }|upper) }}
If - else <?php if (isset($user[‘name’])) {
echo $user[‘name’]
} else {
echo ‘Who are you?’ };
?>
{% if user.name is defined %}
{{ user.name }}
{% else %}
Who are you?
{% endif %}
Loops <?php foreach ( $users as $key => $user ) {
print$user[‘name’]; } ?>
{% for key, user in users %}
{{ user.name }}
{% endfor %}
Operation PHP (Drupal 7) Twig (Drupal 8)
Calculation <?php print $user[‘total’] + 1; ?> {{ users.total + 1 }}
Concat Strings <?php print strtolower(‘’Greeting
‘ . $user[‘first’]); ?>
{% set greeting = 'Hello ' %}
{% set name = user.first %}
{{ greeting ~ name|lower }}
{# Hello Shabir #}
Expressions Various strings and array function {% if 1 not in [1, 2, 3] %}
{% if 'cd' in 'abcde' %}
{% if 'Bob' starts with 'B' %}
{% if phone matches '{^[d.]+$}' %}
Logic with
Expressions
PHP: && || <>, and ,or,not {% if user.name is not defined or
user.name == ‘shab’ %}
http://twig.sensiolabs.org/doc/templates.html
Extending layout
• Don’t duplicate the whole twig file just to change a single piece of
output. Extend it.
{% extends ‘layout.html.twig’ %}
• Conditional Extends:Mobile variable is set in code and passed to
template
{% extends mobile ? “mobile.html.twig" : “layout.html.twig” %}
• Blocks: Define content in blocks to allow for extending of templates.
{% block sidebar %}…content… {% endblock %}
• Debugging code: In setting.php uncomment the following line.
# $settings['twig_debug'] = TRUE;
{{ dump(user) }}
Killed Support for IE6,7 and most of IE8
Changes for
coders
01110111 01101001 01101100 01101100
00100000 01100011 01101111 01100100
01100101 00100000 01110000 01101000
01110000 00100000 01100110 01101111
01110010 00100000 01100110 01101111
01101111 01100100
Web Services
It’s like Services module in core, only better.
Issue tag: WSCCI
What problems are we trying to solve?
http://www.youtube.com/watch?v=l98dVUABD4w
What problems are we trying to solve?
http://www.youtube.com/watch?v=l98dVUABD4w
http://www.youtube.com/watch?v=l98dVUABD4w
Module Development!! Welcome Symfony
• Drupal 8 is built on top of the following
symphony components
• HttpFoundation and HttpKernal
• Routing
• Eventdispatcher
• Dependency injection
• Class loader
• Yaml, TWIG, Serializer
https://speakerdeck.com/fabpot/symfony2-meets-drupal-8
Module Anatomy
• The core modules are now in core directory
• The contributed and custom modules are now in
modules directory
• .info file is replaced by .info.yml
• .module file are no more mandatory.
• Drupal 8 is built on top of symphony 2 components
• Using PSR-0 for autoloading the classes and controllers
modules example lib Drupal example TestsExampleFooTest.php
ExampleBarTest.
php
Lets Develop a Hello World module
• As drupal 8 is now more like a framework, Correct!! So it does have a
scaffolding tool! So you people no need to create that PSR-0 imposed
nested directories.
• Steps for installation
• Now type the following command and follow the steps
./bin/console generate:module
https://github.com/hechoendrupal/DrupalAppConsole
Lets Develop a Hello World module
modules/mymodule/mymodule.info.yml
modules/mymodule/mymodule.local_task.yml
Lets Develop a Hello World module
Next Add a main route file that replace hook_menu
It should also be in main directory with the name
modules/mymodule/mymodule.routing.yml
Controller contains main logic and
menu Callback
In lib/mymodule/Drupal/Controller/myController.php paste the following code
Hook_info is now a plugin
In lib/mymodule/Drupal/plugin/myblock.php paste the following code
Drupal 8 Plugin System
• So what is plugin????
Some examples of plugins
are
1) Block
2) Custom fields
3) Custom field widget
4) Cck filter type
5) Custom image effects
6) Custom Actions
Benefits of plugin
• Definition and implementation in one place, in D7 it wasn’t necessary
• Plugins are lazy loaded (the code is in loaded to memory until called)
• Code is unified and extensible
• Reusable
http://www.youtube.com/watch?v=2o5uY-iOoMo
Core concepts used in Drupal 8
• Dependency Injection
• Service Containers
• PSR-0
• Annotation
PSR-0 Autoloading
• Fully-qualified namespace should be in the format of
Vendor/Namespace/Classname
• Directory structure must match namespace for plugin
http://www.php-fig.org/psr/psr-0
Annotation
• Metadata inside php docblocks
Normal Comment
Annotation
http://www.slideshare.net/rdohms/annotations-in-php-they-exist
Dependency Injection
• It is a symphony design pattern, some time called inversion of control.
• A class is instantiated inside a class, it means the class should know
about the class.
• If the dependent class is changed, the other class must be changed.
• We want the code to be ignorant, the more the code knows the less
reusable it will be
Service Containers
• Auto-instantiating all service oriented classes with all its registered
dependencies
• Also called dependency Injection containers
https://jtreminio.com/2012/10/an-introduction-to-pimple-and-service-containers
Some of API functions and hooks are changed in drupal 8
Operation Drupal 7 Drupal 8
String check_plain(), drupal_placeholder() String::placeholder(), String::placeholder()
Node/Entity $nodes = Node_load_multiple($nids)
Node_view_multiple($nodes)
Node_save($node);
$nodes=Entity_load_multiple(‘node’,$nids)
Entity_view_multiple($nodes)
Entity_create(‘node’,$values)->save()
Menus hook_menu
menu_get_objects()
Module.routing.yml
$request()->attributes->get(‘node’)
Taxonomies taxonomy_vocabulary_machine_name_l
oad('forums');
entity_load('taxonomy_vocabulary',
'forums');
Fields Field_info_field()
field_info_instance()
$fieldInfo = DrupalfieldField::fieldInfo();
$fieldInfo->getField($entity_type,
$field_name);
$fieldInfo->getInstance('node', 'article',
'field_name');
Alters Drupal_alter() // to alter data
Hook_form_alter()
Hook_form_id_alter
ModuleHandler::alter()
Same as d7
Some of API functions and hooks are changed in drupal 8
Operation Drupal 7 Drupal 8
hooks Module_invoke_all()
module_implements() //check if the
module implements certain hook
moduleHandler::invokeAll()
moduleHandler::getImplementations()
URLs drupal_get_query_parameters() UrlHelper::filterQueryParameters($url);
Paths (Where Am I) drupal_get_path() Drupal_get_path()
User (Who Am I) Global $user $account = Drupal::currentUser()
Modules loading and
Query entity
module_load_include()
EntityFieldQuery
Drupal::moduleHandler-
>loadInclude('node', 'inc', 'node.admin');
Drupal::entityQuery()
Javascript/css Drupal_add_js,drupal_add_css,drupal_a
dd_library
Gone in drupal 8
#attached = array(‘js’ => ‘myjs.js’)
http://slidedeck.io/fmitchell/d8apifuncnyccamp2014
Other tool.
• Composer
• Guzzle and http dev client (Chrome extension)
• Assetic (Asset manager)
• PHPUNIT for testing
• PSR/Log: Consistent logging from components and drupal
• Drupal scaffolding tool aka drupal app console
• Drush 7
Core mentoring
• Contribute your efforts to this awesome tool and make it the top of
the technologies
• Join irc channels at Tuesday morning and Wednesday evening and get
an issue to work on
• Or you can go to www.corementoring .org and get an issue
Questions????
• Thank you for you patience!!
Ad

More Related Content

What's hot (20)

Organinzing Your PHP Projects (2010 Memphis PHP)
Organinzing Your PHP Projects (2010 Memphis PHP)Organinzing Your PHP Projects (2010 Memphis PHP)
Organinzing Your PHP Projects (2010 Memphis PHP)
Paul Jones
 
Becoming A Drupal Master Builder
Becoming A Drupal Master BuilderBecoming A Drupal Master Builder
Becoming A Drupal Master Builder
Philip Norton
 
How to learn to build your own PHP framework
How to learn to build your own PHP frameworkHow to learn to build your own PHP framework
How to learn to build your own PHP framework
Dinh Pham
 
A Dexterity Intro for Recovering Archetypes Addicts
A Dexterity Intro for Recovering Archetypes AddictsA Dexterity Intro for Recovering Archetypes Addicts
A Dexterity Intro for Recovering Archetypes Addicts
David Glick
 
Drupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentDrupal 8 - Corso frontend development
Drupal 8 - Corso frontend development
sparkfabrik
 
Dexterity in the Wild
Dexterity in the WildDexterity in the Wild
Dexterity in the Wild
David Glick
 
Jumpstart Django
Jumpstart DjangoJumpstart Django
Jumpstart Django
ryates
 
Overlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh MyOverlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh My
Steve McMahon
 
Deprecated: Foundations of Zend Framework 2
Deprecated: Foundations of Zend Framework 2Deprecated: Foundations of Zend Framework 2
Deprecated: Foundations of Zend Framework 2
Adam Culp
 
Django
DjangoDjango
Django
Abhijeet Shekhar
 
Domas monkus drupal module development
Domas monkus drupal module developmentDomas monkus drupal module development
Domas monkus drupal module development
Domas Monkus
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
fishwarter
 
PyGrunn 2017 - Django Performance Unchained - slides
PyGrunn 2017 - Django Performance Unchained - slidesPyGrunn 2017 - Django Performance Unchained - slides
PyGrunn 2017 - Django Performance Unchained - slides
Artur Barseghyan
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
Sudip Simkhada
 
Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)
Jacob Kaplan-Moss
 
You suck at Memory Analysis
You suck at Memory AnalysisYou suck at Memory Analysis
You suck at Memory Analysis
Francisco Ribeiro
 
Jsf2 composite-components
Jsf2 composite-componentsJsf2 composite-components
Jsf2 composite-components
vinaysbk
 
Customizing the Django Admin
Customizing the Django AdminCustomizing the Django Admin
Customizing the Django Admin
Lincoln Loop
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
Zeeshan Ahmed
 
A look at Drupal 7 Theming
A look at Drupal 7 ThemingA look at Drupal 7 Theming
A look at Drupal 7 Theming
Aimee Maree Forsstrom
 
Organinzing Your PHP Projects (2010 Memphis PHP)
Organinzing Your PHP Projects (2010 Memphis PHP)Organinzing Your PHP Projects (2010 Memphis PHP)
Organinzing Your PHP Projects (2010 Memphis PHP)
Paul Jones
 
Becoming A Drupal Master Builder
Becoming A Drupal Master BuilderBecoming A Drupal Master Builder
Becoming A Drupal Master Builder
Philip Norton
 
How to learn to build your own PHP framework
How to learn to build your own PHP frameworkHow to learn to build your own PHP framework
How to learn to build your own PHP framework
Dinh Pham
 
A Dexterity Intro for Recovering Archetypes Addicts
A Dexterity Intro for Recovering Archetypes AddictsA Dexterity Intro for Recovering Archetypes Addicts
A Dexterity Intro for Recovering Archetypes Addicts
David Glick
 
Drupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentDrupal 8 - Corso frontend development
Drupal 8 - Corso frontend development
sparkfabrik
 
Dexterity in the Wild
Dexterity in the WildDexterity in the Wild
Dexterity in the Wild
David Glick
 
Jumpstart Django
Jumpstart DjangoJumpstart Django
Jumpstart Django
ryates
 
Overlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh MyOverlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh My
Steve McMahon
 
Deprecated: Foundations of Zend Framework 2
Deprecated: Foundations of Zend Framework 2Deprecated: Foundations of Zend Framework 2
Deprecated: Foundations of Zend Framework 2
Adam Culp
 
Domas monkus drupal module development
Domas monkus drupal module developmentDomas monkus drupal module development
Domas monkus drupal module development
Domas Monkus
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
fishwarter
 
PyGrunn 2017 - Django Performance Unchained - slides
PyGrunn 2017 - Django Performance Unchained - slidesPyGrunn 2017 - Django Performance Unchained - slides
PyGrunn 2017 - Django Performance Unchained - slides
Artur Barseghyan
 
Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)
Jacob Kaplan-Moss
 
Jsf2 composite-components
Jsf2 composite-componentsJsf2 composite-components
Jsf2 composite-components
vinaysbk
 
Customizing the Django Admin
Customizing the Django AdminCustomizing the Django Admin
Customizing the Django Admin
Lincoln Loop
 

Similar to Drupal 8 - Core and API Changes (20)

13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS
DrupalMumbai
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
manugoel2003
 
Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8
Angela Byron
 
DrupalCon LA 2015 Review
DrupalCon LA 2015 ReviewDrupalCon LA 2015 Review
DrupalCon LA 2015 Review
littleMAS
 
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Mir Nazim
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)
Oscar Merida
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Mack Hardy
 
Drupal module development
Drupal module developmentDrupal module development
Drupal module development
Rachit Gupta
 
Intro to drupal_7_architecture
Intro to drupal_7_architectureIntro to drupal_7_architecture
Intro to drupal_7_architecture
Hai Vo Hoang
 
Everything You Need to Know About the Top Changes in Drupal 8
Everything You Need to Know About the Top Changes in Drupal 8Everything You Need to Know About the Top Changes in Drupal 8
Everything You Need to Know About the Top Changes in Drupal 8
Acquia
 
Twig for Drupal 8 and PHP | Presented at OC Drupal
Twig for Drupal 8 and PHP | Presented at OC DrupalTwig for Drupal 8 and PHP | Presented at OC Drupal
Twig for Drupal 8 and PHP | Presented at OC Drupal
webbywe
 
Drupal 8 improvements for developer productivity php symfony and more
Drupal 8 improvements for developer productivity  php symfony and moreDrupal 8 improvements for developer productivity  php symfony and more
Drupal 8 improvements for developer productivity php symfony and more
Acquia
 
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
Eric Sembrat
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
Oscar Merida
 
How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.
DrupalCampDN
 
Your first d8 module
Your first d8 moduleYour first d8 module
Your first d8 module
tedbow
 
Drupal development
Drupal development Drupal development
Drupal development
Dennis Povshedny
 
Introduction To Drupal
Introduction To DrupalIntroduction To Drupal
Introduction To Drupal
Lauren Roth
 
Dolibarr - What's new in 20.0 - DevCamp Montpellier 2024.pptx
Dolibarr - What's new in 20.0 - DevCamp Montpellier 2024.pptxDolibarr - What's new in 20.0 - DevCamp Montpellier 2024.pptx
Dolibarr - What's new in 20.0 - DevCamp Montpellier 2024.pptx
Laurent Destailleur
 
Knolx session
Knolx sessionKnolx session
Knolx session
Knoldus Inc.
 
13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS
DrupalMumbai
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
manugoel2003
 
Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8
Angela Byron
 
DrupalCon LA 2015 Review
DrupalCon LA 2015 ReviewDrupalCon LA 2015 Review
DrupalCon LA 2015 Review
littleMAS
 
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Mir Nazim
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)
Oscar Merida
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Mack Hardy
 
Drupal module development
Drupal module developmentDrupal module development
Drupal module development
Rachit Gupta
 
Intro to drupal_7_architecture
Intro to drupal_7_architectureIntro to drupal_7_architecture
Intro to drupal_7_architecture
Hai Vo Hoang
 
Everything You Need to Know About the Top Changes in Drupal 8
Everything You Need to Know About the Top Changes in Drupal 8Everything You Need to Know About the Top Changes in Drupal 8
Everything You Need to Know About the Top Changes in Drupal 8
Acquia
 
Twig for Drupal 8 and PHP | Presented at OC Drupal
Twig for Drupal 8 and PHP | Presented at OC DrupalTwig for Drupal 8 and PHP | Presented at OC Drupal
Twig for Drupal 8 and PHP | Presented at OC Drupal
webbywe
 
Drupal 8 improvements for developer productivity php symfony and more
Drupal 8 improvements for developer productivity  php symfony and moreDrupal 8 improvements for developer productivity  php symfony and more
Drupal 8 improvements for developer productivity php symfony and more
Acquia
 
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
Eric Sembrat
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
Oscar Merida
 
How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.
DrupalCampDN
 
Your first d8 module
Your first d8 moduleYour first d8 module
Your first d8 module
tedbow
 
Introduction To Drupal
Introduction To DrupalIntroduction To Drupal
Introduction To Drupal
Lauren Roth
 
Dolibarr - What's new in 20.0 - DevCamp Montpellier 2024.pptx
Dolibarr - What's new in 20.0 - DevCamp Montpellier 2024.pptxDolibarr - What's new in 20.0 - DevCamp Montpellier 2024.pptx
Dolibarr - What's new in 20.0 - DevCamp Montpellier 2024.pptx
Laurent Destailleur
 
Ad

Recently uploaded (20)

Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Ad

Drupal 8 - Core and API Changes

  • 1. Drupal 8 Core and API Changes Shabir Ahmad MS Software Engg. NUST Principal Software Engineser – PHP/Drupal [email protected]
  • 2. Agenda • What's coming in Drupal 8 for… o End users and clients? o Site builders? • Designers and themers? o Twig templates • Developers? o Symfony Components o Module development o Plugin System • Tools and External libraries (Composer, Drush, Guzzle, DrupalAppConsole) • API Function changes • How can I contribute to community
  • 3. End Users & Site Builders • WYSIWYG in Core • Better Authoring Experience • In place editing • Responsive in its Core (Mobile friendly admin panel) • Responsive admin panel • Web services and view in its core • English no more special language. Multilingual out of the box http://www.slideshare.net/AcquiaInc/drupal-8-preview-what-to-expect?qid=5f17d509-2207- 4521-9994-a093a776a41b&v=qf1&b=&from_search=5
  • 5. Yeyyyy!!! We can use all html 5 benefits without installing any contrib modules
  • 6. HTML5 Form Elements $form['telephone'] = array( '#type' => 'tel', '#title' => t('Phone'), ); $form['website'] = array( '#type' => 'url', '#title' => t('Website'), ); $form['email'] = array( '#type' => 'email', '#title' => t('Email'), ); $form['tickets'] = array( '#type' => 'number', '#title' => t('Tickets required'), );
  • 9. What is TWIG?? • A PHP Template Engine to separate Presentation layer from the Controller/Model (PHP) • Developed by same people behind Symfony; yes, that’s in Drupal 8 Core too But PHP was Just fine, Why on earth to use twig!!
  • 10. Common Complaints • Mixed PHP with HTML can be just plain sloppy and hard to read • PHP still has to scan html documents looking for all those <?php tags amongst the HTML • Designers have too much power and can open security bugs in the presentation layer with PHP • Defining a function or filtering for theming was sloppy — no real standard way • Php is faster but twig is safer As a developer you can’ do any php in templates like <?php $user = db_query(“SELECT n.nid FROM users WHERE uid = “.$_GET[‘uid’].“)”; ?> http://twig.sensiolabs.org/doc/templates.html
  • 11. Benefits • An extendable template engine • Secure (can enable variable output escaping globally) • It’s Unit Tested • Great documentation and online resources • Not coupled to Symfony so it has its own roadmap and community • Easy to understand clean syntax • Once you know it, can use it in other PHP frameworks outside of Drupal • Syntax support in several IDEs (Sublime text,PHPStorm, Netbeans) http://twig.sensiolabs.org/doc/templates.html
  • 12. Lets understand the basics of Twig Operation PHP (Drupal 7) Twig (Drupal 8) Print output <?php print $something[‘key’] ?> {{ something.key }} Comments <?php // …. Or /* ….*/ { # … #} Filters <?php t(‘Welcome, ’ . $user[‘name’]); ?> {{ ‘Welcome, @name’|t({ ‘@name’: user.name }) }} Combining filters <?php strtoupper(t(‘Welcome, ’ .$user[‘name’]);) ?> {{ ‘Welcome, @name’|t({ ‘@name’: user.name }|upper) }} If - else <?php if (isset($user[‘name’])) { echo $user[‘name’] } else { echo ‘Who are you?’ }; ?> {% if user.name is defined %} {{ user.name }} {% else %} Who are you? {% endif %} Loops <?php foreach ( $users as $key => $user ) { print$user[‘name’]; } ?> {% for key, user in users %} {{ user.name }} {% endfor %}
  • 13. Operation PHP (Drupal 7) Twig (Drupal 8) Calculation <?php print $user[‘total’] + 1; ?> {{ users.total + 1 }} Concat Strings <?php print strtolower(‘’Greeting ‘ . $user[‘first’]); ?> {% set greeting = 'Hello ' %} {% set name = user.first %} {{ greeting ~ name|lower }} {# Hello Shabir #} Expressions Various strings and array function {% if 1 not in [1, 2, 3] %} {% if 'cd' in 'abcde' %} {% if 'Bob' starts with 'B' %} {% if phone matches '{^[d.]+$}' %} Logic with Expressions PHP: && || <>, and ,or,not {% if user.name is not defined or user.name == ‘shab’ %} http://twig.sensiolabs.org/doc/templates.html
  • 14. Extending layout • Don’t duplicate the whole twig file just to change a single piece of output. Extend it. {% extends ‘layout.html.twig’ %} • Conditional Extends:Mobile variable is set in code and passed to template {% extends mobile ? “mobile.html.twig" : “layout.html.twig” %} • Blocks: Define content in blocks to allow for extending of templates. {% block sidebar %}…content… {% endblock %} • Debugging code: In setting.php uncomment the following line. # $settings['twig_debug'] = TRUE; {{ dump(user) }}
  • 15. Killed Support for IE6,7 and most of IE8
  • 16. Changes for coders 01110111 01101001 01101100 01101100 00100000 01100011 01101111 01100100 01100101 00100000 01110000 01101000 01110000 00100000 01100110 01101111 01110010 00100000 01100110 01101111 01101111 01100100
  • 17. Web Services It’s like Services module in core, only better. Issue tag: WSCCI
  • 18. What problems are we trying to solve? http://www.youtube.com/watch?v=l98dVUABD4w
  • 19. What problems are we trying to solve? http://www.youtube.com/watch?v=l98dVUABD4w
  • 21. Module Development!! Welcome Symfony • Drupal 8 is built on top of the following symphony components • HttpFoundation and HttpKernal • Routing • Eventdispatcher • Dependency injection • Class loader • Yaml, TWIG, Serializer https://speakerdeck.com/fabpot/symfony2-meets-drupal-8
  • 22. Module Anatomy • The core modules are now in core directory • The contributed and custom modules are now in modules directory • .info file is replaced by .info.yml • .module file are no more mandatory. • Drupal 8 is built on top of symphony 2 components • Using PSR-0 for autoloading the classes and controllers modules example lib Drupal example TestsExampleFooTest.php ExampleBarTest. php
  • 23. Lets Develop a Hello World module • As drupal 8 is now more like a framework, Correct!! So it does have a scaffolding tool! So you people no need to create that PSR-0 imposed nested directories. • Steps for installation • Now type the following command and follow the steps ./bin/console generate:module https://github.com/hechoendrupal/DrupalAppConsole
  • 24. Lets Develop a Hello World module modules/mymodule/mymodule.info.yml modules/mymodule/mymodule.local_task.yml
  • 25. Lets Develop a Hello World module Next Add a main route file that replace hook_menu It should also be in main directory with the name modules/mymodule/mymodule.routing.yml
  • 26. Controller contains main logic and menu Callback In lib/mymodule/Drupal/Controller/myController.php paste the following code
  • 27. Hook_info is now a plugin In lib/mymodule/Drupal/plugin/myblock.php paste the following code
  • 28. Drupal 8 Plugin System • So what is plugin???? Some examples of plugins are 1) Block 2) Custom fields 3) Custom field widget 4) Cck filter type 5) Custom image effects 6) Custom Actions
  • 29. Benefits of plugin • Definition and implementation in one place, in D7 it wasn’t necessary • Plugins are lazy loaded (the code is in loaded to memory until called) • Code is unified and extensible • Reusable http://www.youtube.com/watch?v=2o5uY-iOoMo
  • 30. Core concepts used in Drupal 8 • Dependency Injection • Service Containers • PSR-0 • Annotation
  • 31. PSR-0 Autoloading • Fully-qualified namespace should be in the format of Vendor/Namespace/Classname • Directory structure must match namespace for plugin http://www.php-fig.org/psr/psr-0
  • 32. Annotation • Metadata inside php docblocks Normal Comment Annotation http://www.slideshare.net/rdohms/annotations-in-php-they-exist
  • 33. Dependency Injection • It is a symphony design pattern, some time called inversion of control. • A class is instantiated inside a class, it means the class should know about the class. • If the dependent class is changed, the other class must be changed. • We want the code to be ignorant, the more the code knows the less reusable it will be
  • 34. Service Containers • Auto-instantiating all service oriented classes with all its registered dependencies • Also called dependency Injection containers https://jtreminio.com/2012/10/an-introduction-to-pimple-and-service-containers
  • 35. Some of API functions and hooks are changed in drupal 8 Operation Drupal 7 Drupal 8 String check_plain(), drupal_placeholder() String::placeholder(), String::placeholder() Node/Entity $nodes = Node_load_multiple($nids) Node_view_multiple($nodes) Node_save($node); $nodes=Entity_load_multiple(‘node’,$nids) Entity_view_multiple($nodes) Entity_create(‘node’,$values)->save() Menus hook_menu menu_get_objects() Module.routing.yml $request()->attributes->get(‘node’) Taxonomies taxonomy_vocabulary_machine_name_l oad('forums'); entity_load('taxonomy_vocabulary', 'forums'); Fields Field_info_field() field_info_instance() $fieldInfo = DrupalfieldField::fieldInfo(); $fieldInfo->getField($entity_type, $field_name); $fieldInfo->getInstance('node', 'article', 'field_name'); Alters Drupal_alter() // to alter data Hook_form_alter() Hook_form_id_alter ModuleHandler::alter() Same as d7
  • 36. Some of API functions and hooks are changed in drupal 8 Operation Drupal 7 Drupal 8 hooks Module_invoke_all() module_implements() //check if the module implements certain hook moduleHandler::invokeAll() moduleHandler::getImplementations() URLs drupal_get_query_parameters() UrlHelper::filterQueryParameters($url); Paths (Where Am I) drupal_get_path() Drupal_get_path() User (Who Am I) Global $user $account = Drupal::currentUser() Modules loading and Query entity module_load_include() EntityFieldQuery Drupal::moduleHandler- >loadInclude('node', 'inc', 'node.admin'); Drupal::entityQuery() Javascript/css Drupal_add_js,drupal_add_css,drupal_a dd_library Gone in drupal 8 #attached = array(‘js’ => ‘myjs.js’) http://slidedeck.io/fmitchell/d8apifuncnyccamp2014
  • 37. Other tool. • Composer • Guzzle and http dev client (Chrome extension) • Assetic (Asset manager) • PHPUNIT for testing • PSR/Log: Consistent logging from components and drupal • Drupal scaffolding tool aka drupal app console • Drush 7
  • 38. Core mentoring • Contribute your efforts to this awesome tool and make it the top of the technologies • Join irc channels at Tuesday morning and Wednesday evening and get an issue to work on • Or you can go to www.corementoring .org and get an issue
  • 39. Questions???? • Thank you for you patience!!