Pedro Lozano Drupal developer



Reply to comment

Posted by Pedro Lozano

A little trick I started using recently: using cookies to alter Drupal behavior when navigating the site (usually developing or debugging) with a shared user account that should present a different behavior to the rest of the people.

Use case. A few developers may be building a site and they all use the admin account for setup tasks. Now one of them doesn't want to see url aliases because he needs to see node ids in urls for debugging purposes.

You could put a code like this in settings.php:

function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
  if ($_COOKIE['disable_url_aliases']) {
    $path = $original_path;
  }
}

Now, using a Firefox extension like Firecookie or Web Developer, you can add a cookie called disable_url_aliases in your browser that will disable url aliases only for you, the rest of the developers won't notice.

Other use case is using a different theme.

/**
 * Implementation of hook_init().
 */
function project_customizations_init() {
  global $custom_theme;
 
  if ($_COOKIE['custom_theme']) {
    $custom_theme = $_COOKIE['custom_theme'];
  } 
}

For this snippet to work you must create the cookie custom_theme with the value set to the name of the theme that you want to use.

Other case ideas:

  • Displaying debug information when navigating as anonymous.
  • Avoid analytics when when navigating as anonymous.
  • Navigate with a different language.
  • Disable cache. Combined with xdebug profiler it allows you to profile anonymous page generation while still keep the cache active for the rest of the users.

I'm sure this list can be made longer. You are welcome to post your ideas in the comments.

Reply

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • HTML tags will be transformed to conform to HTML standards.

More information about formatting options



Flickr

Sunset over the bay of CádizSeagullCrabsCrabPostesSalinasHouseWarehouse

twitter

  • @vodafone_es 3. Incluso teniendo en cuenta la penalización de 100€, me sale 140€ más barato irme a Orange. 20 hours 43 min ago
  • @vodafone_es 2. El precio es más caro cuando me logueo y uso los puntos que cuando estoy sin loguearme. :-( 20 hours 44 min ago
  • @vodafone_es 1. Sigue saliendo no disponible. 20 hours 45 min ago

Follow peterlozano on Twitter