function RulesPluginUI::settingsFormPermissionMatrix

Provides a matrix permission for the component based in the existing roles.

Return value

array Form elements with the matrix of permissions for a component.

1 call to RulesPluginUI::settingsFormPermissionMatrix()
RulesPluginUI::settingsForm in ui/ui.core.inc
Adds the configuration settings form (label, tags, description, ...).

File

ui/ui.core.inc, line 549

Class

RulesPluginUI
Faces UI extender for all kind of Rules plugins.

Code

protected function settingsFormPermissionMatrix() {
    $form['#theme'] = 'user_admin_permissions';
    $status = array();
    $options = array();
    $role_names = user_roles();
    $role_permissions = user_role_permissions($role_names);
    $component_permission = rules_permissions_by_component(array(
        $this->element,
    ));
    $component_permission_name = key($component_permission);
    $form['permission'][$component_permission_name] = array(
        '#type' => 'item',
        '#markup' => $component_permission[$component_permission_name]['title'],
    );
    $options[$component_permission_name] = '';
    foreach ($role_names as $rid => $name) {
        if (isset($role_permissions[$rid][$component_permission_name])) {
            $status[$rid][] = $component_permission_name;
        }
    }
    // Build the checkboxes for each role.
    foreach ($role_names as $rid => $name) {
        $form['checkboxes'][$rid] = array(
            '#type' => 'checkboxes',
            '#options' => $options,
            '#default_value' => isset($status[$rid]) ? $status[$rid] : array(),
            '#attributes' => array(
                'class' => array(
                    'rid-' . $rid,
                ),
            ),
        );
        $form['role_names'][$rid] = array(
            '#markup' => check_plain($name),
            '#tree' => TRUE,
        );
    }
    // Attach the default permissions page JavaScript.
    $form['#attached']['js'][] = drupal_get_path('module', 'user') . '/user.permissions.js';
    return $form;
}