your first d8 module

Post on 29-Nov-2014

247 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Learn the basics of module development in Drupal 8.

TRANSCRIPT

Your First Drupal 8 Module

Ted Bowman!a.k.a tedbow

Drupal Trainer!

• Drupal Training and Consulting

• @sixmiletech

• sixmiletech.com

• Drupal 7 Module Development

• coupon = 2013BADCAMP

• sixmiletech.com

• Training Newsletter Signup

• Free Webinar

• Online Class discounts

What should you know?

• PHP programming (or another language)!

• Object Oriented Programming(it helps)!

• Basic functions of Drupal!

• Experience with some modules

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

Warning!!!!

• Drupal 8 is still changing

• Pulled Drupal 8 Thursday

• Live Demo - Scary!!!!!

Its All about Hooks(mostly)

• Events in Drupal

• Allows Modules to “hook into“ functions of Drupal core & contrib Modules

• They are everywhere

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

Implementing a Hook

• How do I start?

Don't Call Drupal

• Drupal will call you!

It's all in the Name

• Drupal looks for functions that follow its naming conventions

“module_name“_“hook_name“

For Example

• Module: token

• Hook: hook_form_alter

• becomes.....

• token_form_alter

For Example - D7

How it works

More than Hooks - Plugins

• Drupal 8 adds Plugins to core

• Core Plugins

• Blocks

• Field Types

• Field Formatters

• Views Handlers

Providing a Plugin

• Plugins are discovered by Annotations

Plugins

• Replace info hooks

• hook_block_info

• hook_entity_info

• etc....

Let's make a 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

Create Module Folder

• /modules/rnotices

• or.....

• /modules/custom/rnotices

Create Module Files

• In /modules/custom/rnotices...

• rnotices.info.yml

• rnotices.module

*.info.yml Files

• Replaces .info file

• Tells Drupal about your module

rnotices.info.yml

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

*.module file

• Contains PHP Functions

• Needs opening <?php tag

• Needed even if empty(still?)

To the Code!

Your First Drupal 8 Module

Questions?

top related