See Permissions' Machine Names (and much more) with Xray module for Drupal 7

Submitted by on

With Drupal 7's third and final release candidate unleashed on us all this morning, it is long past time to help the #D7CX movement with a seasonal offering of our own.

The most fitting gift would be porting a Drupal 6 module, but it wouldn't be a modern winter holiday without an environmentally irresponsible brand new toy: Introducing the Xray module, designed to help site builders and module developers investigate a Drupal 7 site.

Xray image: skeleton using a power drill. The feature i'd like to point out in relation to porting modules and developing for Drupal 7 is Xray's report showing permission machine names (screenshot below). Permissions in Drupal 7 have human-friendly translatable titles, which is awesome, but the machine names – which module developers must use – have disappeared entirely from the user interface.

A moderately complex Drupal site can have a Permissions page like a Las Vegas building-side of lightbulbs... but with checkboxes – so i don't like to create new permissions unless i know of a clear use case. In developing modules, therefore, i prefer to reuse existing permissions when applicable. For instance, the Xray module, instead of defining a special permission for its reports, reuses the "View site reports" permission.

To refer to a permission in code, we need its machine name, not the title we can see on the Permissions page (admin/people/permissions). My chapter on module development in the coming Definitive Guide to Drupal 7 covers (in the course of building the Xray module) how to find permission machine names in the database or in the code, but it wouldn't be Drupal if we couldn't say there's a module for that, so a permission machine name report is incorporated into Xray itself.

Note: Anything incorrect in this chapter may misinform tens of thousands, so please, code review Xray module mercilessly, and all comments and suggestions requested and welcome!

Further note: Please vote for the When There's Not a Module for That, the intermediate module building session at Drupalcon Chicago which will include parts of the making of Xray module, and for sessions involving other DGD7 authors, and then for every session that interests you because there's less than 24 hours left to vote!

By the way, the machine name for "View site reports" is access site reports. Drupal will always keep us on our toes.

Xray, in another feature interesting for module developers and sometimes for site builders, displays what function and arguments produce each page you visit.

The most up-to-date code for Xray can be downloaded directly (tar.gz) from Gitorious.

A table of permission titles and permission machine names.

Comments

Submitted by Fernando on Mon, 09/17/2012 - 17:40

I'm working on a site for a clenit that uses a WordPress blog but Drupal for everything else. This code is going into a module that let's Drupal pull post info out of WordPress's database rather than relying on the Aggregator module to harvest the RSS feed.

Add new comment

You must have Javascript enabled to use this form.