Friday 29 October 2010

Drupal 6: Altering the help message for a particular URL

I noticed that on the "All Content" page, the help message is empty, but my theme still displays a big empty bubble, which looks like a bug. After doing some research I realised the help message on this page came from the node_help() function, and was returning just a space on purpose, as a not-null value meant that the little "more help" link would still be displayed.

SOLUTION
Implement the theme_help() hook in your theme's template.php. Note: replace THEME with your theme name.

function THEME_help() {
 $help = menu_get_active_help();
 if (arg(0)."/".arg(1)."/".arg(2)=="admin/content/node" && !arg(3))
 {
  $help = "<p>My help message.<p>".$help;
 }
 
 if ($help) return "<div class='help'>".$help."</div>";
 else return null;
}

This will work for the URL admin/content/node, but can easily be altered to work for any URL.

REFERENCES
http://stackoverflow.com/questions/1296106/drupal-6-hook-for-altering-help-field-in-a-form

Thursday 28 October 2010

Opening Drupal PHP files in Eclipse

By default, some Drupal files will not open in the proper editor (they will just be treated as plain text). Assuming you have PDT installed for PHP development, you can specify which filetypes contain PHP code and hence should be opened in the PHP editor.

Look in Windows > Preferences > General > Content Types > Text > PHP Content Type, and add each of the following associations:
*.engine
*.theme
*.install
*.inc
*.module
*.profile
*.test

PROBLEM
If when you then try opening one of these files, you get an error along the lines of:
Unable to create editor ID org.eclipse.php.editor: org.eclipse.core.internal.filebuffers.SynchronizableDocument cannot be cast to org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument

SOLUTION
Restart eclipse.


References: http://drupal.org/node/75242

Saturday 23 October 2010

Disable Alt+Space from activating the window menu in Ubuntu 10.10 Maverick

I wanted to change my Gnome-Do hotkey to Alt+Space, but it didn't work - when I pressed the key combination, it just activated the window menu. In order to assign this key combination to something else you must first disable it's current use. To do this, go into the main menu, then System > Preferences > Keyboard Shortcuts, and find "Activate Window Menu", double click it to assign it a new key combination, and simply press Backspace to disable it.

Monday 4 October 2010

Apache Ant error: restrict doesn't support the nested "name" element

System: Ant 1.7.1 and Sun Java 1.6 on Ubuntu Lucid 10.04

Code snippet:
<target name="jar">
<jar basedir="${bin}" destfile="${project.name}.jar">
<restrict>
<name name="**/*" />
<archives>
<zips>
<fileset dir="/opt/project_jars">
<include name="file.jar" /> 
</fileset> 
</zips> 
</archives> 
</restrict> 
</jar> 
</target>

From googling the error, I found this thread: http://markmail.org/message/y2ly5gykzbpab7p7. The suggested solution of adding namespace information got rid of the original error, but introduced a new one:
restrict doesn't support the nested "archives" element

Actual solution: upgrade Ant to 1.8
sudo apt-get install ant1.8