Top Banner
drupal-6.9.tar.gz 1052 KB
36

Advanced Module development

Dec 12, 2014

Download

Technology

drupalindia

This presentation will be delivered by Sumeet pareek on 31st jan'09 at drupal camp india.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Advanced Module development

drupal-6.9.tar.gz 1052 KB

Page 2: Advanced Module development

CMS+

framework+

Community

Page 3: Advanced Module development

Getting Involved!

Page 4: Advanced Module development

do (drupal_module_development) or die(a_noob);

/* Btw.. That is the official title of this talk. */

Page 5: Advanced Module development

Hooks

Page 6: Advanced Module development

Drupal APIhttp://api.drupal.org/

Page 7: Advanced Module development

Seek the purpose

You got to answer some questions.|

a good starting point|

What do I want to do?

Page 8: Advanced Module development

Answers to be found

1. The end user should be able to do this ___________ .

2. __________ be done to the end user.

3. All corollaries of #1 and #2

After all..

Page 9: Advanced Module development

end user

Page 10: Advanced Module development

Lets say we want…User account page

Member Since:3weeks 2days

Has role ‘lucky’:expires in 13 more days

Has role ‘geek’:Never expires

BLAH.. BLAH…

<Username>

Role ‘rookie’:expires in 14 days

Role ‘content contributor’:expires in 100 days

This is how user profile page should look like to anybody visiting it.

Block displaying currently logged in users “role length” details

** we also want the user to receive ‘n’ number of automated mail notifications as he is approaching a particular role expiry.

Page 11: Advanced Module development

Some more answers to be found

1. Does the admin need to be bothered?

2. What settings/configurations ought to be exposed to the admin?

3. What is the right place (drupal path) to do this?

4. Okay.. So how should the form(s) look like?

Page 12: Advanced Module development

Lets say we want…

Page 13: Advanced Module development

Lets say we want…

Page 14: Advanced Module development

Can I do just use PnC ?

Highly recommended to evaluate if the requirements can be fullfiled by PnC of drupal core + “killer modules”

Drupal core Core – Optional modules Cck, Views, Panels et al

Page 15: Advanced Module development

Contributions!! Where? How?

There are very high chances that what you are looking for has already been developed

http://drupal.org/project/Modules http://drupalmodules.com/module-f

inder Google -> site:drupal.org/project

<search keywords> -cvs

Page 16: Advanced Module development

No Luck!!

Page 17: Advanced Module development

Time to get hands dirty !!

How?

Page 18: Advanced Module development

Make sure to look inside related modules

Related =>Modules that do things which are only slightly different or slightly similar to the things that you wound want your module to do.

Page 19: Advanced Module development

Indispensable development help

Page 20: Advanced Module development

Indispensable development help

CoderSchema

Form BuilderDevel

Page 21: Advanced Module development

Determine the schema

Requirement collection starts form the user. Development should start from the database.

Map the schema to all/any mock ups you have prepared.

Page 22: Advanced Module development

Schmea mockup

role_length

rid int

rlength int

exprid int

asg_mail text

exp_mail text

role_length_user_ roles

rid tinyint

uid int

asg_time timestamp

expmail_sent text

Page 23: Advanced Module development

Map schema to everything else in the UI mockups just created

Page 24: Advanced Module development

role_length

rid int

rlength int

exprid int

asg_mail text

exp_mail text

role_length_user_roles

rid tinyint

uid int

asg_time timestamp

expmail_sent text

User account page

Member Since:3weeks 2days

Has role ‘lucky’:expires in 13 more days

Has role ‘geek’:Never expires

BLAH.. BLAH…

<Username>

Role ‘rookie’:expires in 14 days

Role ‘content contributor’:expires in 100 days

** we also want the user to receive ‘n’ number of mail notifications as he is approaching a particular role expiry.

Check if we have all the data that we need. * Avoid redundancy. There is a lot of data in tables not created by the module being developed.

Page 25: Advanced Module development

Creating .info and .install files Use dependencies only when core functionality of your module

depends upon other modules ELSE use module_exists()

Schema API ? http://api.drupal.org/api/function/hook_install http://api.drupal.org/api/function/hook_uninstall http://api.drupal.org/api/function/hook_install_schema http://api.drupal.org/api/function/hook_schema

Page 26: Advanced Module development

Creating .module file http://api.drupal.org/api/function/hook_help http://api.drupal.org/api/function/hook_menu

Form API ? http://api.drupal.org/api/file/form_api_reference.html/6 http://api.drupal.org/api/function/hook_form_alter AHAH !!

Page 27: Advanced Module development

Best practices to structure $form

Why are they called “best practices” ?

Page 28: Advanced Module development

How to:dynamic forms

and forms that “grow”

what is the difference!!??

Page 29: Advanced Module development

jQueryTo jazz up your forms with tool tips, pop-ins, char count et al.

AHAH FAPI + menu callbackTo ajaxify forms without changing the types of or number of elements in the form. (eg: username availability)

AHAH FAPI + menu callback + form rebuildingTo asynchronously grow the form. Adding/Removing elements or changing types of elements.

Page 30: Advanced Module development

Initially requests for the form

Build the form > Send out the rendered form > Save form state in the cache

Acts upon the AHAH element

“AHAH callback” fetches form from the cache > build it using $_POST values > Add/Removes/Modifies elements > Set the cache > Output changes as JSON

AHAH grabs the JSON response and does the magic.

Changing forms asynchronously

Page 31: Advanced Module development

Major hooks

http://api.drupal.org/api/function/hook_user Gotcha: Not implementing the case delete.

Especially dangerous when modules own tables have user related data. Just do it in the memory of node/8

http://api.drupal.org/api/function/hook_cron http://api.drupal.org/api/function/hook_block

Page 32: Advanced Module development

Tools we can use… DATABASE API http://api.drupal.org/api/function/drupal_write_records http://api.drupal.org/api/function/user_roles http://api.drupal.org/api/function/format_interval http://api.drupal.org/api/function/user_multiple_role_edit http://api.drupal.org/api/function/user_load http://api.drupal.org/api/function/drupal_mail http://api.drupal.org/api/function/watchdog

~ 2200 more

Page 33: Advanced Module development

Ain’t Drupal beautiful ?!

To keep it that waydon’t spit out your output,

theme it.

Page 34: Advanced Module development

Ta-Da!!

Lets go to node/59

Page 35: Advanced Module development

http://drupal.org/node/100748

1. Add code to CVS2. Create the project on drupal.org3. Create a release4. Add a handbook page

Page 36: Advanced Module development

May the force be with you