your first d8 module

29
Your First Drupal 8 Module

Upload: tedbow

Post on 29-Nov-2014

245 views

Category:

Technology


0 download

DESCRIPTION

Learn the basics of module development in Drupal 8.

TRANSCRIPT

Page 1: Your first d8 module

Your First Drupal 8 Module

Page 2: Your first d8 module

Ted Bowman!a.k.a tedbow

Drupal Trainer!

Page 3: Your first d8 module

• Drupal Training and Consulting

• @sixmiletech

• sixmiletech.com

Page 4: Your first d8 module

• Drupal 7 Module Development

• coupon = 2013BADCAMP

Page 5: Your first d8 module

• sixmiletech.com

• Training Newsletter Signup

• Free Webinar

• Online Class discounts

Page 6: Your first d8 module
Page 7: Your first d8 module

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

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

Warning!!!!

• Drupal 8 is still changing

• Pulled Drupal 8 Thursday

• Live Demo - Scary!!!!!

Page 10: Your first d8 module

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

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

Implementing a Hook

• How do I start?

Page 13: Your first d8 module

Don't Call Drupal

• Drupal will call you!

Page 14: Your first d8 module

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

For Example

• Module: token

• Hook: hook_form_alter

• becomes.....

• token_form_alter

Page 16: Your first d8 module

For Example - D7

Page 17: Your first d8 module

How it works

Page 18: Your first d8 module

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

Providing a Plugin

• Plugins are discovered by Annotations

Page 20: Your first d8 module

Plugins

• Replace info hooks

• hook_block_info

• hook_entity_info

• etc....

Page 21: Your first d8 module

Let's make a module!!

Page 22: Your first d8 module

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

Create Module Folder

• /modules/rnotices

• or.....

• /modules/custom/rnotices

Page 24: Your first d8 module

Create Module Files

• In /modules/custom/rnotices...

• rnotices.info.yml

• rnotices.module

Page 25: Your first d8 module

*.info.yml Files

• Replaces .info file

• Tells Drupal about your module

Page 26: Your first d8 module

rnotices.info.yml

name: Role Notices type: module description: 'Display notices per role.' package: Demo core: 8.x

Page 27: Your first d8 module

*.module file

• Contains PHP Functions

• Needs opening <?php tag

• Needed even if empty(still?)

Page 28: Your first d8 module

To the Code!

Page 29: Your first d8 module

Your First Drupal 8 Module

Questions?