Aller au contenu principal
loading

Comment modifier le formulaire de recherche Drupal (Theme Drupal Search form)

POSTÉ DANS Drupal 7 TAGS Drupal 7 AUTEUR herve COMMENTAIRES 2

Voila comment modifier le formulaire de recherche Drupal pour ajouter les CSS et le texte que l'on souhaite :

 

/**
* Override or insert PHPTemplate variables into the search_theme_form template.
*
* @param $vars
*   A sequential array of variables to pass to the theme template.
* @param $hook
*   The name of the theme function being called (not used in this case.)
*/
  
function montheme_preprocess_search_theme_form(&$vars, $hook) {
  
  // Modify elements of the search form
  $vars['form']['search_theme_form']['#title'] = t('Recherche sur mon site');
  
  // Set a default value for the search box
  $vars['form']['search_theme_form']['#value'] = t('Entrez ici votre recherche');
  
  // Add a custom class to the search box
  $vars['form']['search_theme_form']['#attributes'] = array('class' => t('customsearch'));
  
  // Change the text on the submit button
  $vars['form']['submit']['#value'] = t('Rechercher');
  
  // Rebuild the rendered version (search form only, rest remains unchanged)
  unset($vars['form']['search_theme_form']['#printed']);
  $vars['search']['search_theme_form'] = drupal_render($vars['form']['search_theme_form']);
  
  // Rebuild the rendered version (submit button, rest remains unchanged)
  unset($vars['form']['submit']['#printed']);
  $vars['search']['submit'] = drupal_render($vars['form']['submit']);
  
  // Collect all form elements to make it easier to print the whole form.
  $vars['search_form'] = implode($vars['search']);
}

 



2 commentaire