V používaném tématu vzhledu vytvořte (upravte) soubor template.php, do kterého vložte požadovanou funkci nalezenou přímo v Drupalu nebo na api.drupal.org:
/** * Implements HOOK_form_alter() */ function MYTHEMENAME_form_alter(&$form, &$form_state, $form_id) { //kpr($form); // require Devel modul //dpm($form_id); // require Devel modul //drupal_set_message($form_id); // print form ID to messages //drupal_set_message(print_r($form, TRUE)); // print array to messages //var_dump($form); //echo $form_id .", "; }
/** * Implements HOOK_form_FORM_ID_alter() */ function MYTHEMENAME_form_search_block_form_alter(&$form, &$form_state, $form_id) { //kpr($form); // require Devel modul //var_dump($form); //kpr(); // require Devel modul }
Např. modifikace atributů a textu tlačítek:
/** * Implements HOOK_form_alter() */ function MYMODUELNAME_form_alter(&$form, &$form_state, $form_id) { if($form_id == 'user_register') { // change submit button $form['submit']['#value'] = t('Complete the registration'); } }
/** * Implements HOOK_form_alter() */ function MYTHEMENAME_form_alter(&$form, &$form_state, $form_id) { //var_dump($form); // submit input if(isset($form['product_id']) && $form_id == 'commerce_cart_add_to_cart_form_' . $form['product_id']['#value']) { $form['submit']['#attributes']['title'] = t('Add to Wishlist'); } // 1. step of checkout if($form_id == 'views_form_commerce_cart_form_default') { $form['actions']['continue_shopping']['#value'] = t('Continue'); $form['actions']['submit']['#value'] = t('Update demand'); $form['actions']['checkout']['#value'] = t('Send demand'); } // 2. step of checkout if($form_id == 'commerce_checkout_form_checkout') { $form['buttons']['continue']['#value'] = t('Send demand'); } }
Příklad úpravy exposed filtru (#process):
/** * Custom process function **/ function MYFUNCTION_process($element, $form_state, $form) { //print('<pre>'.print_r($form,1).'</pre>'); //kpr($element); //kpr($form_state); // First element "CUSTOM_TEXT" $element['CUSTOM_TEXT'] = array( '#markup' => "<div class='my-class'>CUSTOM TEXT</div>", ); // Second element "MY_LINK" $element['MY_LINK'] = array( '#type' => 'link', '#prefix' => '<div class="MYCLASS">', '#title' => '<span>'. t('TITLE') .'</span>', '#suffix' => '</div>', '#href' => 'MYURL', '#id' => 'prev', '#ajax' => array( 'wrapper' => 'level-form', 'method' => 'html', ), '#options' => array( 'html' => true, 'fragment' => 'MY-ANCHOR', 'attributes' => array( 'title' => t('HOVER TITLE'), ), 'query' => array( 'year' => 2013, 'month' => 9, ) ), '#weight' => -10, ); return $element; }
function HOOK_form_alter(&$form, &$form_state, $form_id) { $form['date']['value']['#process'][] = 'MYFUNCTION_process'; //kpr($form); }
...