function workflow_access_form in Workflow 7
Same name and namespace in other branches
- 7.2 workflow_access/workflow_access.pages.inc \workflow_access_form()
Implements hook_form().
Add a "three dimensional" (state, role, permission type) configuration interface to the workflow edit form.
1 string reference to 'workflow_access_form'
- workflow_access_menu in workflow_access/
workflow_access.module - Implements hook_menu().
File
- workflow_access/
workflow_access.module, line 108 - Provides node access permissions based on workflow states.
Code
function workflow_access_form($form, $form_state, $workflow) {
if ($workflow) {
drupal_set_title(t('@name Access', array(
'@name' => $workflow
->getName(),
)));
}
else {
drupal_set_message(t('Unknown workflow'));
drupal_goto('admin/config/workflow/workflow');
}
$bc = array(
l(t('Home'), '<front>'),
);
$bc[] = l(t('Configuration'), 'admin/config');
$bc[] = l(t('Workflow'), 'admin/config/workflow');
$bc[] = l(t('Workflow'), 'admin/config/workflow/workflow');
$bc[] = l(t($workflow->name), "admin/config/workflow/workflow/{$workflow->wid}");
// $bc[] = l(t('Access'), "admin/config/workflow/access/$workflow->wid");
drupal_set_breadcrumb($bc);
$form = array(
'#tree' => TRUE,
);
$form['#wid'] = $workflow->wid;
// A list of roles available on the site and our
// special -1 role used to represent the node author.
$rids = user_roles(FALSE, 'participate in workflow');
$rids['-1'] = t('author');
// Add a table for every workflow state.
foreach ($workflow
->getStates() as $state) {
if ($state
->isCreationState()) {
// No need to set perms on creation.
continue;
}
$view = $update = $delete = array();
$count = 0;
foreach (workflow_access_get_workflow_access_by_sid($state->sid) as $access) {
$count++;
if ($access->grant_view) {
$view[] = $access->rid;
}
if ($access->grant_update) {
$update[] = $access->rid;
}
if ($access->grant_delete) {
$delete[] = $access->rid;
}
}
// Allow view grants by default for anonymous and authenticated users,
// if no grants were set up earlier.
if (!$count) {
$view = array(
DRUPAL_ANONYMOUS_RID,
DRUPAL_AUTHENTICATED_RID,
);
}
// TODO better tables using a #theme function instead of direct #prefixing
$form[$state->sid] = array(
'#type' => 'fieldset',
'#title' => $state
->label(),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#tree' => TRUE,
);
$form[$state->sid]['view'] = array(
'#type' => 'checkboxes',
'#options' => $rids,
'#default_value' => $view,
'#title' => t('Roles who can view posts in this state'),
'#prefix' => '<table width="100%" style="border: 0;"><tbody style="border: 0;"><tr><td>',
);
$form[$state->sid]['update'] = array(
'#type' => 'checkboxes',
'#options' => $rids,
'#default_value' => $update,
'#title' => t('Roles who can edit posts in this state'),
'#prefix' => "</td><td>",
);
$form[$state->sid]['delete'] = array(
'#type' => 'checkboxes',
'#options' => $rids,
'#default_value' => $delete,
'#title' => t('Roles who can delete posts in this state'),
'#prefix' => "</td><td>",
'#suffix' => "</td></tr></tbody></table>",
);
}
$form['warning'] = array(
'#type' => 'markup',
'#markup' => '<p><strong>' . t('WARNING:') . '</strong> ' . t('Use of the "Edit any," "Edit own," and even "View published content" permissions
for the content type may override these access settings.') . '</p>',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
return $form;
// Place our block comfortably down the page.
$form['submit']['#weight'] = 10;
$form['#submit'][] = 'workflow_access_form_submit';
}