drupal is stupid (but i love it anyway)

Post on 24-Jun-2015

3.211 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

Regrettably, my machine didn't cooperate when I tried to record this presentation. I don't think the slides will do you much good without the stuff I said, but a few people asked for them.---Depending on who you ask, Drupal is either a framework or a platform, but no matter how you look at it, there are things about it that suck. Hear Brock Boland talk about the pain points of coding for Drupal 6, how things have improved in Drupal 7, and what's expected to be better in Drupal 8.

TRANSCRIPT

Drupal is Stupid(But I Love It Anyway)

Thursday, November 10, 11

oh hai

• Brock Boland, Jackson River

• @brock

• brock@brockboland.com

• GoSpringboard.com

Thursday, November 10, 11

Plan

• Drupal Overview

• What sucks

• What’s awesome

Thursday, November 10, 11

Drupal

• Open Source CMS

• 6 vs. 7

• Hook system

• Theme functions

• Contrib modules

Thursday, November 10, 11

Stupid

Thursday, November 10, 11

Core doesn’t do much

Thursday, November 10, 11

Animal Fun Fact #1

Thursday, November 10, 11

Animal Fun Fact #1

Source: http://blogs.dixcdn.com/shine_a_light/2011/02/02/love-birds/

Thursday, November 10, 11

Catch-all Hooks• hook_block()

• list, configure, save, view

• hook_taxonomy()

• delete, insert, update

• hook_comment()

• insert, update, view, validate, publish, unpublish, delete

• hook_nodeapi()

• alter, delete, delete revision, insert, load, prepare, print, rss item, search result, presave, update, update index, validate, view

Thursday, November 10, 11

No Objects

Thursday, November 10, 11

DB Layer

• Uses straight SQL queries

• db_query() and db_query_range()

• db_fetch_object() or db_fetch_array()

• drupal_write_record()

Thursday, November 10, 11

db_query("UPDATE {node_type} SET type = '%s', name = '%s', module = '%s', has_title = %d, title_label = '%s', has_body = %d, body_label = '%s', description = '%s', help = '%s', min_word_count = %d, custom = %d, modified = %d, locked = %d WHERE type = '%s'", $info->type, $info->name, $info->module, $info->has_title, $info->title_label, $info->has_body, $info->body_label, $info->description, $info->help, $info->min_word_count, $info->custom, $info->modified, $info->locked, $existing_type);

D6

$fields = array( 'type' => (string) $type->type, 'name' => (string) $type->name, 'base' => (string) $type->base, 'has_title' => (int) $type->has_title, 'title_label' => (string) $type->title_label, 'description' => (string) $type->description, 'help' => (string) $type->help, 'custom' => (int) $type->custom, 'modified' => (int) $type->modified, 'locked' => (int) $type->locked, 'disabled' => (int) $type->disabled, 'module' => $type->module, );

if ($is_existing) { db_update('node_type') ->fields($fields) ->condition('type', $existing_type) ->execute();

if (!empty($type->old_type) && $type->old_type != $type->type) { field_attach_rename_bundle('node', $type->old_type, $type->type); } module_invoke_all('node_type_update', $type); $status = SAVED_UPDATED; }

else { $fields['orig_type'] = (string) $type->orig_type; db_insert('node_type') ->fields($fields) ->execute();

field_attach_create_bundle('node', $type->type);

module_invoke_all('node_type_insert', $type); $status = SAVED_NEW; }

D7

Thursday, November 10, 11

Source: http://schoolworkhelper.net/2011/06/wolves-habitat-characteristics-behaviors/

Animal Fun Fact #2

Thursday, November 10, 11

Animal Fun Fact #2

Source: http://www.indyposted.com/135755/sarah-palin-hunting-clip-offends-some-over-animal-abuse-others-over-poor-hunting-skills-video/sarah-palin-hunting-2/

Thursday, November 10, 11

Multiple Implementation

Options

Thursday, November 10, 11

Thursday, November 10, 11

Ajax/AHAH

Thursday, November 10, 11

