18.10.2016 Views

Drupal 7 Module Development

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Drupal</strong> Permissions and Security<br />

3. An optional description of the permission. This string should be a complete<br />

sentence, and wrapped in t(). <strong>Drupal</strong>'s user interface guidelines encourage<br />

you to use this element if the permission needs special clarification,<br />

especially if permission is being given to untrustworthy users who could<br />

pose a security risk. For our example, we will clearly state: "Displays the<br />

content types that a user may create on the user's profile page."<br />

When we put these three parts together, our hook looks like the following code:<br />

/**<br />

* Implement hook_permission().<br />

*/<br />

function example_permission() {<br />

return array(<br />

'view content creation permissions' => array(<br />

'title' => t('View the content creation options for registered<br />

users'),<br />

'description' => t('Displays the content types that a user may<br />

create on the user\'s profile page.'),<br />

),<br />

);<br />

}<br />

Using the description element is tempting, for completeness, but<br />

<strong>Drupal</strong>'s UI testing discovered that it serves mostly a visual clutter for the<br />

end user.<br />

The following screenshot shows examples of the types of permissions that<br />

benefit from a full description. This page can be found at the following path:<br />

admin/people/permissions<br />

[ 220 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!