Display nodetype "name" (human name for nodetype) instead of the nodetype "type" (machine name for nodetype)

ali27 - April 9, 2008 - 09:49
Project:Taxonomy Quick Find
Version:5.x-1.0
Component:User interface
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

I've patched the module. It works on our site. Please check the code to tell us if it's secure and drupal code compliant enough.

You'll see the code added between the commented lines 416 to 436 (// dev-label-080401), under the function taxonomy_quick_find_view_block($delta) { of * Function to get the contents for a block. This also includes the Javascript too. :

// dev-label-080401 : display the nodetype "name" instead of the nodetype "type"  
    $result = db_query('SELECT distinct n.nid, n.title, nt.name FROM ({node_type} nt INNER JOIN {node} n USING (type)) INNER JOIN {term_node} tn USING (nid) WHERE n.type = "%s" AND n.status = 1 AND tn.tid = %d ORDER BY n.created DESC LIMIT %d', $type, $preset, $settings['limit']);
     
      if ($result && db_num_rows($result) > 0) {
        $items = array();
        while ($node = db_fetch_object($result)) {
          $items[] = l($node->title, 'node/' . $node->nid);
        
          $nodetypename=$node->name; // new variable contains the node type name
        }
        $output .= theme('item_list', $items, ucwords(t($nodetypename)), 'ul', array('class' => 'tqf_' . $type));
      }
      else {
      // if the previous query has no result then we create another query
      $result = db_query('SELECT distinct n.nid, nt.name FROM {node_type} nt INNER JOIN {node} n USING (type)  WHERE n.type = "%s" AND n.status = 1 ORDER BY n.created DESC LIMIT %d', $type, $preset, $settings['limit']);
     
       db_num_rows($result);
       $node = db_fetch_object($result);
       $nodetypename=$node->name;
     
      // dev-label-080401 : display the nodetype "name" instead of the nodetype "type"  

        $output .= theme('item_list', array(t('Aucun résultat associé.')), ucwords(t($nodetypename)), 'ul', array('class' => 'tqf_' . $type));
      }
    }
    return $output;
  }
  else {
    return '';
  }
}

Thank you

#1

ali27 - April 9, 2008 - 09:50
Assigned to:Anonymous» ali27

Just assigning the patch

#2

nicholasThompson - April 14, 2008 - 10:49

There is a function in Drupal to handle the requesting of node type names. I will add this feature separarely using that if needed.

Thanks for the idea though...

PS: For patches you may want to read the how to create patches handbook page

#3

nicholasThompson - September 17, 2008 - 14:43
Assigned to:ali27» Anonymous
Status:needs review» fixed

Fixed in latest Dev.

#4

Anonymous (not verified) - October 1, 2008 - 15:12
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

#5

doc2@drupalfr.org - March 3, 2009 - 11:08
Version:5.x-1.x-dev» 5.x-1.0
Category:feature request» bug report

Much simpler solution to the issue, against the 5.x-1.0 version of the .module file,

a small bug to fix lies line 447:
        $output .= theme('item_list', array(t('No items found.')), ucwords(t($type)), 'ul', array('class' => 'tqf_'. $type));

replace it by:
        $output .= theme('item_list', array(t('No items found.')), ucwords(t($types[$type])), 'ul', array('class' => 'tqf_'. $type));

You're done!

    Explanations:

I saw that only s[$type] was missing by comparing this line to the 444th:
        $output .= theme('item_list', $items, ucwords(t($types[$type])), 'ul', array('class' => 'tqf_'. $type));

It's been quite a while that I've been using it like this and it still works fine. I've attached the corrected version of the module for the lazy drupalers (still with the "ucwords()" PHP function, see below)!

AttachmentSize
taxonomy_quick_find.module.txt 16.92 KB

#6

doc2@drupalfr.org - February 28, 2009 - 16:20
Status:closed» needs review

Oups, patch status, even if it's not a proper one... sorry for that.

 
 

Drupal is a registered trademark of Dries Buytaert.