Drupal

Drupal 7 Custom 404 Page Template

dans le tempate.php du theme, ajouter :

function THEMENAME_preprocess_page(&$variables) {   
  $status = drupal_get_http_header("status");  
  if($status == "404 Not Found") {      
    $variables['theme_hook_suggestions'][] = 'page__404';
  }
}

snippet trouvé ici : http://www.dejaaugustine.com/2011/07/drupal-7-custom-404-page-template/

et voici l'équivalent pour Drupal 6 :

function THEMENAME_preprocess_page(&$variables) {   
  if(stripos(drupal_get_headers(), "404 Not Found") !== false) {
      $variables['template_file'] = 'page-404';
  }
}

Changer l'URL d'admin de Drupal 7

En ajouter ces 2 fonctions dans un module de votre projet, l'url de l'admin devient "votre-site.com/gestion". Et "votre-site.com/admin" renverra une erreur 404.

// Implements hook_outbound_alter().
function monmodule_path_url_outbound_alter(&$path, &$options, $original_path) {
    
    if (preg_match('|^admin(/{0,1}.*)|', $path, $matches)) {
        $path = 'gestion'. $matches[1];
    }
}

// Implements hook_inbound_alter().
function monmodule_path_url_inbound_alter(&$path, $original_path, $path_language) {

    if (preg_match('|^gestion(/{0,1}.*)|', $path, $matches)) {
            $path = 'admin'. $matches[1];
    }
    if (preg_match('|^admin(/{0,1}.*)|', $original_path, $matches)) {
            $path = '404'. $matches[1];
    }
}

Tags:

Changer l'URL d'admin de Drupal 6

En ajouter ces 2 fonctions dans le fichier settings.php de votre projet, l'url de l'admin devient "votre-site.com/gestion". Et "votre-site.com/admin" renverra une erreur 404.

function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
	if (preg_match('|^admin(/{0,1}.*)|', $path, $matches)) {
		$path = 'gestion'. $matches[1];
	}
}

function custom_url_rewrite_inbound(&$result, $path, $path_language) {
	if (preg_match('|^gestion(/{0,1}.*)|', $path, $matches)) {
		$result = 'admin'. $matches[1];
	}
	if (preg_match('|^admin(/{0,1}.*)|', $path, $matches)) {
		$result = '404'. $matches[1];
	}
}

Modifier le bloc de recherche Drupal

function mon_theme_preprocess_search_block_form(&$vars, $hook) {

  // Modify elements of the search form
  unset($vars['form']['search_block_form']['#title']);

  // Set a default value for the search box
  $vars['form']['search_block_form']['#value'] = t('Search');

  // Add a custom class to the search box
  $vars['form']['search_block_form']['#attributes'] =
    array(   
    'onfocus' => 'if(this.value == \''.t('Search').'\') {this.value = \'\';}',
    'onblur' => 'if(this.value == \'\') {this.value = \''.t('Search').'\';}');

  // Change the text on the submit button
  $vars['form']['submit']['#value'] = "ok";

  // Rebuild the rendered version (search form only, rest remains unchanged)
  unset($vars['form']['search_block_form']['#printed']);
  $vars['search']['search_block_form'] = drupal_render($vars['form']['search_block_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']);
}

Utiliser Jquery 1.5 avec le frontend de drupal 6

Pour utiliser Jquery 1.5 sur le frontend de Drupal 6, il faut créer un module.
Mettre la version de jquery dans le dossier du module (ex: mon_module/jquery.min.js).

Avec cette fonction :

/**
 * Implementation of moduleName_preprocess_hook().
 * Replace Drupal core's jquery.js with the 1.5.2 only in the front end.
 */
function mon_module_preprocess_page(&$variables) {

  // Only do this for pages that have JavaScript on them.
  if (!empty($variables['scripts'])) {

    // Only if front end
    if (arg(0) != 'admin' && arg(2) != 'edit' && arg(1) != 'add' && arg(0) != 'batch' ) {

      // Get an array of all the JavaScript files loaded by Drupal on this page.
      $scripts = drupal_add_js();

      // Replace jquery.js
      $new_jquery = array(drupal_get_path('module', 'mon_module') .'/jquery.min.js' => $scripts['core']['misc/jquery.js']);
      $scripts['core'] = array_merge($new_jquery, $scripts['core']);
      unset($scripts['core']['misc/jquery.js']);
      $variables['scripts'] = drupal_get_js('header', $scripts);
    }
  }
}

Pages

Subscribe to RSS - Drupal