Code Snippets

AHAH Helper

The AHAH Helper module eases the work when developing AHAH powered forms. More information about the AHAH Helper can be found here.
 

An example of a problem can be when creating a form that initially displays a drop-down and a submit button. When a user selects on of the valid options, another drop-down is displayed with additional options which is associated with what the user has selected. The solution to this problem is the code shown below.

function MY_MODULE_NAME_ahah_powered_form($form_state) {
  $form = array();
	
  /*  register your form */
  ahah_helper_register($form, $form_state);
	
  if(!isset($form_state['storage']['classification']['type'])) {
    $type_default_value = 0;
    } else {
    $type_default_value = $form_state['storage']['classification']['type'];
  }
	
  if(!isset($form_state['storage']['classification']['animal'])) {
    $animal_default_value = 0;
  } else {
    $animal_default_value = $form_state['storage']['classification']['animal'];
  }
	
  /* sample drop-box options */
  $type_options = array(
    0 => 'Choose Animal Type',
    1 => 'Invertebrates',
    2 => 'Vertebrates'
  );
  $animal_options[1] = array(
    0 => 'Choose Animal',
    3 => 'Mollusks',
    4 => 'Arthropods'
  );
  $animal_options[2] = array(
    0 => 'Choose Animal',
    5 => 'Fish',
    6 => 'Amphibians'
  );
	
  $form['classification'] = array(
    '#type'   => 'fieldset',
    '#title'  => t(''),
    '#prefix' => '
', '#suffix' => '
',
    /* Don't forget to set #tree! */
    '#tree'   => TRUE, 
  );
  $form['classification']['type'] = array(
    '#type'          => 'select',
    '#title'         => '',
    '#default_value' => $type_default_value,
    '#options'       => $type_options,
    '#ahah'          => array(
    'event'   => 'change',
    'wrapper' => 'classification',
      /* This is the "magical path". Note that the parameter is an array of
       the parents of the form item of the wrapper div! */
    'path'    => ahah_helper_path(array('classification')),
    ),
  );
	
  /* display if user has selected animal type */
  if($type_default_value) {
    $form['classification']['animal'] = array(
      '#type'          => 'select',
      '#title'         => '',
      '#default_value' => $animal_default_value,
      '#options'       => $animal_options[$type_default_value],
    );
  }
	
  $form['classification']['go'] = array(
    '#type'  => 'submit',
    '#value' => t('Go'),
  );
  return $form;	
}
- See more at: http://www.appnovation.com/blog/ahah-made-easy-ahah-helper#sthash.DK7HOqkv.dpuf
 
 
yum install rsync

Once Rsync is installed. You can type rsync -man to see all the options available to it. Here is an example of Rsync:

rsync -r -v username@servername.com:/var/www/vhosts/site1/ /var/www/vhosts/site2

This example will merge the code from site1 on the remote server to site2 on my local. Using the -v specifies verbose and -r is recursive.

rsync -r -v --exclude “sites/default/files” username@servername.com:/var/www/vhosts/site1/ /var/www/vhosts/site2

This example will merge the code from site 1 to site2 but will also exclude the directory “sites/default/files”.

Resource Tags: