Your first d8 module
-
Upload
tedbow -
Category
Technology
-
view
247 -
download
0
description
Transcript of Your first d8 module
![Page 1: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/1.jpg)
Your First Drupal 8 Module
![Page 2: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/2.jpg)
Ted Bowman!a.k.a tedbow
Drupal Trainer!
![Page 3: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/3.jpg)
• Drupal Training and Consulting
• @sixmiletech
• sixmiletech.com
![Page 4: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/4.jpg)
• Drupal 7 Module Development
• coupon = 2013BADCAMP
![Page 5: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/5.jpg)
• sixmiletech.com
• Training Newsletter Signup
• Free Webinar
• Online Class discounts
![Page 6: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/6.jpg)
![Page 7: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/7.jpg)
What should you know?
• PHP programming (or another language)!
• Object Oriented Programming(it helps)!
• Basic functions of Drupal!
• Experience with some modules
![Page 8: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/8.jpg)
Why make a module?
• Contribute to Drupal.org
• Functions to reuse between sites
• Functions specific to a site
• Learn to debug contrib and core
• Learn how other modules work
![Page 9: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/9.jpg)
Warning!!!!
• Drupal 8 is still changing
• Pulled Drupal 8 Thursday
• Live Demo - Scary!!!!!
![Page 10: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/10.jpg)
Its All about Hooks(mostly)
• Events in Drupal
• Allows Modules to “hook into“ functions of Drupal core & contrib Modules
• They are everywhere
![Page 11: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/11.jpg)
Example Hooks
Hook Name Drupal Function
hook_node_load Loading a node from database
hook_form_alter Allows altering forms
hook_user_login User has just logged in
![Page 12: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/12.jpg)
Implementing a Hook
• How do I start?
![Page 13: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/13.jpg)
Don't Call Drupal
• Drupal will call you!
![Page 14: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/14.jpg)
It's all in the Name
• Drupal looks for functions that follow its naming conventions
“module_name“_“hook_name“
![Page 15: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/15.jpg)
For Example
• Module: token
• Hook: hook_form_alter
• becomes.....
• token_form_alter
![Page 16: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/16.jpg)
For Example - D7
![Page 17: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/17.jpg)
How it works
![Page 18: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/18.jpg)
More than Hooks - Plugins
• Drupal 8 adds Plugins to core
• Core Plugins
• Blocks
• Field Types
• Field Formatters
• Views Handlers
![Page 19: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/19.jpg)
Providing a Plugin
• Plugins are discovered by Annotations
![Page 20: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/20.jpg)
Plugins
• Replace info hooks
• hook_block_info
• hook_entity_info
• etc....
![Page 21: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/21.jpg)
Let's make a module!!
![Page 22: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/22.jpg)
Role Notices
• Allows admin to set notices for each role
• Provides a block to display notices
• Provides notices as display field on users
• Allows other modules to change notices before displaying
![Page 23: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/23.jpg)
Create Module Folder
• /modules/rnotices
• or.....
• /modules/custom/rnotices
![Page 24: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/24.jpg)
Create Module Files
• In /modules/custom/rnotices...
• rnotices.info.yml
• rnotices.module
![Page 25: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/25.jpg)
*.info.yml Files
• Replaces .info file
• Tells Drupal about your module
![Page 26: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/26.jpg)
rnotices.info.yml
name: Role Notices type: module description: 'Display notices per role.' package: Demo core: 8.x
![Page 27: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/27.jpg)
*.module file
• Contains PHP Functions
• Needs opening <?php tag
• Needed even if empty(still?)
![Page 28: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/28.jpg)
To the Code!
![Page 29: Your first d8 module](https://reader034.fdocuments.in/reader034/viewer/2022051323/5479e867b379596a2b8b48b2/html5/thumbnails/29.jpg)
Your First Drupal 8 Module
Questions?