Speed Up Your Drupal Development Using Installations and Distributions

Creating Additional User Roles and Assigning Permissions

All of the Drupal sites that we build at my company have a moderation workflow in place provided by the Workbench Moderation module (http://drupal.org/project/workbench_moderation). This requires creating some additional roles for users who can edit and publish content. I also usually create a Developer role for use by any of the other Developers in the team that has permissions to all of the modules on the site, as well as an Administrator role for users who need more administrative access than Editors and Publishers, but who don't need full Developer-level access. Again, I can reference a section of code from standard.install and use that as a template:


// Create new user roles for Developers, Administrators, 
// Editors and Publishers.
$roles = array('Developer', 'Administrator', 'Editor', 'Publisher');
foreach ($roles as $weight => $name) {
  $role = new stdClass;
  $role->name = $name;
  $role->weight = $weight + 2, // New roles must have at 
                               // least a weight of 2.

  // Save the new role.
  user_role_save($role);

  if ($name == 'Developer') {
    // Give the Developer role all permissions.
    user_role_grant_permissions($role->rid, 
 ↪array_keys(module_invoke_all('permission')));

    // Set this as the administrator role.
    variable_set('user_admin_role', $role->rid);

    // Assign user 1 the Developer role.
    db_insert('users_roles')
      ->fields(array('uid' => 1, 'rid' => $role->rid))
      ->execute();
}

I've created an array containing the names of the new roles I want to create, and then a foreach() loop including the key of each item that will be used to define the weight for each role. The first section applies to all new roles where the role is created, and then there is an additional section that applies only to the Developer role. This section assigns all permissions to the Developer role as well as assigning the role to user 1.

Figure 6. The Additional Roles

With the new roles created, I now can set some default permissions:


// Assign some default permissions.
$filtered_html_permission = 
 ↪filter_permission_name($filtered_html_format);
$raw_html_permission = filter_permission_name($raw_html_format);
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, 
 ↪array('access content', $filtered_html_permission));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, 
 ↪array('access content', 'access administration menu', 
 ↪'access devel information', $filtered_html_permission, 
 ↪$raw_html_permission));

To start, I find out the name of the permissions for the Filtered HTML and Raw HTML text formats that I created earlier. Anonymous users are going to have very restricted permissions and are only going to be able to access content and use the Filtered HTML permission. The authenticated users also will be able to access the Administration Menu and information from the Devel module, as well as the Filtered HTML and Raw HTML text formats.

These are just a few examples of what can be done using installation profiles and distributions, and I've shown some of the ways I automate the Drupal installation and configuration processes. The complete installation profile I'm currently using at Nomensa also includes custom themes with theme template overrides that then can be used on custom public-facing and administration themes and additional Drupal configuration. This has saved me hours of time in the initial development stages as opposed to having to redo the same steps each time I start developing a new site.

______________________

Oliver Davies is an Application Developer at Nomensa, specializing in Drupal and PHP development. Outside work, Oliver is a keen contributor to the Drupal community—attending local user groups and maintaining several of his own contributed modules.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

info

Anonymous's picture

Thanks for this article. It's just what I was searching for. I am always interested in this subject. Will bookmark it.
indiaseowordpressdesigns

thanks for the information,

dherach's picture

thanks for the information, this article really helped me in performing their duties. this my blog resep ayam

Reply to comment | Linux Journal

cell port thailand's picture

cellport clinic bangkok

Feel free to visit my weblog ... cell port thailand

Reply to comment | Linux Journal

d'leedon's picture

Potong Pasir MRT at the doorstep, residents can easily access almost to any destination
through.d'leedon

thanks for the information,

dherach's picture

thanks for the information, this article really helped me in performing their duties. this my blog resep ayam

The difference between install profiles and distros

marcvangend's picture

Thanks for the article. A quick note about the title: I think you meant to say "Installation Profiles" instead of "Installations".

Your article is mainly about creating installation profiles and not so much about distributions. That's okay, because installation profiles are great and they can indeed speed up your development process.

IMHO it's too easy to say that "distributions are install profiles on drupal.org" and be done with it. The big difference is that if you use a distribution, you're no longer the maintainer of that code. That has some advantages like the availability of support and updates. The disadvantage is, that if you want to change the way a distribution works, you cannot simply go in and change the code. If you did that, it would get much harder to get support and install updates. In my experience, a distribution can dramatically speed up your development process if it is exactly (or very close to) what you need. If you are planning to make a lot of changes, building on a distribution may even slow down your development process. This is especially true for distributions with lots of features and styling, such as Open Atrium.

Features / Exportables

btopro's picture

Nice article, Features, Profiler and Profiler Builder modules would all help in making a more complete export and install package (and faster) :)

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix