drupal 8 dx changes
DESCRIPTION
In this presentation we will talk about API Changes from D7 to D8 with code examples and a demo. The talk was given in Drupal camp Delhi and Mumbai by Piyuesh Kumar.TRANSCRIPT
Future Proofing Your Drupal Skills
Piyuesh KumarQED42
1
AGENDA:• Drupal 8 Api Changes:
• Module info file• Routing System• Drupal 8 CMI & Using Config inspector• Writing forms and their submit handlers in d8.• Drupal 8 new plugin system• Basic changes to oftenly uses Drupal functions.
2
Info File• Info files changed to info.yml• Old info file: {d7.info}
• New info file: {d8.info.yml}
3
Warning:Things are about to get...
geeky.
4
ROUTING SYSTEM
• d7(hook_menu):
5
D8 ROUTING SYSTEM(HOOK_MENU)
• d8 conversion(hook_menu):• Hook_menu Lives until hook_default_menu_links()
gets into core(https://drupal.org/node/2047633 )
6
D8 ROUTING SYSTEM(ROUTING.YML)
• d8 conversion:• Callbacks and permissions are defined in a yml
file.{d8.routing.yml}
7
D8 ROUTING SYSTEM(WRITING CONTROLLERS)
• d8 conversion:• Writing Page Callbacks
8
D8 ROUTING SYSTEM(CORE CONTROLLERS)
• _form• _content• _controller• _entity_form• _entity_list• and many more..
9
CONFIGURATION SCHEMA
• R.I.P variable-get/variable_set
10
CONFIGURATION SCHEMA
• When would Config data get saved?
• UI changes (automatic): When the save button is clicked on an admin page, data gets written to the active store as well as db.
• Code changes (manual): use admin/config/development/sync to sync the config in code with db and active store.
11
CMI(EXAMPLE)
• D7:
• D8:
12
USING CONFIG INSPECTOR
• https://drupal.org/project/config_inspector/git-instructions
13
WRITING FORMS AND THEIR SUBMIT HANDLERS IN D8
• FormInterface(https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!FormInterface.php/interface/FormInterface/8)
• SystemConfigFormBase(http://drupalcontrib.org/api/drupal/drupal!core!modules!system!lib!Drupal!system!SystemConfigFormBase.php/class/SystemConfigFormBase/8)
14
EXAMPLE
• D7:
15
EXAMPLE• D8:
16
D8 FORMS(VALIDATION & SUBMISSION)
• function validateForm(array &$form, array &$form_state) {}
• function submitForm(array &$form, array &$form_state) {}
17
D8 FORMS(SYSTEM_SETTINGS_FORM
??)• Extends SystemConfigFormBase:
18
D8 FORMS(OTHER EXTENDABLE CLASSES IN CORE)
• ConfirmFormBase(https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!ConfirmFormBase.php/class/ConfirmFormBase/8)
• BulkFormBase(https://api.drupal.org/api/drupal/core!modules!system!lib!Drupal!system!Plugin!views!field!BulkFormBase.php/8)
• FieldInstanceFormBase
• ViewsFormBase(https://api.drupal.org/api/drupal/core!modules!views_ui!lib!Drupal!views_ui!Form!Ajax!ViewsFormBase.php/class/ViewsFormBase/8)
19
WHAT HAPPENED TO DRUPAL_*_FORM FUNCTIONS?
20
DRUPAL 8 NEW PLUGIN SYSTEM
21
Module/hook system functions replaced with
module handler service(https://drupal.org/n
ode/1894902)
22
Basic Function from d7 to d8• 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()
• For more goto https://drupal.org/list-changes
23
References
Demo code is available at https://github.com/piyuesh23/Drupal8-demo
• https://drupal.org/list-changes• http://previousnext.com.au/blog/controlling-access-
drupal-8-routes-access-checks• https://drupal.org/node/1800686• DrupalCon Portland Videos
(http://www.youtube.com/playlist?list=PLpeDXSh4nHjRlZKs7cj2L_kLI5osP5ERc)
24