SlideShare a Scribd company logo
The Synergy of Drupal Hooks/APIs
Custom Chart Block	

Engr. Ranel O. Padon	

	

Drupal Summer Camp PH 2015
About Me
•  Software Engineer at Kite Systems (Hong Kong-based company)	

–  full-time Drupal developer for CNN Travel (our client)	

•  part-time Python lecturer in University of the Philippines	

•  involved with programming for 9 years (Python, Java, etc)	

•  involved in Drupal for the last 3 years	

•  projects: http://github.com/ranelpadon	

•  plays football/futsal
Coverage/Use Cases
•  Block API: create, enable, display, update, save 	

•  Form API: textarea, select list, checkbox, textfield	

•  variable_get, variable_set, variable_del	

•  EntityFieldQuery API	

•  hook_menu, drupal_get_form, system_settings_form	

•  JSON menu callback: drupal_json_output	

•  Render API: #markup, #attached	

•  drupal_get_path	

•  Extending Drupal Behaviors (attach function) 	

•  Drupal.settings JS object
Drupal Hooks/APIs
•  There is beauty and synergy in Drupal functions.	

	

	

•  Synergy	

	

the interaction of elements that when combined
	

produce a total effect that is greater than 	

	

the sum of the individual elements, contributions,
	

etc.
Drupal Hooks/APIs
•  Individual Drupal functions are boring and 	

	

not that useful, but their combinations 	

	

are interesting and very powerful.
CNN Travel Blocks
•  if you go to the CNN Travel site:	

	

 	

http://travel.cnn.com	

	

you’ll notice that we have so many blocks in the
	

front page	

	

•  blocks add valuable information to the site and
creates more visual interest to your page	

	

•  recently, we’ve implemented a block that features	

	

our partner hotels
CNN Travel Partner Hotels
CNN Travel Partner Hotels
Drupal Learning Milestones
Typical Learning Curve
Learning Curve
In the beginning of any learning, while you're on the long,
flat part of the curve, you put in great amounts of time
and effort, but see little in the way of results. 	

	

Persistent practice helps you move along the learning
curve until you hit that sweet spot—about 80% of the
way into the process—where the curve starts to rise
sharply, and results come easily.	

	

http://bruceelkin.hubpages.com/hub/10-000-Hours--The-Awesome-
Power-of-Practice
Learning Curve
in most field of learning (sports, programming, music,
etc), there are many tutorials/exercises about the basic
skills, but relatively few about the ‘intermediate’ skills	

	

this presentation will try to fill the knowledge gap for
Drupal devs by exposing some of the most useful
functions	

	

partner hotels block is an interesting block and a good
Drupal development exercise since its implementation
involves lots of Drupal hooks/functions
Learning Curve
•  there are 403 hooks in Drupal 7 core alone and
hundreds/thousands of related/utility functions	

•  but you only need a handful of them to be productive	

•  knowing 10-20 of the most useful functions could
boost your productivity	

•  I’ll showcase the value of some of the Drupal
functions/use cases by creating a simpler and related
version of Partner Hotels block
Summer Camp Module
•  summercamp	

•  summercamp.info	

•  summercamp.module
Summer Camp Module
•  Info Files	

•  contains metadata/info about the name	

	

description, version, package/group, etc of	

	

the module
Summer Camp Module
•  Info Files	

•  similar to php.ini file	

•  comments preceded by a semicolon (;)	

•  more details: https://www.drupal.org/node/542202
Summer Camp Module
•  summercamp.info	

•  name and core version	

	

are the minimum info needed
Summer Camp Module
•  summercamp.module	

•  contains PHP/Drupal variables/functions/hooks	

•  more details: https://www.drupal.org/node/1074360
Summer Camp Module
•  summercamp	

•  summercamp.info	

•  summercamp.module	

•  the module could now be enabled in admin/modules page
Implementing a Block
•  Register: hook_block_info()	

•  Display: hook_block_view()	

•  Update: hook_block_configure()	

•  Save: hook_block_save()
Hook_Block_Info
•  summercamp.module	

•  register a new block, enable it, assign to right sidebar
Hook_Block_Info
•  the block will now appear in block admin page
Hook_Block_View
•  summercamp.module	

•  if the currently passed/processed block is our target,	

	

set its Title and Contents
The Rendered Block
•  the block will now show in the right sidebar. J
Hook_Block_Configure
•  to make the block contents editable in Admin UI,	

	

we could use the hook_block_configure().	

•  but we need a persistent storage/table for its contents	

•  we could use the handy Variable table built-in	

	

in Drupal
Variable table
	

there are 29 variables 	

	

by default in	

	

Drupal 7.37	

	

	

	

maintenance_mode is	

	

