think like a drupal developer

25
Drupalcamp Atlanta 2011 Think Like a Drupal Developer Erik Webb Technical Consultant, Acquia Drupalcamp Atlanta 2011

Upload: erik-webb

Post on 08-May-2015

2.795 views

Category:

Technology


1 download

DESCRIPTION

Drupal is hard. It's not just a CMS, it's not just a framework, it has the power of both and the simplicity of neither. So where do you get started?This session will bring developers new to Drupal up-to-speed on exactly what they need to know to tackle that next big Drupal project. You will learn not about the newest and greatest modules and performance tricks, but instead about how a Drupal developers thinks and solve problems. Once you understand what Drupal wants from you, it's much easier to conquer any crazy requirement a client may give.The best Drupal developers are lazy developers. Meaning that they only develop what's necessary to solve the problem and use the wealth of contributed modules to help them get there. Many new developers coming from handmade web sites tend to over-develop and waste time solving problems others have already solved or problems Drupal can already solve for you. This session will make you more efficient, saving you time and helping you get your projects out the door faster!

TRANSCRIPT

Page 1: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Think  Like  a  Drupal  Developer

Erik WebbTechnical Consultant, Acquia

Drupalcamp Atlanta 2011

Page 2: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Who  am  I?

• Joined Acquia in April 2010

• 30+ clients in almost 2 dozen states

• Systems administrator background (RHCE)

• LAMP development (10+ years PHP)

• Go Jackets!

Page 3: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Who  are  you?

Page 4: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Drupal  is  hard.  It's  not  just  a  CMS,  it's  not  just  a  framework,  it  has  the  power  of  both  and  the  simplicity  of  neither.  So  where  do  you  get  started?

Page 5: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

How  Drupal  works

1. Lookup URL in aliases, menu router

2. Check for cached page

3. Check permissions for page

4. Run page callback

5. Process render array

Page 6: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

What  Drupal  Can  Do

• Managing lots of structured data

• Strictly manage access to content and functionality

• Providing an organized administration section

• Allowing themers great flexibility

• Using common page layouts

Page 7: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Coders  vs.  Builders

• We’re all developers

• Good Drupal developers are “lazy”• Efficiency beats all

• Enjoy your weekends!

• Trust the community

• Rethink problems, not solutions

Page 8: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Building  vs.  Coding

• Building• Flatter learning curve

• Easier transition for “web developers”

• More maintainable*

• Dependent on community

• Book learnin’

• Faster development

• Reusable solutions

• Coding• Steep learning curve

• Easier transition for programmers

• Less maintainable*

• Customized to client

• Blood, sweat, & tears

• Faster performance*

• One-off advantages

Page 9: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

What  to  code

Page 10: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Modifying  Forms

• hook_form_alter(), hook_form_FORM_ID_alter()

• Administrative and user-facing forms

• Examples• Making individual fields required

• Changing order of fields

• Adding help text

• Additional validation or submission handlers

Page 11: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Changing  Nodes

• Structure• hook_node_view()

• Add new data

• Modify existing data

• Change data in all places

• Presentation• template_preprocess_nod

e()

• Reformat data

• Combine into pseudo-fields

• NEVER alter data, treat as read-only

Page 12: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Menu  Manipulation

• hook_menu_alter()

• Change menu properties• Hide links globally

• Change title

• Change permissions

• Override callbacks

• Efficient, runs only on cache clear

Page 13: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

When  to  code  or  build

Page 14: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Content  Aggregation

• Views• Graphical setup

• Community-driven

• Built-in caching

• Many display options

• Efficient prototyping

• EntityFieldQuery• Full control*

• Low overhead

• Extremely Drupal-specific

• No SQL!

• Combine with Entity Load Cache*

Page 15: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Contextual  Changes

• Context module• Flexible API

• Easily exportable to code

• Extendable by non-coders

• hook_boot(), hook_init()

• Completely custom

• Performance-focused

• Handling condition and reactions

Page 16: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Examples

Page 17: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Client:  Anytime  an  anonymous  user  visits  a  news  article,  I  want  to  show  them  a  modal  with  a  subscription  link.

Page 18: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Use  Context

• Wrong way• template_preprocess_node() to add JS in a theme

• Right way• Create a modal reaction for Context

• Why not use hook_boot()?

• Right way• Use pure JavaScript to check for body.logged-in CSS class

Page 19: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Client:  I  don’t  want  anonymous  users  seeing  any  content  tagged  with  the  “Internal”  keyword.

Page 20: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Nodes  are  everywhere!

• Wrong way• hook_node_access() doesn’t affect the menu

• Wrong way• Override ‘access callback’ for URL ‘node/%’

• Wrong way• hook_node_view() returns drupal_access_denied()

• Right way• hook_node_access_records() changes all node accessing

Page 21: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Client:  I  want  all  checkboxes  to  be  those  cool  image  buttons  instead  of  the  normal  checks.

Page 22: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Form  altering  isn’t  always  the  right  way

• Wrong way• Use CSS/JS to change input[type=”checkbox”]

• Wrong way• Use hook_form_alter() to change the ‘#theme’ property for

all checkboxes to your theme function

• Right way• Simply create modulename_checkbox() to override all uses

of the form element

Page 23: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Client:  I  want  to  incorporate  my  company-­‐wide  header/masthead  into  my  Drupal  site.

Page 24: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

iframe?  What  is  this,  1999?

• Wrong way• Hard code into an include file in your theme

• Wrong way• Recreate the header using Drupal’s menu system and CSS

• Right way• Create a JS include somewhere else

• Right way• Use a web service to retrieve the HTML (and cache it!)

Page 25: Think Like a Drupal Developer

Drupalcamp Atlanta 2011

Questions?

Ask me - @erikwebb on Twitter