Drupal 7

PHP String or Character Replacement (preg_replace)

Sometimes you want to run multiple replacements on a string of text or an array. This method uses matching arrays for patterns and replacements to make it easy to see what is being swapped for what.

Javascript tracer function

This is a handy little function that can be used for debugging in Drupal. SInce console.log can sometimes break some browsers without a console, this at least makes sure the console.log is only run when you are logged into the site. It also has a nice feature of including the name of the function that called it.

Targetting media types in omega .info file

Sometimes you need a screen only stylesheet:
css[global.css][options][media] = 'screen'

For print:
css[print.css][options][media] = 'print'

Menu Classes

When building a menu, you may need to customize certain links to be a certain color/style while others remain the base menu style. Using the function below, your links will be given: class="leaf menu-[menu-link-id]".

In template.php file insert this:

Loading a Block

If you need to load a block into a custompage and you want it to have all the proper wrappers of a block: Use this method:

Codit: Template Tracers for Drupal

One of the confusions with Drupal is knowing where content is coming from, what tpl controls it and where the tpl resides. Place the following template tracer code at the start and end of the output on a tpl and this will never cause confusion again.

Revealing the actual location of the template file is made secure by only revealing the template location if the user has permission to see template tracer output.

Entity Load

Entity Load is the root function that funcitons like node_load, node_load_multiple, taxonomy_term_load and taxonomy_term_load_multiple all use. Here two of just using the root function to load node(s) or taxonomy term(s).
The function looks like
entity_load($entity_type, $ids)
@param $ids is a flat array of node ids or term ids.

Load Node(s)


Just say no. They should not be on our sites. They have not had any influence with search engines for nearly a decade. Editors should not waste time putting them in and developers should not waste their time by giving them that field.

On most of our content types, they are not on by default, but unfortunately our install profile adds them by default to info page, carousel page, and article page content types. Please go into your currently under production sites and remove "Meta-Keywords" from the content type. DO NOT remove "Meta-Description", those are still important.

Setting up a CSV for import with feeds

Steps for sanitizing a spreadheet for import into feeds
a) Move the field mapped to the title to the first column of the spreadsheet.
b) Remove any duplicate entries for if duplicates will cause a problem
c) Save sheet as msdos csv
d) change file extention from .csv to .txt
e) replace the following with items in the brackets [] pay careful attention to spaces in them
[?] -> [']
[ ' ] -> [ ]
[ÿ] -> [space]

Feeds : importing geolocation

For some reason the geolocation field does not show up as a field that can be imported. It requires an additional field importer to make the geo latitude and longitude fields become available.

The additional importer comes from #5 in this post

Simply place the file in the feeds/mappers/ directory.

An important lesson learned here: If the geo fields are mapped on an importer, the import will fail if the geo fields have no data or are empty.


Subscribe to RSS - Drupal 7