interoperability

http://en.wikipedia.org/wiki/Interoperability#Software


The following list of articles is based around the concept of writing Drupal modules and themes that "play nice" with Core and other modules and themes. Much is often said for the APIs and modules that create them. However, there's more fundamental systems in Drupal that module authors should take not of.

Play nice when binding to node types

At one time or another you're going to come up with a great piece of minor functionality that binds itself to a node in some cunning way. Here we'll explore the one most common methods to achieve this; throwing your crap straight into the node build process. You could attach it via a node link also but this article is looking at the badness made in a recent CVS application. So we'll stick with a that to keep things short.

So what has this to do with interoperability and node types? Well, not a lot actually, it's more about playing nice with node types and how you attach your cruft to them.

Take this wonderful snippet lifted from a recent application:

  1. function foo_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  2.  
  3.   // ... do something funky and put it in $my_cruft ...
  4.  
  5.   $node->content['foo'] = array(
  6.     '#value' => $my_cruft,
  7.     '#weight' => CONST_NO_ONE_CAN_CHANGE,
  8.   );
  9. }



Getting nodes and display a list

This article focuses on one of the main reasons applications are rejected, that it acquires a list of nodes and renders some sort of output to the browser. It's a common task often seen and often done totally wrong.

So, by example, lets look at a snippet of often seen code that's reviewed and rejected and then we'll break it down and examine each point.

  1. function foo() {
  2.   $sql = "SELECT nid, title FROM {node} WHERE type = 'foo'";
  3.   $result = db_query($sql);
  4.   while ($row = db_fetch_array($r)) {
  5.     $output .= '<li><a href="node/'.$row['nid'].'">'. $row['title'].'</li>';
  6.   }
  7.   return $output;
  8. }



Syndicate content