2. Routes {Adding new menu / Access Control / Local
Tasks / Upcasting.}
Forms {Writing new custom form / Writing system settings
form.}
Configuration System.
More Changes for developers.
Drupal 8 Demo module showing all of the above
Topics
Drupal 8 Demo module showing all of the above
Drupal 8 Demo module showing all of the above
Drupal 8 Demo module showing all of the above
Drupal 8 Demo module showing all of the above
Drupal 8 Demo module showing all of the above
Drupal 8 Demo module showing all of the above
2
8. THE LESS YOUR CODE
KNOWS ABOUT THINGS
IT NEED THE MORE
REUSABLE IT IS
8
9. ALL OUR NOTIFIER CLASS NEEDS TO KNOW IS IT NEEDS
SOMETHING ON WHICH IT HAS TO CALL THE SEND METHOD.
9
10. Learn More about DI
DrupalCon Portland (Kat Bailey)
https://www.youtube.com/watch?v=kocJ6pn9kEc
10
11. Service Container
A Service Container (or dependency injection container) is
simply a PHP object that manages the instantiation of
services (i.e. objects)
{d8_demo.services.yml}
11
21. Namespacing & Folder Structure
Name Spacing
• Keeps
it reusable in other project with risk factor for conflict = 0.
Drupal/<module_name>.
• Drupal/<module_name>/Controller
to keep all the Controllers related to
<module_name> grouped in the same place.
Folder Structure
• lib/Drupal/<module_name>/Controller/<classname.php
• lib
directory is used to keep all the php classes seperate from other module/yml files.
• The
Drupal/hello part of the directory path is needed to comply with PSR-0, a
standard that says that the complete class name must be represented on the file
system.
21
24. Defining _access_check_admin
•
Register a new service using d8_demo.services.yml
•
tagged with access_check so Drupal can find it when it
loads all access checks
•
Convention to create a unique service name starting with
access_check.
24
26. Reusable Requirements
• Allow
everyone
_access: 'TRUE'
• Check
if user is logged in
_user_is_logged_in: 'TRUE'
• Check
if a user has a permission
_permission: 'my permission name'
• Check
if a user has a role
_role: 'role1+role2' (AND)
_role: 'role1, role2' (OR)
26
31. Forms
•
Form Api stays the same in Drupal 8. However, forms are now
Classes coz of d8's Object-oriented nature.
•
Base Classes in core:
•
FormBase
•
ConfigFormBase
•
ConfirmFormBase
•
BulkFormBase
•
ViewsFormBase
•
FieldInstanceFormBase
31
35. How do i save my configurations now?
•
•
DrupalCoreConfigConfigFactory
Where does this data get saved now?
35
36. Plugin System
•
Info hooks => Plugins
•
hook_info => annotation based discovery
•
Why annotation based?
•
•
Memory used is released once the file is read.
•
•
Uses php's tokenizer which allows the files to be parsed as text.
Loading the file in as php would mean that allocated memory was
required until the request was finalised.
All info hooks as plugins.
36
40. Changes to commonly used Drupal functions/hooks
•
hook_init removed(https://drupal.org/node/2013014)
•
drupal_goto has been
removed(https://drupal.org/node/2023537)e.g.,
drupal_goto($url)=>new RedirectResponse($url);
•
hook_boot has been removed(https://drupal.org/node/1909596)
•
$_GET[‘q'] has been removed(https://drupal.org/node/1659562)
•
drupal_*_form functions replaced with formBuilder service. e.g.,
drupal_get_from => Drupal::formBuilder()->getForm()
•
and many more...(https://drupal.org/list-changes)
40
41. References
Demo code is available at
https://github.com/piyuesh23/Drupal8-demo
•
https://drupal.org/list-changes
•
http://previousnext.com.au/blog/controlling-accessdrupal-8-routes-access-checks
•
https://drupal.org/node/1800686
•
DrupalCon Portland Videos
(http://www.youtube.com/playlist?
list=PLpeDXSh4nHjRlZKs7cj2L_kLI5osP5ERc)
41
Necessary Clutter module_load_include
Need to Bootstrap Drupal or at least the class for testing/reusing.
Constructor needs to know about Mailer Class
Mailer Class might need arguments in future requiring us to change the constructor of any class implementing it.
Or we might not need to send an email in future at all.
Constructor just knows its needs to be supplied with an instance of a Mailer class.
Class can accept anything thats implementing MailerInterface.
Inversion of Control.
Framework supplies the code with whatever it needs.
Rather than code instanting the lib classes and calling the library functions.
Classes: doesn’t know anything about the container. Decoupled. Declaratively expressing their dependencies.
Configuration: Contains Service Definitions(Class to intantiate+its dependencies)
Injector/Container:
Application: Entry point of application. Instantiate the container and ask it for what app needs.