Drupal 7

Feeds: Addresses - importing an address

NOTE: Feeds address is tempermental. If you are bringing in US data you must import a country code of "US" and a state codes must be two letter all caps like "FL" or "NY".

Caching intensive processes in Drupal

Yes all of Drupal's pages are cached by ordinary page caching. However, some processes are so intensive that we want to cache them beyond Drupal's default. Good candidates for such caching are lists of cities within regions.
UPDATE: A more refined method using Drupal static and caching should be used
Here are the basics for caching the return of a heavy function.

Updating settings.php prior to BETA or LIVE

In settings.php a change is needed to allow Drupal to access the Live database vs the Local Database.

The original entry will look like this

Entity Field Query OR not AND

Entity Field Query is useful for returning nodes based on field values or node properties


= new EntityFieldQuery();

Codit Blocks

  • Blocks can be added quickly  through code (similar to custompage blocks, but without any admin or database changes) by adding a block directory and template, then flushing cache.
  • Any block can have a callback function that automatically takes what it returns and puts it in the $variables array for the tpl to access.  These callback functions should only return data, not markup.  Save the processing of turning data into markup for the tpl.   Callback function also easily handle caching and permissions access.
  • Can be used to override any block title, including the ability to disable all block titles except any that have been overridden.
  • Block placement can be handled by the Context module, Panels, or the block admin.

Cookie Domain in Drupal

There are times when we need to force a specific cookie domain in Drupal. This often comes as a request from the Analytics team as the Google Analytics module uses the $cookie_domain variable in its tracking.

This variable is set in settings.php. Care has to be taken though because setting the cookie domain to be that of the live site will prevent you from logging in on a dev site.
Here is the fix:
Add this line to settings.php

Load A Menu Into Block

To load a menu into a block use this function:

$aLoadedBlock = menu_block_view($delta);
$sBlockOutput = render($aLoadedBlock);

Checks access to the menu and loads all the links.

clean urls on 1and1

This is what I used to get clean urls working on 1and1 hosting

In .htaccess replace the former with the latter:

-  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

+ RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]

Creating a new hook

Here is a nice starter article on creating a new hook to use within Drupal

Build an external link from a field value

When building an external link from a field value you have to do some checking to make sure that "google.com" works as reliably as "http://google.com" as well as variations such as https:// and ftp://. String checks become convoluted to do them correctly and done incorrectly, they can break links that have something other than the planned for scheme of http://.

This method is pretty reliable and includes additional Drupal sanitization and protection through the url() function.


Subscribe to RSS - Drupal 7