function workbench_access_user_form in Workbench Access 7
Assign sections to a user.
Parameters
$account: The user account being acted upon.
2 string references to 'workbench_access_user_form'
- workbench_access_menu in ./
workbench_access.module - Implements hook_menu().
- workbench_access_sections in ./
workbench_access.admin.inc - Show user sections.
File
- ./
workbench_access.admin.inc, line 363 - Workbench Access admin file.
Code
function workbench_access_user_form($form, &$form_state, $account) {
if (!isset($account->workbench_access)) {
$account = user_load($account->uid);
}
$active = workbench_access_get_active_tree();
$form = array();
$form['uid'] = array(
'#type' => 'value',
'#value' => $account->uid,
);
$form['helptext'] = array(
'#type' => 'markup',
'#markup' => '<p>' . t('The list below shows your editorial groups. You may edit any content in these sections and their children.') . '</p>',
);
if (user_access('assign_workbench_access')) {
$form['helptext']['#markup'] .= '<p>' . t('You may edit these settings by checking the proper options.') . '</p>';
}
$sections = $account->workbench_access;
$form['sections']['#tree'] = TRUE;
$active_items = array_keys($active['active']);
$section_items = array_keys($sections);
$parent = 0;
$used = array();
foreach ($active['tree'] as $section) {
$disabled = FALSE;
if (in_array($section['access_id'], $used)) {
continue;
}
if ($section['depth'] == 0) {
$display = FALSE;
$parent = $section['access_id'];
$collapsed = TRUE;
if (!empty($sections[$section['access_id']])) {
$collapsed = FALSE;
$display = TRUE;
}
elseif (!empty($section['children'])) {
$check = array_intersect($section_items, $section['children']);
if (!empty($check)) {
$collapsed = FALSE;
}
}
// Do we show inactive sections here?
if (!empty($active['active'][$section['access_id']])) {
$display = TRUE;
}
elseif (!empty($section['children'])) {
$check = array_intersect($active_items, $section['children']);
if (!empty($check)) {
$display = TRUE;
}
}
if ($display) {
$form['sections'][$parent] = array(
'#type' => 'fieldset',
'#title' => check_plain($section['name']),
'#collapsible' => TRUE,
'#collapsed' => $collapsed,
'#tree' => TRUE,
);
}
}
// Do we show inactive sections here?
if (isset($active['active'][$section['access_id']])) {
if (user_access('assign workbench access') && !empty($active['active'][$section['access_id']])) {
$string = str_repeat('-', $section['depth']) . ' ' . check_plain($section['name']);
if (isset($account->workbench_access_by_role[$section['access_id']])) {
$string .= '*';
$show_message = TRUE;
$disabled = TRUE;
}
$form['sections'][$parent][$section['access_id']] = array(
'#type' => 'checkbox',
'#title' => $section['depth'] == 0 ? t('All of @string', array(
'@string' => $string,
)) : t('@string', array(
'@string' => $string,
)),
'#default_value' => isset($sections[$section['access_id']]),
'#disabled' => !empty($disabled),
);
}
elseif (isset($sections[$section['access_id']])) {
$string = str_repeat('-', $section['depth']) . ' ' . check_plain($section['name']);
if (isset($account->workbench_access_by_role[$section['access_id']])) {
$string .= '*';
$show_message = TRUE;
}
$form['sections'][$parent][$section['access_id']] = array(
'#type' => 'markup',
'#markup' => $section['depth'] == 0 ? t('All of @string', array(
'@string' => $string,
)) : t('@string', array(
'@string' => $string,
)) . '<br />',
);
}
/* Unused. Here for reference.
elseif (variable_get('workbench_access_display_unassigned_sections', 0)) {
$form['sections'][$parent][$section['access_id']] = array(
'#type' => 'markup',
'#markup' => ($section['depth'] == 0 ? t('All of') . ' ' : '') . str_repeat('-', $section['depth']) . ' ' . check_plain($section['name']) . '<br />',
);
$form['sections'][$parent][$section['access_id']]['#prefix'] = '<span class="workbench-access-disabled">';
$form['sections'][$parent][$section['access_id']]['#suffix'] = '</span>';
} */
}
else {
$form['sections'][$parent][$section['access_id']] = array(
'#type' => 'value',
'#value' => 0,
);
}
$used[] = $section['access_id'];
}
if (!empty($show_message)) {
$form['sections'][$parent]['message'] = array(
'#type' => 'markup',
'#markup' => '<p>' . t('Items marked with an asterisk (*) are assigned by role.') . '</p>',
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save sections'),
'#access' => user_access('assign workbench access'),
);
return $form;
}