Drupalcon kickstart module development

From Colettapedia
Jump to navigation Jump to search
  • selecting modules that are distributed - acquia drupal.
  • Drupal.org customizations
  • need.info (ini format key value pairs) and .module (php)

implement hooks

  • a function named with defined patter, with certain arguments
  • whenever drupal needs it, it will be called
  • sites-> all->modules -> modulename: modulename.info and modulename.module

Example

  • implement hook_link()
function quicklink_link(...)
{
  if( $type == 'node' && user_access(...)) {
    $links['quicklink_node_delete'] = array(
     'title' => 'delete this post',  // title means the link text
      'href' => 'node/' . $object->nid . 'delete',
      'attributes' => array(
        'title' => t( 'Jump to deleting this post'), // the hover attribute
      // you can also alter these links
     }
  return $links;
}

another example

  • forms api
function search_box( &$form_state, $form_id ){
  $form[$form_id] = array(
    '#title' => ...

 $form['#submit'] = 
  • hook_form_alter()
finction site_section_form_alter(..)

if( $node = menu_get_object('node'))

  $key = some text
   $text = array ( node_get_types('name', $node)

   //add stuff to $form to be accessed later
   $form['site_section' = array of stuff;
  //overrride overwrite submit
  $form['submit'] = site_section_search_submit // custom function.

contact form example: add category pulldown

function drupaltown_form_alter (...)
  if( $form_id == 'contact_mail_page' )
    form['message']['#rows'] = 20..
    // move category to the top
    $form'contact_information']['#weight'] = -1


  //contact/exhibitions path
  $contacts = arg(1); // $contacts = exhibitions

digital whiteboard

  • add new page
function drupaltown_menu()
  $items['whiteboard'] = array(
  'title'=> 'Whitebord'
    //'access callback
  • the callback
fucntion drupaltown_whiteboard_page()

find the hooks

  • module_invoke_all( 'my module suffix') //hey every module out there i did something
  • first parameter names the hook
  • drupal_alter()

links