Latest Tweets:

"git add -N" Made My Day (--intent-to-add)

Perfect for creating a patch that will include new files.

Swap display formatters for RSS (absolute links) in Drupal 6

Ever need images to render as absolute links when RSS feeds in Drupal views? Of course you have. In Drupal 6 + Views2 + contrib CCK you are forced into node display mode which leaves you pretty limited. Additionally, any image display widgets only generate relative links. So you either need to create an alternate display widget or do this…

#1) Tell this field to follow another display formatter via code (this is in a custom module).

/**
 * Modify fields for absolute links in RSS feeds.
 */
function MYMODULE_preprocess_content_field(&$variables) {
  if($variables['element']['#field_name'] == "field_MYFIELD" && $variables['element']['#node']->build_mode == NODE_BUILD_RSS) {
    $variables['element']['items'][0]['#theme'] = 'MYMODULE_imagefield_formatter_image_nodelink_abs';
  }
}

Then create an alternate version on the display formatter. In my case we just needed the normal imagefield link output (I have great editors) though you might want to use and imagecache formatter. (Find a function to copy in the imagecache module.) I placed this code within the template.php —because the function name HAS to start with your theme name. 

/**
 * Alternate imagefield display for absolute links. See: MYMODULE_preprocess_content_field
 */
function MYTHEME_imagefield_formatter_image_nodelink($element) {
  // Inside a view $element may contain null data. In that case, just return.
  if (empty($element['#item']['fid'])) {
    return '';
  }
  $node = $element['#node'];
  $imagetag = theme('imagefield_formatter_image_plain', $element);
  $class = 'imagefield imagefield-nodelink imagefield-'. $element['#field_name'];
  return l($imagetag, 'node/'. $node->nid, array('attributes' => array('class' => $class), 'html' => TRUE, 'absolute' => TRUE));
}

That’s it. To improve this you might also register the theme function within your module and avoid spreading this code out in two places.

Alter items displayed on pages after the first (Drupal)

NOTE: These instructions are from a Drupal 6 + Views 2 setup, but I’m sure the technique is transferable to D7 and I may update this if/when I do that same thing on one of my D7 sites.

Here’s a super quick technique for showing more items per page once you’ve entered pager mode. This is particularly useful when you use an block view attachment to show a first set of bigger items (or a single featured item).

#0) Build your view.

#1) Create an Argument of type “Global: Null”

#2) Select ”Provide default argument”

#3) Choose “Fixed entry” and enter any old thing, this is a dummy value.

#4) Choose a Validator of type ”PHP code.”

#5) Use the following code to know when the page view is in pager mode…

if(isset($_GET['page'])) {
  $view->display['page_1']->handler->options['items_per_page'] = 14;
}
return TRUE;

Here’s a screenshot to make it easy…

revert-a-faulty-merge ... Thanks Linus!

Feel like this is the most official primary source on dealing with reverting bad changes.

Right from the horses mouth.

Linus Torvalds

Move core block settings to a new theme (Drupal)

This mySQL will help you move core block settings across from one theme to another. It also include two region name replaces. http://drupalbin.com/21207

# Reset blocks to remove standard placements.
UPDATE block SET status = 0, region = -1 WHERE theme = 'OLD-THEME';

# Pull data across.
UPDATE block AS export_blocks
INNER JOIN block AS import_blocks
  ON import_blocks.module = export_blocks.module
  AND import_blocks.delta = export_blocks.delta
SET
  export_blocks.weight = import_blocks.weight,
  export_blocks.region = REPLACE(
    REPLACE(import_blocks.region, 'OLD-REGION1', 'NEW-REGION1'),
'OLD-REGION2', 'NEW-REGION2'),
export_blocks.visibility = import_blocks.visibility, export_blocks.pages = import_blocks.pages, export_blocks.title = import_blocks.title, export_blocks.status = import_blocks.status WHERE export_blocks.theme = 'NEW-THEME' AND import_blocks.theme = 'OLD-THEME';