just inserted for demo	

	

of this presentation
Variable table
•  we could easily manipulate values in 	

	

the Variable table, without using SQL directly:	

	

OPERATION	

 DRUPAL FUNCTION	

Create/Update	
   variable_set()	
  
Read	
   variable_get()	
  
Delete	
   variable_del()
Variable table
•  variable_set(NAME, VALUE )	

•  variable_get(NAME, DEFAULT_VALUE)	

•  variable_del(NAME)
Variable table
•  Variable table is very valuable	

•  There’s an Easter Egg in Drupal.org J	

•  https://www.drupal.org/files/my_tombstone.jpg
Hook_Block_Configure
•  we need a way to edit the block contents
Hook_Block_Configure
•  editing the block contents is now possible, but
changes will still not be saved.
Hook_Block_Save
•  we’ll use the another hook to save the edits
Hook_Block_View
•  and adjust the hook_block_view to make use 	

	

of the saved content
Hook_Block_Save
•  edit the block content, save the changes, 	

	

the rendered block will be updated.
Charts
•  we’ll use the ChartJS since it’s open-source,	

	

simple to use, has clean syntax, and mobile-friendly:	

	

http://www.chartjs.org/
ChartJS Page
•  include the ChartJS script	

•  create a CANVAS element in a page	

•  set the input data	

•  convert the CANVAS element to a chart object	

	

against the input data
ChartJS Page
•  include the ChartJS script	

•  select version from here: 	

•  https://cdnjs.com/libraries/chart.js	

•  latest version:	

•  https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.js
ChartJS Page
•  create a CANVAS element in the page
ChartJS Page
•  set the input data
ChartJS Page
•  convert the CANVAS element to a chart object	

	

against the input data
ChartJS Page
•  convert the CANVAS element to a chart object	

	

against some input data.
ChartJS Page
•  the rendered chart and the hovered value.
ChartJS Page
•  we could add hover effects: highlight and label
Chart Block
•  how do we display a chart in a Drupal block?	

•  we need to satisfy these conditions again:	

•  include the ChartJS script	

•  create a CANVAS element in a page	

•  set the input data	

•  convert the CANVAS element to a chart object	

	

against the input data
Chart Block
•  we’ll focus first on the input data	

•  we need a JSON data from Drupal	

•  we’ll create 3 articles and broadcast them as	

	

JSON objects
Data Source: Create 3 Articles
•  Article 1 	

–  Tags: ‘alpha’	

–  Body: ‘Lorem Ipsum 1’	

	

•  Article 2	

–  Tags: ‘beta’	

–  Body: ‘Lorem Ipsum 2’	

•  Article 3	

–  Tags: ‘alpha’	

–  Body: ‘Lorem Ipsum 3’
EntityFieldQuery API
•  create a helper function to retrieve the articles	

•  we’ll use the powerful and flexible EFQ API
EntityFieldQuery API
•  _get_articles() function callback
Hook_Menu | JSON Output
•  bind the function to a menu	

•  encode the _get_articles() output to JSON 	

•  set the access permission to use
Hook_Menu
•  Make sure to clear the Drupal cache to register 	

	

and activate the newly created menu
•  the JSON data will
now be accessible	

•  you might want to
use Chrome’s
JSON Formatter
Hook_Block_View | #Markup
•  insert a CANVAS element	

•  convert ‘content’ to array structure	

•  insert a ‘#markup’ property/array key	

•  set the block markup
Hook_Block_View | #Attached
•  insert the ChartJS script	

•  attach a new JS file to the ‘content’	

•  set the JS data/src	

•  set the data as external script
Drupal Behaviors | Driver File
•  implement the ChartJS driver file	

•  create a new Drupal behavior, 	

	

define the ‘attach’-mode function	

•  let’s use first the previous, non-Drupal	

	

sample chart codes
•  implement the ChartJS driver file	

•  attach a new JS file to the ‘content’	

•  set the JS data/src	

•  set the data as a local file
Hook_Block_View | #Attached
•  insert the ChartJS driver	

•  attach a new JS file to the ‘content’	

•  set the JS data/src	

•  set the data as a local file
Chart Block
•  the chart will now be rendered in the block J
Drupal Behaviors | Driver File
•  adjust the ChartJS driver	

•  fetch the Articles JSON as the input data	

•  convert the chart renderer to a function	

•  will be used in a JSON function callback
Chart Block | Articles
•  the articles’ JSON data will now be rendered
Injecting JS | #Attach
•  note that the main advantage of #attach compared	

	

to drupal_add_js() is that they are ‘alterable’	

	

since they are inserted as array elements	

•  same justification applies for drupal_add_css()	

•  #attach is also used in Drupal 8.	