function ahah_callback_method() { // AHAH processing prep $form_state = array('storage' => NULL, 'submitted' => FALSE); $form_build_id = $_POST['form_build_id']; $form = form_get_cache($form_build_id, $form_state);

$args = $form['#parameters']; $form_id = array_shift($args); $form_state['post'] = $form['#post'] = $_POST; $form['#programmed'] = $form['#redirect'] = FALSE;

drupal_process_form($form_id, $form, $form_state); $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

// Now you can do stuff}

DIY

Thursday, November 10, 11

/** * Given a POST of a Drupal form (with both a form_build_id set), this * function rebuilds the form and then only renders the given form item. If no * form item is given, the entire form is rendered. * * Is used directly in a menu callback in ahah_helper's sole menu item. Can * also be used in more advanced menu callbacks, for example to render * multiple form items of the same form and return them separately. * * @param $parents */function ahah_helper_render($form_item_to_render = FALSE) { $form_state = array('storage' => NULL, 'submitted' => FALSE); $form_build_id = $_POST['form_build_id'];

// Get the form from the cache. $form = form_get_cache($form_build_id, $form_state); $args = $form['#parameters']; $form_id = array_shift($args);

// Are we on the node form? $node_form = FALSE; if (preg_match('/_node_form$/', $form_id)) { $node_form = TRUE; module_load_include('inc', 'node', 'node.pages'); }

// We will run some of the submit handlers so we need to disable redirecting. $form['#redirect'] = FALSE; // We need to process the form, prepare for that by setting a few internals // variables. $form['#post'] = $_POST; $form['#programmed'] = FALSE; $form_state['post'] = $_POST;

// $form_state['storage']['#ahah_helper']['file'] has been set, to know // which file should be loaded. This is necessary because we'll use the form // definition itself rather than the cached $form. if (isset($form_state['storage']['#ahah_helper']['file'])) { require_once($form_state['storage']['#ahah_helper']['file']); }

// If the form is being rebuilt due to something else than a pressed button, // e.g. a select that was changed, then $_POST['op'] will be empty. As a // result, Forms API won't be able to detect any pressed buttons. Eventually // it will call _form_builder_ie_cleanup(), which will automatically, yet // inappropriately assign the first in the form as the clicked button. The // reasoning is that since the form has been submitted, a button surely must // have been clicked. This is of course an invalid reasoning in the context // of AHAH forms. // To work around this, we *always* set $form_state['submitted'] to true, // this will prevent _form_builder_ie_cleanup() from assigning a wrong // button. When a button is pressed (thus $_POST['op'] is set), then this // button will still set $form_state['submitted'],

// $form_state['submit_handlers'] and $form_state['validate_handlers']. // This problem does not exist when AHAH is disabled, because then the // assumption is true, and then you generally provide a button as an // alternative to the AHAH behavior. $form_state['submitted'] = TRUE; // Continued from the above: when an AHAH update of the form is triggered // without using a button, you generally don't want any validation to kick // in. A typical example is adding new fields, possibly even required ones. // You don't want errors to be thrown at the user until they actually submit // their values. (Well, actually you want to be smart about this: sometimes // you do want instant validation, but that's an even bigger pain to solve // here so I'll leave that for later…) if (!isset($_POST['op'])) { // For the default "{$form_id}_validate" and "{$form_id}_submit" handlers. $form['#validate'] = NULL; $form['#submit'] = NULL; // For customly set #validate and #submit handlers. $form_state['submit_handlers'] = NULL; $form_state['validate_handlers'] = NULL; // Disable #required and #element_validate validation. _ahah_helper_disable_validation($form); }

// Build, validate and if possible, submit the form. drupal_process_form($form_id, $form, $form_state); if ($node_form) { // get the node from the submitted values $node = node_form_submit_build_node($form, $form_state);

// hack to stop taxonomy from resetting when the form is rebuilt $form_state['node']['taxonomy'] = taxonomy_preview_terms($node); }

// This call recreates the form relying solely on the form_state that the // drupal_process_form set up. //$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id); $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

// Get the form item we want to render. $form_item = _ahah_helper_get_form_item($form, $form_item_to_render);

// Get the JS settings so we can merge them. $javascript = drupal_add_js(NULL, NULL, 'header'); $settings = call_user_func_array('array_merge_recursive', $javascript['setting']);

drupal_json(array( 'status' => TRUE, 'data' => theme('status_messages') . drupal_render($form_item), 'settings' => array('ahah' => $settings['ahah']), ));}

ahah_helper module

Thursday, November 10, 11

Assumes You Want an HTML Page

Thursday, November 10, 11

Source: http://www.dailymail.co.uk/travel/article-1320804/Mountain-goats-climb-160ft-near-vertical-Cingino-dam.html

Animal Fun Fact #3

Thursday, November 10, 11

Source: http://www.dailymail.co.uk/travel/article-1320804/Mountain-goats-climb-160ft-near-vertical-Cingino-dam.html

Animal Fun Fact #3

Thursday, November 10, 11

Steep Learning Curve

Thursday, November 10, 11

Original source unknown

Thursday, November 10, 11

Wonky-ass Interface

Thursday, November 10, 11

Thursday, November 10, 11

Thursday, November 10, 11

Thursday, November 10, 11

Thursday, November 10, 11

Always NeedCustom Module(s)

Thursday, November 10, 11

Media Handling

Thursday, November 10, 11

Thursday, November 10, 11

Misc. Crap

• HTML5

• Mobile

• Configuration Management

• Content Migration

Thursday, November 10, 11

Still?Pretty Awesome

Thursday, November 10, 11

Stable

Thursday, November 10, 11

Secure

Thursday, November 10, 11

Contrib Modules

Thursday, November 10, 11

Community

Thursday, November 10, 11

On the Whole?

• Stupid

• Getting better

• Still not going to use anything else

Thursday, November 10, 11

Questions?Which is funnier:

Pirate Monkey, or Aviator Monkey?

jacksonriver.com/monkeys

Thursday, November 10, 11

Once more

• Brock Boland

• @brock

• brock@brockboland.com

Thursday, November 10, 11

top related