Drupal 7: Phpx Tools Module

David G - DrupalRecently when debugging a Drupal 7 website I wanted to help a designer on my team find the appropriate template file(s) to able to be overwritten within our theme to customize how some output was displayed on the website.

For our project the production webserver does not allow viewing or modification of the subsites setting.php file. This security best practice sucks for numerous reasons I don’t list at this time. But, being Drupal it’s still possible to interact with the $conf settings if you really want to. Recently I found the Extended Tools for PHP Execute module which I feel should be in any Developers toolbox when working on remote Drupal installations.

My Designer’s Settings.php Issue

As of a recent version of Drupal we can easily enable debug output in the rendered HTML by enabling theme debugging via settings.php. In a previous Arvixe post I wrote about this, additionally see the Drupal Documentation on Template Suggestions.

So I know that this functionality exists in Drupal to help themers and designers, but on my site I don’t have access to settings.php. What am I to do!? Well, I also know the Devel module allows execution of PHP code. So, I went ahead and installed the devel module and issued this code snippet:

variable_set(‘theme_debug’, TRUE);

This is equivalent to setting $conf[‘theme_debug’] = TRUE; in the settings.php. Whew! Disaster avoided!! (silly secure conscious system admins).

But, do I really want to have to remember the exact why to call this code every time?! Not really.

Recently released is the PHPX Tools module which I found on Drupal.org. By installing it via Drush:

$ drush dl phpx_tools
Project phpx_tools (7.x-1.0) downloaded to sites/all/modules/phpx_tools.    [success]

dgurba at odin in ~/.../personal/paragraph_charts/www
$ drush en phpx_tools -y
The following projects have unmet dependencies:    [ok]
phpx_tools requires devel
Would you like to download them? (y/n): y
Project devel (7.x-1.5) downloaded to sites/all/modules/devel    [success]

Project devel contains 3 modules: devel_generate, devel, devel_node_access.

The following extensions will be enabled: phpx_tools, devel
Do you really want to continue? (y/n): y
phpx_tools was enabled successfully.    [ok]
devel was enabled successfully.    [ok]

We can now easily have the Devel execute PHP code admin page maintain a history of snippets we have run; which is incredibly useful! Having run the above code once the website can now remember it for us and we can simply give the code a descriptive name and either Run it, or Save and Run it.

Example code to enable theme_debug for Drupal 7.

Example code to enable theme_debug for Drupal 7.

The PHPX Tools maintains a history of code you’ve executed even if you don’t give it a Name. This can be helpful if you forget to name a script you’ve created. You may load via Ajax any previously run or saved code snippets.

Example saved code snippets to both enable and disable theme_debug in D7.

Example saved code snippets to both enable and disable theme_debug in D7.

By running the above code and inspecting the Source the viewed HTML I can see output such as:

<!-- THEME DEBUG -->
<!-- CALL: theme('region') -->
* region--page-top.tpl.php
x region.tpl.php
<!-- BEGIN OUTPUT from 'modules/system/region.tpl.php' -->
<div class="region region-page-top"

So I can visually see that this module is working properly.

So, if you don’t have access to the settings.php file or Drush on remote servers. Than this tool, with some preset scripts you maintain via Gists or in a local snippets repository … You can easily import these scripts as needed into a drupal site so that you have a simple set of scripts which don’t require Drush usage. It will be interesting to see if the module creator or someone else provides a sample set of scripts to include with the module out-of-the-box.

Additionally the module supports code formatting and syntax highlighting with an additional javascript module; personally I prefer to debug scripts locally and then simply copy-and-paste them to the Production site.

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

Tags: , , | Posted under Drupal, Programming/Coding | RSS 2.0

Author Spotlight

David Gurba

I am a web programmer currently employed at UCSB. I have been developing web applications professionally for 8+ years now. For the last 5 years I’ve been actively developing websites primarily in PHP using Drupal. I have experience using LAMP and developing data driven websites for clients in aviation, higher education and e-commerce. If you’d like to contact me I can be reached at david.gurba@arvixe.com

Leave a Reply

Your email address will not be published. Required fields are marked *