C'est possible de surcharger une fonction theme_nom d'un module dans mon template.php ?

Catégories:

Bonjour à tous,

Dans un module (print) je retrouve cette fonction

<?php
function theme_print_mail_format_link() {
 
$print_mail_link_class  = variable_get('print_mail_link_class', PRINT_MAIL_LINK_CLASS_DEFAULT);
 
$print_mail_show_link = variable_get('print_mail_show_link', PRINT_MAIL_SHOW_LINK_DEFAULT);
 
$print_mail_link_text = filter_xss(variable_get('print_mail_link_text', t('Send to friend')));

  $img = drupal_get_path('module', 'print') .'/icons/mail_icon.gif';
 
$title = t('Send this page by e-mail.');
 
$class = strip_tags($print_mail_link_class);
 
$new_window = FALSE;
 
$format = _print_format_link_aux($print_mail_show_link, $print_mail_link_text, $img);

  return array('text' => $format['text'],
              
'html' => $format['html'],
              
'attributes' => print_fill_attributes($title, $class, $new_window),
              );
}

?>

Je voudrais ré-écrire cette fonction pour modifier le chemin et le nom de l’image, l’a variable $img.

Je n’ai pas trouvé comment le faire, c’est possible ?

Merci d’avance.

#

Ho mon dieu, j’ai trouvé par un coup de chance inespéré après avoir fait des tests. Je commence à dompter la bête, et sincèrement, je suis vraiment surpris. Dire que j’aurai pu utiliser cette technique plutôt que de modifier à la mano les fichiers des modules… Voici la technique magique :

Dans mon template.php j’ai écris

<?php
function montheme_print_mail_format_link()
{
$array = theme_print_mail_format_link() ;
 
$img = '/'.$base_path . path_to_theme()  .'/img_icon/digikam.png';

    $array['text'] = '<img src="'.$img.'" alt="Envoyer à un ami" title="Envoyer à un ami" width="32 height="32" class="print-icon"';
   return
$array;
}
?>

Franchement Drupal est trop bien conçu, plus puissant que l’api de Joomla qui est déjà un framework complet à part entière !

Je me remercie ;-)

#

je comprends plus rien, habituellement c’est ce que je fais, mais ça ne marche pas pour certaines fonctions d’ubercart.

Par exemple dans uc_attribute.admin.inc j’ai la fonction

<?php
function theme_uc_object_attributes_form($form) {
 
$output = '';

  if ($form['view']['#value'] == 'overview') {
   
$header = array(t('Remove'), t('Name'), t('Label'), t('Default'), t('Required'), t('List position'), t('Display'));

    if (count(element_children($form['attributes'])) > 0) {
      foreach (
element_children($form['attributes']) as $aid) {
       
$row = array(
         
drupal_render($form['attributes'][$aid]['remove']),
         
drupal_render($form['attributes'][$aid]['name']),
         
drupal_render($form['attributes'][$aid]['label']),
         
drupal_render($form['attributes'][$aid]['option']),
         
drupal_render($form['attributes'][$aid]['required']),
         
drupal_render($form['attributes'][$aid]['ordering']),
         
drupal_render($form['attributes'][$aid]['display']),
        );

        $rows[] = array(
         
'data' => $row,
         
'class' => 'draggable',
        );
      }
    }
    else {
     
$rows[] = array(
        array(
'data' => t('You must first <a href="!url">add attributes to this !type</a>.', array('!url' => request_uri() .'/add', '!type' => $form['type']['#value'])), 'colspan' => 6),
      );
    }

    drupal_add_tabledrag('uc-attribute-table', 'order', 'sibling', 'uc-attribute-table-weight');
   
$output = theme('table', $header, $rows, array('id' => 'uc-attribute-table'));
  }
  else {
   
$output = '<div class="uc-attributes-add-link">';
   
$output .= t('You may add more attributes <a href="!url">here</a>.', array('!url' => url('admin/store/attributes/add')));
   
$output .= '</div>';
  }

  $output .= drupal_render($form);

  return $output;
}
?>

je l’ai donc copiée dans template.php, modifiée et renommée au nom de mon thème : basic. J’ai reconstruis le theme registry mais rien n’y fait je ne passe pas dedans, qu’est-ce qui peut poser problème ? Où peut on trouver des explications sur le theming ?
Est-ce par ce que c’est un formulaire que ça ne fonctionne pas ?

<?php
function basic_uc_object_attributes_form($form) {
 
$output = '';

  if ($form['view']['#value'] == 'overview') {
   
$header = array(t('Remove'), t('Name'), t('Label'), t('Default'), t('Required'), t('List position'));

    if (count(element_children($form['attributes'])) > 0) {
      foreach (
element_children($form['attributes']) as $aid) {
       
$row = array(
         
drupal_render($form['attributes'][$aid]['remove']),
         
drupal_render($form['attributes'][$aid]['name']),
         
drupal_render($form['attributes'][$aid]['label']),
         
drupal_render($form['attributes'][$aid]['option']),
         
drupal_render($form['attributes'][$aid]['required']),
         
drupal_render($form['attributes'][$aid]['ordering']),
        );

        $rows[] = array(
         
'data' => $row,
         
'class' => 'draggable',
        );
      }
    }
    else {
     
$rows[] = array(
        array(
'data' => t('You must first <a href="!url">add attributes to this !type</a>.', array('!url' => request_uri() .'/add', '!type' => $form['type']['#value'])), 'colspan' => 6),
      );
    }

    drupal_add_tabledrag('uc-attribute-table', 'order', 'sibling', 'uc-attribute-table-weight');
   
$output = theme('table', $header, $rows, array('id' => 'uc-attribute-table'));
  }
  else {
   
$output = '<div class="uc-attributes-add-link">';
   
$output .= t('You may add more attributes <a href="!url">here</a>.', array('!url' => url('admin/store/attributes/add')));
   
$output .= '</div>';
  }

  $output .= drupal_render($form);

  return $output;
}
?>

#

Salut,

Tu utilises correctement le theming mais maintenant je connais pas trop ubercart mais regarde peut-être de ce côté en ce qui concerne le theming …

http://drupal.org/theme-guide/6-7

Drupal 6 Certified

Syndiquer le contenu