•  you could alter the #attached JS/CSS files	

	

using hook_js_alter() and hook_css_alter()
Creating an Admin Page
•  there are times you’ll need to have some admin page	

	

for inputting custom site settings/configurations	

	

•  for instance, you’ll like to control if you would like
to show the chart labels, have an text field entry for
the chart colors or highlight colors, a way to select
the chart type, a way to use other chart script, and
so on.
Creating an Admin Page
•  use case: we want to select the chart type to display	

•  the user could choose to display a Pie or Doughnut
chart
Creating an Admin Page
•  requires a hook_menu that will call a page element
generated using Form API	

•  input site/form data could be saved in the Variable
table using the handy system_settings_form().
Target Menu and Admin Page
Chart Settings Admin Page
Hook_Menu: Paths
Hook_Menu: Labels and Form
_Chart_Admin_Settings Form
Adjust Hook_Block_View
Adjust Drupal Behaviors
Adjust Drupal Behaviors
Dynamic Chart J
Expose other Chart Options
Adjust _Chart_Admin_Settings
Configure Module’s Info
SummerCamp Module Repo
•  I’ve already implemented the repo in GitHub and
added more blocks and features:	

•  https://github.com/ranelpadon/summercamp	

•  showcases ChartJS, Panoramio API, and GitHub’s
Gist API.	

•  implements blocks using theme function and
template file	

•  demonstrates processing JSON data in back-end
and front-end	

•  and more..
https://github.com/ranelpadon/summercamp
Recommendations
•  Drupal Development Tools	

•  Essential and Effective Drupal Tools	

•  http://befused.com/drupal/essential-tools
Recommendations
•  Drupal Development Books	

•  Master Drupal 7 Module Development by Wadman	

•  http://befused.com/master-drupal/	

•  Drupal 7 Module Development	

	

 by Butcher, et al.
