Aprium Software

Drupal

Drupal Module Weight

Sometimes you will be executing a form alter and the $form object passed to you does not match what is coming out on the screen. This is most likely that another module is running after your form alter and changing the form.

So the solution is make your module execute after all the other modules have finished. You can do this by changing the system weight. There are 2 ways of doing this, the first is to install the module order module which is in development at the moment but should do the trick.

Changing the ImageCache Preset On The Fly

Its quite common when making a site to need a different size image for the first teaser than the rest of the teasers in the list. This job is made more difficult because when the CCK image field is sent to the template it only gives you the end result in the $output variable and does not give you the images path.

Its does however give you a file id in the raw data which you can use to load the file object and get all the information you need create a new image from a different preset.

Make sure the user is logged in

This article is a quick solution if you have a menu item for adding content and you want to make sure the user is logged in before going to the add node page. This solution will also display a register/login link and then redirect them once they have logged in.

1) Firstly make sure you have the php filter module enabled and you are logged in as admin.

2) Next create a new page and set the input format to php.

3) Then paste the following code into the body of the page.

<?php
global $user;

if($user->uid == 0) {
?>

Exports nodes as CSV

The best way I have found to export nodes is through the views bonus pack. After installing that you will see a bunch of new options in the feed display. Now you can select the style of CSV file.

I did notice that the headers are not set correctly but you can fix this by opening up views-bonus-export-csv.tpl.php and adding
drupal_set_header('Content-Type: text/x-comma-separated-values; charset=UTF-8');
drupal_set_header('Content-Disposition: attachment; filename="data.csv"');

Drupal Supports PHP 5.3

The new version of Drupal 6.14 now supports PHP 5.3. This news was tacked onto the bottom of the 6.14 release notes and read:


Drupal 6.14 is the first stable release to support PHP 5.3.0, but this might not be true about the contributed modules you are using. Watch out for updates to your contributed modules if you experience problems with PHP 5.3.0 support.

This is great news for me because like many OS X users I upgraded to snow leopard which comes bundled with PHP 5.3 and stop all by Drupal projects from running.

hook_uc_cart_alter

hook_uc_cart_alter is a really useful hook if you need to change items in the shopping cart. It replaces the need to theme all the check out pages individually.

The shopping cart items come through as a by reference parameter. This means you don't have to return the variable.

$items[0]->title = 'testings';

Drupal Location searching by UK postcode

I have been asked to configure the location 6.x-3.1-rc1 module to allows a postcode proximity search. This allows you to search for nodes within 5 miles of a postcode which is very powerful. Out of the box location 3.1 looks like it supports it, however when activated for the uk the search will just return nothing.

Editing a Drupal views query SQL

The Drupal views system is awesome and delivers graphical query building with fast performance. However from time to time you may wish to add certain complexity to your view that the module just cant deliver.

 

Duplicate entry 'F j, Y - H:i' " warning for INSERT into date_format table

After updating to Date API 2.0 we ran the update.php and started to get this error on various pages.

user warning: Duplicate entry 'F j, Y - H:i' for key 2 query: INSERT INTO date_format (format, type, locked) VALUES ('F j, Y - H:i', 'medium', 1) in /xxx/Sites/htdocs/bmi/includes/common.inc on line 3425

Mysql Remote Backup

This article covers how to write a Mysql backup script for shell. First of all we need to create the file so open a new text file called backup.sh and set the first line as.

#!/usr/bin/expect

We are using an expect script because it is better suited to dealing with remote requests and responses. The script is going to run like a command and will use the following parameters.

Syndicate content

Hire

If you need a London based Drupal developer you can hire me. Check the availability page and contact me on info@aprium.net.

 

Powered by Drupal, an open source content management system

Copyright Aprium 2010