Drupal: template.php form_alter and breadcrumb hooks

Add a Read-Only field to User Register Form

To create a read-only field on the user registration form in Drupal, for instance to add a Terms & Conditions textarea field, you must override the form_alter hook.

function _form_alter(&$form, &$form_state, $form_id) {
 if ($form_id == 'user_register_form') {
  $form['field_developer_agreement']['und'][0]['value']['#attributes']['readonly'] = 'readonly';
  $form['field_developer_agreement']['und'][0]['value']['#resizable'] = FALSE;
  $form['field_developer_agreement']['und'][0]['value']['#cols'] = 40;
 }
}


The form_id can be found by adding the following code to the form_alter hook.

function _form_alter(&$form, &$form_state, $form_id) {
 drupal_set_message("This is the form id : $form_id");
}

Modify Breadcrumb and using Breadcrumb by Path


function _breadcrumb($breadcrumb) {
$links = array();
$path = '';
// Get URL arguments
$arguments = explode('/', request_uri());
// Remove empty values
foreach ($arguments as $key => $value) {
  if (empty($value)) {
   unset($arguments[$key]);
  }
 }
 $arguments = array_values($arguments);
 // Add a 'Home' link to breadcrumb
 $links[] = l(t('Home'), '');
 // Add other links
 if (!empty($arguments)) {
  foreach ($arguments as $key => $value) {
   // Don't make last breadcrumb a link but set to page title
   if ($key == (count($arguments) - 1)) {
    // if last breadcrumb
    $links[] = drupal_get_title();
   } else {
    // create path to set link
    if (!empty($path)) {
     $path .= '/'. $value;
    } else {
     $path .= $value;
    }
    // customize format of breadcrumb values
    // replace hyphens by spaces
    $cvalue =str_replace('-', ' ', $value);
    // create linked breadcrumb value
    $links[] = l(ucwords($cvalue), $path);
   }
  }
 }
}

Leave a Reply

Your email address will not be published. Required fields are marked *