Special Thanks
•  CNN Travel (http://travel.cnn.com) for the
ideas and inspiration for this presentation.
There is beauty in Drupal.

More Related Content

What's hot

Resume_JiaLIU
Resume_JiaLIUResume_JiaLIU
Resume_JiaLIUJia Liu
 
Java Collections
Java CollectionsJava Collections
Java Collections
RJNEESH KAUR
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
guy_davis
 
Learning iOS and hunting NSZombies in 3 weeks
Learning iOS and hunting NSZombies in 3 weeksLearning iOS and hunting NSZombies in 3 weeks
Learning iOS and hunting NSZombies in 3 weeks
Calvin Cheng
 
Sling Models Overview
Sling Models OverviewSling Models Overview
Sling Models Overview
Justin Edelson
 
[2015/2016] Backbone JS
[2015/2016] Backbone JS[2015/2016] Backbone JS
[2015/2016] Backbone JS
Ivano Malavolta
 
iOS Beginners Lesson 2
iOS Beginners Lesson 2iOS Beginners Lesson 2
iOS Beginners Lesson 2
Calvin Cheng
 
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
Kobkrit Viriyayudhakorn
 
Netflix's Recommendation ML Pipeline Using Apache Spark: Spark Summit East ta...
Netflix's Recommendation ML Pipeline Using Apache Spark: Spark Summit East ta...Netflix's Recommendation ML Pipeline Using Apache Spark: Spark Summit East ta...
Netflix's Recommendation ML Pipeline Using Apache Spark: Spark Summit East ta...
Spark Summit
 

What's hot (11)

Resume_JiaLIU
Resume_JiaLIUResume_JiaLIU
Resume_JiaLIU
 
Java Collections
Java CollectionsJava Collections
Java Collections
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Learning iOS and hunting NSZombies in 3 weeks
Learning iOS and hunting NSZombies in 3 weeksLearning iOS and hunting NSZombies in 3 weeks
Learning iOS and hunting NSZombies in 3 weeks
 
Sling Models Overview
Sling Models OverviewSling Models Overview
Sling Models Overview
 
[2015/2016] Backbone JS
[2015/2016] Backbone JS[2015/2016] Backbone JS
[2015/2016] Backbone JS
 
slingmodels
slingmodelsslingmodels
slingmodels
 
iOS Beginners Lesson 2
iOS Beginners Lesson 2iOS Beginners Lesson 2
iOS Beginners Lesson 2
 
Context at design
Context at designContext at design
Context at design
 
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
 
Netflix's Recommendation ML Pipeline Using Apache Spark: Spark Summit East ta...
Netflix's Recommendation ML Pipeline Using Apache Spark: Spark Summit East ta...Netflix's Recommendation ML Pipeline Using Apache Spark: Spark Summit East ta...
Netflix's Recommendation ML Pipeline Using Apache Spark: Spark Summit East ta...
 

Viewers also liked

Mba
MbaMba
Manual clips
Manual clipsManual clips
Manual clips
workhome
 
Introdução a python módulo c
Introdução a python   módulo cIntrodução a python   módulo c
Introdução a python módulo cJader Gabriel
 
Import python
Import pythonImport python
Import python
josenildoaf
 
デザイナーがTkinterで遊んでみました。
デザイナーがTkinterで遊んでみました。デザイナーがTkinterで遊んでみました。
デザイナーがTkinterで遊んでみました。
Chachamaru
 
Creating masterpieces with raphael
Creating masterpieces with raphaelCreating masterpieces with raphael
Creating masterpieces with raphael
Pippi Labradoodle
 
Python Programming - III. Controlling the Flow
Python Programming - III. Controlling the FlowPython Programming - III. Controlling the Flow
Python Programming - III. Controlling the Flow
Ranel Padon
 
Python Programming - VII. Customizing Classes and Operator Overloading
Python Programming - VII. Customizing Classes and Operator OverloadingPython Programming - VII. Customizing Classes and Operator Overloading
Python Programming - VII. Customizing Classes and Operator OverloadingRanel Padon
 
Py S60
Py S60Py S60
Py S60
Jonh Edson
 
Python Programming - IX. On Randomness
Python Programming - IX. On RandomnessPython Programming - IX. On Randomness
Python Programming - IX. On RandomnessRanel Padon
 
Python Programming - XI. String Manipulation and Regular Expressions
Python Programming - XI. String Manipulation and Regular ExpressionsPython Programming - XI. String Manipulation and Regular Expressions
Python Programming - XI. String Manipulation and Regular ExpressionsRanel Padon
 
Python Programming - VIII. Inheritance and Polymorphism
Python Programming - VIII. Inheritance and PolymorphismPython Programming - VIII. Inheritance and Polymorphism
Python Programming - VIII. Inheritance and PolymorphismRanel Padon
 
Power and Elegance - Leaflet + jQuery
Power and Elegance - Leaflet + jQueryPower and Elegance - Leaflet + jQuery
Power and Elegance - Leaflet + jQuery
Ranel Padon
 
Python Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsPython Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsRanel Padon
 
Python Programming - V. Sequences (List and Tuples) and Dictionaries
Python Programming - V. Sequences (List and Tuples) and DictionariesPython Programming - V. Sequences (List and Tuples) and Dictionaries
Python Programming - V. Sequences (List and Tuples) and Dictionaries
Ranel Padon
 
Python Programming - XII. File Processing
Python Programming - XII. File ProcessingPython Programming - XII. File Processing
Python Programming - XII. File ProcessingRanel Padon
 
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Ranel Padon
 

Viewers also liked (20)

Mba
MbaMba
Mba
 
Manual clips
Manual clipsManual clips
Manual clips
 
Introdução a python módulo c
Introdução a python   módulo cIntrodução a python   módulo c
Introdução a python módulo c
 
Import python
Import pythonImport python
Import python
 
デザイナーがTkinterで遊んでみました。
デザイナーがTkinterで遊んでみました。デザイナーがTkinterで遊んでみました。
デザイナーがTkinterで遊んでみました。
 
Python IDE Roundup
Python IDE RoundupPython IDE Roundup
Python IDE Roundup
 
Creating masterpieces with raphael
Creating masterpieces with raphaelCreating masterpieces with raphael
Creating masterpieces with raphael
 
Python Programming - III. Controlling the Flow
Python Programming - III. Controlling the FlowPython Programming - III. Controlling the Flow
Python Programming - III. Controlling the Flow
 
Python Programming - VII. Customizing Classes and Operator Overloading
Python Programming - VII. Customizing Classes and Operator OverloadingPython Programming - VII. Customizing Classes and Operator Overloading
Python Programming - VII. Customizing Classes and Operator Overloading
 
Py S60
Py S60Py S60
Py S60
 
Python Programming - IX. On Randomness
Python Programming - IX. On RandomnessPython Programming - IX. On Randomness
Python Programming - IX. On Randomness
 
Python Programming - XI. String Manipulation and Regular Expressions
Python Programming - XI. String Manipulation and Regular ExpressionsPython Programming - XI. String Manipulation and Regular Expressions
Python Programming - XI. String Manipulation and Regular Expressions
 
Python Programming - VIII. Inheritance and Polymorphism
Python Programming - VIII. Inheritance and PolymorphismPython Programming - VIII. Inheritance and Polymorphism
Python Programming - VIII. Inheritance and Polymorphism
 
Introducción a dr racket
Introducción a dr racketIntroducción a dr racket
Introducción a dr racket
 
Power and Elegance - Leaflet + jQuery
Power and Elegance - Leaflet + jQueryPower and Elegance - Leaflet + jQuery
Power and Elegance - Leaflet + jQuery
 
Python Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsPython Programming - VI. Classes and Objects
Python Programming - VI. Classes and Objects
 
Python Programming - V. Sequences (List and Tuples) and Dictionaries
Python Programming - V. Sequences (List and Tuples) and DictionariesPython Programming - V. Sequences (List and Tuples) and Dictionaries
Python Programming - V. Sequences (List and Tuples) and Dictionaries
 
Python Programming - XII. File Processing
Python Programming - XII. File ProcessingPython Programming - XII. File Processing
Python Programming - XII. File Processing
 
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
 
An introduction-to-tkinter
An introduction-to-tkinterAn introduction-to-tkinter
An introduction-to-tkinter
 

Similar to The Synergy of Drupal Hooks/APIs (Custom Module Development with ChartJS)

Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
Gil Fink
 
Drupal Javascript for developers
Drupal Javascript for developersDrupal Javascript for developers
Drupal Javascript for developers
Dream Production AG
 
SharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure FunctionsSharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure Functions
Sébastien Levert
 
13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS
DrupalMumbai
 
Boosting Your Productivity, with Backbone & RactiveJS
Boosting Your Productivity, with Backbone & RactiveJS Boosting Your Productivity, with Backbone & RactiveJS
Boosting Your Productivity, with Backbone & RactiveJS
Gabriel Gottgtroy Zigolis
 
Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8
Angela Byron
 
Getting Started with DrupalGap
Getting Started with DrupalGapGetting Started with DrupalGap
Getting Started with DrupalGap
Alex S
 
Fapi
FapiFapi
Drupal training-by-ruchiwebsolutions
Drupal training-by-ruchiwebsolutionsDrupal training-by-ruchiwebsolutions
Drupal training-by-ruchiwebsolutions
php2ranjan
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
Gil Fink
 
"Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ...
"Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ..."Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ...
"Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ...
DrupalCamp Kyiv
 
Everything You Need to Know About the Top Changes in Drupal 8
Everything You Need to Know About the Top Changes in Drupal 8Everything You Need to Know About the Top Changes in Drupal 8
Everything You Need to Know About the Top Changes in Drupal 8
Acquia
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
Jussi Pohjolainen
 
Angular JS2 Training Session #2
Angular JS2 Training Session #2Angular JS2 Training Session #2
Angular JS2 Training Session #2
Paras Mendiratta
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
Shabir Ahmad
 
DrupalGap. How to create native application for mobile devices based on Drupa...
DrupalGap. How to create native application for mobile devices based on Drupa...DrupalGap. How to create native application for mobile devices based on Drupa...
DrupalGap. How to create native application for mobile devices based on Drupa...
DrupalCampDN
 
DrupalGap. How to create native application for mobile devices based on Drupa...
DrupalGap. How to create native application for mobile devices based on Drupa...DrupalGap. How to create native application for mobile devices based on Drupa...
DrupalGap. How to create native application for mobile devices based on Drupa...
Alex S
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet CampPuppet
 

Similar to The Synergy of Drupal Hooks/APIs (Custom Module Development with ChartJS) (20)

Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Drupal Javascript for developers
Drupal Javascript for developersDrupal Javascript for developers
Drupal Javascript for developers
 
SharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure FunctionsSharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure Functions
 
13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS 13th Sep, Drupal 7 advanced training by TCS
13th Sep, Drupal 7 advanced training by TCS
 
Boosting Your Productivity, with Backbone & RactiveJS
Boosting Your Productivity, with Backbone & RactiveJS Boosting Your Productivity, with Backbone & RactiveJS
Boosting Your Productivity, with Backbone & RactiveJS
 
Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8Top 8 Improvements in Drupal 8
Top 8 Improvements in Drupal 8
 
Getting Started with DrupalGap
Getting Started with DrupalGapGetting Started with DrupalGap
Getting Started with DrupalGap
 
Fapi
FapiFapi
Fapi
 
JS Essence
JS EssenceJS Essence
JS Essence
 
Drupal training-by-ruchiwebsolutions
Drupal training-by-ruchiwebsolutionsDrupal training-by-ruchiwebsolutions
Drupal training-by-ruchiwebsolutions
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
"Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ...
"Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ..."Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ...
"Paragraphs are more powerful than you can expect" from Vasily Jaremchuk for ...
 
Everything You Need to Know About the Top Changes in Drupal 8
Everything You Need to Know About the Top Changes in Drupal 8Everything You Need to Know About the Top Changes in Drupal 8
Everything You Need to Know About the Top Changes in Drupal 8
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Angularjs
AngularjsAngularjs
Angularjs
 
Angular JS2 Training Session #2
Angular JS2 Training Session #2Angular JS2 Training Session #2
Angular JS2 Training Session #2
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
DrupalGap. How to create native application for mobile devices based on Drupa...
DrupalGap. How to create native application for mobile devices based on Drupa...DrupalGap. How to create native application for mobile devices based on Drupa...
DrupalGap. How to create native application for mobile devices based on Drupa...
 
DrupalGap. How to create native application for mobile devices based on Drupa...
DrupalGap. How to create native application for mobile devices based on Drupa...DrupalGap. How to create native application for mobile devices based on Drupa...
DrupalGap. How to create native application for mobile devices based on Drupa...
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
 

More from Ranel Padon

Views Unlimited: Unleashing the Power of Drupal's Views Module
Views Unlimited: Unleashing the Power of Drupal's Views ModuleViews Unlimited: Unleashing the Power of Drupal's Views Module
Views Unlimited: Unleashing the Power of Drupal's Views Module
Ranel Padon
 
Python Programming - XIII. GUI Programming
Python Programming - XIII. GUI ProgrammingPython Programming - XIII. GUI Programming
Python Programming - XIII. GUI ProgrammingRanel Padon
 
PyCon PH 2014 - GeoComputation
PyCon PH 2014 - GeoComputationPyCon PH 2014 - GeoComputation
PyCon PH 2014 - GeoComputationRanel Padon
 
Python Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and AssertionsPython Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and AssertionsRanel Padon
 
Python Programming - II. The Basics
Python Programming - II. The BasicsPython Programming - II. The Basics
Python Programming - II. The Basics
Ranel Padon
 
Python Programming - I. Introduction
Python Programming - I. IntroductionPython Programming - I. Introduction
Python Programming - I. Introduction
Ranel Padon
 
Of Nodes and Maps (Web Mapping with Drupal - Part II)
Of Nodes and Maps (Web Mapping with Drupal - Part II)Of Nodes and Maps (Web Mapping with Drupal - Part II)
Of Nodes and Maps (Web Mapping with Drupal - Part II)
Ranel Padon
 
Web Mapping with Drupal
Web Mapping with DrupalWeb Mapping with Drupal
Web Mapping with DrupalRanel Padon
 

More from Ranel Padon (8)

Views Unlimited: Unleashing the Power of Drupal's Views Module
Views Unlimited: Unleashing the Power of Drupal's Views ModuleViews Unlimited: Unleashing the Power of Drupal's Views Module
Views Unlimited: Unleashing the Power of Drupal's Views Module
 
Python Programming - XIII. GUI Programming
Python Programming - XIII. GUI ProgrammingPython Programming - XIII. GUI Programming
Python Programming - XIII. GUI Programming
 
PyCon PH 2014 - GeoComputation
PyCon PH 2014 - GeoComputationPyCon PH 2014 - GeoComputation
PyCon PH 2014 - GeoComputation
 
Python Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and AssertionsPython Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and Assertions
 
Python Programming - II. The Basics
Python Programming - II. The BasicsPython Programming - II. The Basics
Python Programming - II. The Basics
 
Python Programming - I. Introduction
Python Programming - I. IntroductionPython Programming - I. Introduction
Python Programming - I. Introduction
 
Of Nodes and Maps (Web Mapping with Drupal - Part II)
Of Nodes and Maps (Web Mapping with Drupal - Part II)Of Nodes and Maps (Web Mapping with Drupal - Part II)
Of Nodes and Maps (Web Mapping with Drupal - Part II)
 
Web Mapping with Drupal
Web Mapping with DrupalWeb Mapping with Drupal
Web Mapping with Drupal
 

Recently uploaded

Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 

Recently uploaded (20)

Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 

The Synergy of Drupal Hooks/APIs (Custom Module Development with ChartJS)

  • 1. The Synergy of Drupal Hooks/APIs Custom Chart Block Engr. Ranel O. Padon Drupal Summer Camp PH 2015
  • 2. About Me •  Software Engineer at Kite Systems (Hong Kong-based company) –  full-time Drupal developer for CNN Travel (our client) •  part-time Python lecturer in University of the Philippines •  involved with programming for 9 years (Python, Java, etc) •  involved in Drupal for the last 3 years •  projects: http://github.com/ranelpadon •  plays football/futsal
  • 3. Coverage/Use Cases •  Block API: create, enable, display, update, save •  Form API: textarea, select list, checkbox, textfield •  variable_get, variable_set, variable_del •  EntityFieldQuery API •  hook_menu, drupal_get_form, system_settings_form •  JSON menu callback: drupal_json_output •  Render API: #markup, #attached •  drupal_get_path •  Extending Drupal Behaviors (attach function) •  Drupal.settings JS object
  • 4. Drupal Hooks/APIs •  There is beauty and synergy in Drupal functions. •  Synergy the interaction of elements that when combined produce a total effect that is greater than the sum of the individual elements, contributions, etc.
  • 5. Drupal Hooks/APIs •  Individual Drupal functions are boring and not that useful, but their combinations are interesting and very powerful.
  • 6. CNN Travel Blocks •  if you go to the CNN Travel site: http://travel.cnn.com you’ll notice that we have so many blocks in the front page •  blocks add valuable information to the site and creates more visual interest to your page •  recently, we’ve implemented a block that features our partner hotels
  • 11. Learning Curve In the beginning of any learning, while you're on the long, flat part of the curve, you put in great amounts of time and effort, but see little in the way of results. Persistent practice helps you move along the learning curve until you hit that sweet spot—about 80% of the way into the process—where the curve starts to rise sharply, and results come easily. http://bruceelkin.hubpages.com/hub/10-000-Hours--The-Awesome- Power-of-Practice
  • 12. Learning Curve in most field of learning (sports, programming, music, etc), there are many tutorials/exercises about the basic skills, but relatively few about the ‘intermediate’ skills this presentation will try to fill the knowledge gap for Drupal devs by exposing some of the most useful functions partner hotels block is an interesting block and a good Drupal development exercise since its implementation involves lots of Drupal hooks/functions
  • 13. Learning Curve •  there are 403 hooks in Drupal 7 core alone and hundreds/thousands of related/utility functions •  but you only need a handful of them to be productive •  knowing 10-20 of the most useful functions could boost your productivity •  I’ll showcase the value of some of the Drupal functions/use cases by creating a simpler and related version of Partner Hotels block
  • 14. Summer Camp Module •  summercamp •  summercamp.info •  summercamp.module
  • 15. Summer Camp Module •  Info Files •  contains metadata/info about the name description, version, package/group, etc of the module
  • 16. Summer Camp Module •  Info Files •  similar to php.ini file •  comments preceded by a semicolon (;) •  more details: https://www.drupal.org/node/542202
  • 17. Summer Camp Module •  summercamp.info •  name and core version are the minimum info needed
  • 18. Summer Camp Module •  summercamp.module •  contains PHP/Drupal variables/functions/hooks •  more details: https://www.drupal.org/node/1074360
  • 19. Summer Camp Module •  summercamp •  summercamp.info •  summercamp.module •  the module could now be enabled in admin/modules page
  • 20. Implementing a Block •  Register: hook_block_info() •  Display: hook_block_view() •  Update: hook_block_configure() •  Save: hook_block_save()
  • 21. Hook_Block_Info •  summercamp.module •  register a new block, enable it, assign to right sidebar
  • 22. Hook_Block_Info •  the block will now appear in block admin page
  • 23. Hook_Block_View •  summercamp.module •  if the currently passed/processed block is our target, set its Title and Contents
  • 24. The Rendered Block •  the block will now show in the right sidebar. J
  • 25. Hook_Block_Configure •  to make the block contents editable in Admin UI, we could use the hook_block_configure(). •  but we need a persistent storage/table for its contents •  we could use the handy Variable table built-in in Drupal
  • 26. Variable table there are 29 variables by default in Drupal 7.37 maintenance_mode is just inserted for demo of this presentation
  • 27. Variable table •  we could easily manipulate values in the Variable table, without using SQL directly: OPERATION DRUPAL FUNCTION Create/Update   variable_set()   Read   variable_get()   Delete   variable_del()
  • 28. Variable table •  variable_set(NAME, VALUE ) •  variable_get(NAME, DEFAULT_VALUE) •  variable_del(NAME)
  • 29. Variable table •  Variable table is very valuable •  There’s an Easter Egg in Drupal.org J •  https://www.drupal.org/files/my_tombstone.jpg
  • 30. Hook_Block_Configure •  we need a way to edit the block contents
  • 31. Hook_Block_Configure •  editing the block contents is now possible, but changes will still not be saved.
  • 32. Hook_Block_Save •  we’ll use the another hook to save the edits
  • 33. Hook_Block_View •  and adjust the hook_block_view to make use of the saved content
  • 34. Hook_Block_Save •  edit the block content, save the changes, the rendered block will be updated.
  • 35. Charts •  we’ll use the ChartJS since it’s open-source, simple to use, has clean syntax, and mobile-friendly: http://www.chartjs.org/
  • 36. ChartJS Page •  include the ChartJS script •  create a CANVAS element in a page •  set the input data •  convert the CANVAS element to a chart object against the input data
  • 37. ChartJS Page •  include the ChartJS script •  select version from here: •  https://cdnjs.com/libraries/chart.js •  latest version: •  https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.js
  • 38. ChartJS Page •  create a CANVAS element in the page
  • 39. ChartJS Page •  set the input data
  • 40. ChartJS Page •  convert the CANVAS element to a chart object against the input data
  • 41. ChartJS Page •  convert the CANVAS element to a chart object against some input data.
  • 42. ChartJS Page •  the rendered chart and the hovered value.
  • 43. ChartJS Page •  we could add hover effects: highlight and label
  • 44. Chart Block •  how do we display a chart in a Drupal block? •  we need to satisfy these conditions again: •  include the ChartJS script •  create a CANVAS element in a page •  set the input data •  convert the CANVAS element to a chart object against the input data
  • 45. Chart Block •  we’ll focus first on the input data •  we need a JSON data from Drupal •  we’ll create 3 articles and broadcast them as JSON objects
  • 46. Data Source: Create 3 Articles •  Article 1 –  Tags: ‘alpha’ –  Body: ‘Lorem Ipsum 1’ •  Article 2 –  Tags: ‘beta’ –  Body: ‘Lorem Ipsum 2’ •  Article 3 –  Tags: ‘alpha’ –  Body: ‘Lorem Ipsum 3’
  • 47. EntityFieldQuery API •  create a helper function to retrieve the articles •  we’ll use the powerful and flexible EFQ API
  • 49. Hook_Menu | JSON Output •  bind the function to a menu •  encode the _get_articles() output to JSON •  set the access permission to use
  • 50. Hook_Menu •  Make sure to clear the Drupal cache to register and activate the newly created menu
  • 51. •  the JSON data will now be accessible •  you might want to use Chrome’s JSON Formatter
  • 52. Hook_Block_View | #Markup •  insert a CANVAS element •  convert ‘content’ to array structure •  insert a ‘#markup’ property/array key •  set the block markup
  • 53. Hook_Block_View | #Attached •  insert the ChartJS script •  attach a new JS file to the ‘content’ •  set the JS data/src •  set the data as external script
  • 54. Drupal Behaviors | Driver File •  implement the ChartJS driver file •  create a new Drupal behavior, define the ‘attach’-mode function •  let’s use first the previous, non-Drupal sample chart codes
  • 55. •  implement the ChartJS driver file •  attach a new JS file to the ‘content’ •  set the JS data/src •  set the data as a local file
  • 56. Hook_Block_View | #Attached •  insert the ChartJS driver •  attach a new JS file to the ‘content’ •  set the JS data/src •  set the data as a local file
  • 57. Chart Block •  the chart will now be rendered in the block J
  • 58. Drupal Behaviors | Driver File •  adjust the ChartJS driver •  fetch the Articles JSON as the input data •  convert the chart renderer to a function •  will be used in a JSON function callback
  • 59.
  • 60.
  • 61. Chart Block | Articles •  the articles’ JSON data will now be rendered
  • 62. Injecting JS | #Attach •  note that the main advantage of #attach compared to drupal_add_js() is that they are ‘alterable’ since they are inserted as array elements •  same justification applies for drupal_add_css() •  #attach is also used in Drupal 8. •  you could alter the #attached JS/CSS files using hook_js_alter() and hook_css_alter()
  • 63.
  • 64. Creating an Admin Page •  there are times you’ll need to have some admin page for inputting custom site settings/configurations •  for instance, you’ll like to control if you would like to show the chart labels, have an text field entry for the chart colors or highlight colors, a way to select the chart type, a way to use other chart script, and so on.
  • 65. Creating an Admin Page •  use case: we want to select the chart type to display •  the user could choose to display a Pie or Doughnut chart
  • 66. Creating an Admin Page •  requires a hook_menu that will call a page element generated using Form API •  input site/form data could be saved in the Variable table using the handy system_settings_form().
  • 67. Target Menu and Admin Page
  • 79. SummerCamp Module Repo •  I’ve already implemented the repo in GitHub and added more blocks and features: •  https://github.com/ranelpadon/summercamp •  showcases ChartJS, Panoramio API, and GitHub’s Gist API. •  implements blocks using theme function and template file •  demonstrates processing JSON data in back-end and front-end •  and more..
  • 81. Recommendations •  Drupal Development Tools •  Essential and Effective Drupal Tools •  http://befused.com/drupal/essential-tools
  • 82. Recommendations •  Drupal Development Books •  Master Drupal 7 Module Development by Wadman •  http://befused.com/master-drupal/ •  Drupal 7 Module Development by Butcher, et al.
  • 83. Special Thanks •  CNN Travel (http://travel.cnn.com) for the ideas and inspiration for this presentation.
  • 84. There is beauty in Drupal.