Skip to main content

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

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.

X ray photo showing skeleton drilling into a wall 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

2012 September 17
Fernando

Permalink

I'm working on a site for a

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

The content of this field is kept private and will not be shown publicly.

Markdown

The comment language code.
CAPTCHA Please help us focus on people and not spambots by answering this question.