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) :)

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState