Fapi
Upcoming SlideShare
Loading in...5
×
 

Fapi

on

  • 589 views

Heavy Lifting with Drupal's FAPI - SandCamp 2011

Heavy Lifting with Drupal's FAPI - SandCamp 2011

Statistics

Views

Total Views
589
Views on SlideShare
589
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Welcome\nLet’s wait for everyone to settle\n
  • \n
  • \n
  • \n
  • \n
  • I’ve made many a module that only implements hook_form_alter\n
  • \n
  • stores the hooks in the default directory default.hooks.inc\n
  • --add Append hooks to module file. Implies '--write --build=code'. Warning: will not check hooks already exist.\n\ndrush dochooks my_module -- inserts hooks into existing modules\n\nremember to clear out unused BS before you try to run the module...\n\nHigher LEVEL\nTelling module builder about your hooks\nLots of contrib modules provide hooks. You can tell module builder about them, so users can easily generate code for your module's hooks in their own modules.\nTo do this, implement hook_module_builder_info() in a file named YOUR_MODULE.module_builder.inc file in your module folder. See the contents of module_builder.module_builder.inc for a detailed example.\n
  • so before i delve into the api itself, i thought i’d mention why i wanted to give this presentation.\n-learning curve\n-wished someone had started me here\n-because of the loop that the form api takes us through, we learn a lot about drupal, it’s hooks and, most importantly, it’s caches.\n-does anyone share this feeling?\n
  • there are a few steps\narrays not objects\n
  • \n
  • spend some time here\ncheckbox vs checkboxes\n
  • \n
  • \n
  • outside the scope of this talk\ntpl.php is reminiscent of MVC frameworks\n
  • \n
  • pass callback function as well as an array of functions for abstracting common tasks that might repeat themselves in other parts of your module and/or form processing\n\n#pre-render called before drupal_render...receives the #element as the param and must return the altered element\n#post-render 2 params “rendered element and its children”\n\nbe careful of overwriting your existing array...you can do a check to see if the properties you are after are set\n\nrules module hooks into these functions\n
  • GO TO THE SIMPLE #MARKUP, #VALUE EXAMPLE\n
  • \n
  • \n
  • \n
  • \n
  • private key is stored in the variables - best not to touch it\n\nif POST exists then we check the cache to see if there is a copy for the current session\nif YES then retrieve cached form and move on to the check if the form was submitted\nif YES we move to the validate functions\nif PASS validate run submit and process values\nif REDIRECT we are off\nif no REDIRECT then redisplay empty form with a message (hopefully)\nif NO check cace, rebuild, set cache, render form\nif NO cached copy, build form, then move to see form was submitted\nNO Post or form_build_id exists then build\n\npg 222 of Pro Drupal 6\n
  • then element_info is called\nfivestar is pretty straightforward\ntinymce modifies the default properties of the already existing textarea element - changes the #process => ‘callback function called tinymce_process_textarea’\n
  • \n
  • This hook allows modules to build multiple forms from a single form "factory" function but each form will have a different form id for submission, validation, theming or alteration by other modules.\n
  • these are the default callbacks that Drupal tries to match to your unique form id. You can set the #validate and #submit keys on the form, and form elements to instruct your callback to do something special. Those are also called during the drupal_process_form function\n
  • these are the default callbacks that Drupal tries to match to your unique form id. You can set the #validate and #submit keys on the form, and form elements to instruct your callback to do something special. Those are also called during the drupal_process_form function\n
  • show http://api.drupal.org/api/drupal/includes--form.inc/function/drupal_process_form/6\n
  • I though I’d mention hook_node_info here because it doesn’t really jive elsewhere in the presentation\n name\n module\n description\n help\naccepts array with the usual params:\nhas_title => FALSE\nhas_body\n
  • \n
  • show hook_form and the returning of the $form\n
  • \n
  • &$form\n
  • \n
  • \n
  • show Form API reference D7\nhttp://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/7\n \n FAPI integration - allows module developers to create new form components using '#type' => 'multiselect'\n\n
  • \n
  • \n

Fapi Fapi Presentation Transcript