Drupal 7

Reading Language from the Array / Object Safely

In Drupal when grabbing info from an array or object you often need the "Language" of the entity to grab the data you need.   Most of the time in the sites we are building, we end up with the language of 'und' for undefined.  Care should be taken to not hardcode in the value of 'und'. Whenever possible, read it from the data you are trying to read, but build in a safety just in case it is not there.
It should look seomthing like this:

PHP Variable safety - to avoid Notices

Simple IF statements are often used, especially in Drupal Theme-ing. ;They look like this

Bulk update of url alias

Running the built in bulk bulk url alias operation can make a mess of custom (not following a pathauto pattern) overridden paths. Typically a bulk change is needed when profiles need their paths altered (WHEN possible, get the patterns set BEFORE data is imported initially)

In the event that a new pattern needs to be applied, here is the prescribed method

Drupal L function

Drupal provides a way build a link that uses results in a friendly path rather than the actual node ID (NID). It does this through the L function.
Avoid outputting "/node/341" at all costs!
Full description from Drupal is here http://api.drupal.org/api/drupal/includes%21common.inc/function/l/7

l($text, $path, array $options = array())

First and Last Class on a list

This function appears in the Codit Module

Here is a function that allows you to quickly get back a class as 'first', 'middle', 'last' and in a case of a single item list 'first last'

Adding Field data to Alias Pattern

In order to use a field's data within a replacement pattern inside of path auto, you need to enable "Entity Tokens" from the "Other" module section. Flush the cache after enabling the module to get the new tokens to show up.

Changing the Date Format for the jQuery Datepicker

                jQuery( "#mmg-main-menu-events-start-eventmenu, #mmg-main-menu-events-end-eventmenu" ).datepicker({
                                      dateFormat: "D dd M yy"

Drupal Password Issues

If you are locked out, or need to re-set the password to something knowable here are the solutions.

Locked out from too many failed login attempts

Drupal 7 automatically blocks you by IP adress after more than 5 failed login attempts.  (It does re-set after time, but we don't have time to wait)

Drupal White Screen of Death

When drupal white screens it is almost always due to a 500 error along with error reporting turned off.

The quickest way to see the problem is to tail the error log for the server you are using.


Subscribe to RSS - Drupal 7