function workbench_access_settings_form in Workbench Access 7
Settings form for Workbench Access configuration.
1 string reference to 'workbench_access_settings_form'
- workbench_access_menu in ./
workbench_access.module - Implements hook_menu().
File
- ./
workbench_access.admin.inc, line 11 - Workbench Access admin file.
Code
function workbench_access_settings_form($form, &$form_state) {
// Make sure all hook_invocations exist.
workbench_access_load_include();
$info = module_invoke_all('workbench_access_info');
$options = array();
foreach ($info as $key => $value) {
$options[$key] = $value['name'] . '<div class="description">' . $value['description'] . '</div>';
}
$active = variable_get('workbench_access');
$form = array();
$form['help'] = array(
'#markup' => '<h2>' . t('Workbench Access settings') . '</h2>',
);
// Check for proper installation.
if (module_exists('taxonomy')) {
$vocabulary = workbench_access_sample_vocabulary();
$exists = workbench_access_vocabulary_exists($vocabulary);
if (!$exists && (empty($active) || $active == 'taxonomy')) {
$form['help']['#markup'] .= '<p>' . t('Install the <a href="!url">test configuration for Workbench</a>.', array(
'!url' => url('admin/config/workbench/access/install'),
)) . '</p>';
}
}
$form['workbench_access'] = array(
'#type' => 'radios',
'#title' => t('Active access scheme'),
'#options' => $options,
'#description' => t('Select the access scheme to use for the site.'),
'#required' => TRUE,
);
if ($active) {
$form['workbench_access']['#default_value'] = $active;
}
// Get the configuration options for the active schemes.
foreach ($info as $key => $value) {
if (!isset($info[$key]['configuration'])) {
$info[$key]['configuration'] = $key . '_workbench_access_configuration';
}
if (function_exists($info[$key]['configuration'])) {
$func = $info[$key]['configuration'];
$func($form, $form_state);
if (isset($form[$key . '_workbench_access_info'])) {
$form[$key . '_workbench_access_info']['#description'] = t('Changing this value in production may <em>disrupt</em> your workflow.');
}
foreach (array(
'validate',
'submit',
) as $action) {
if (function_exists($func . '_' . $action)) {
$form['#' . $action][] = $func . '_' . $action;
}
}
}
}
$types = node_type_get_types();
if (!empty($types)) {
$form['node_types'] = array(
'#type' => 'fieldset',
'#title' => t('Enabled content types'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
foreach ($types as $type => $data) {
$form['node_types']['workbench_access_node_type_' . $type] = array(
'#title' => check_plain($data->name),
'#type' => 'checkbox',
'#default_value' => variable_get('workbench_access_node_type_' . $type, 1),
);
}
$form['node_types']['message'] = array(
'#markup' => t('Only selected content types will have Workbench Access rules <em>enforced</em>.'),
);
// Set the field settings for field-based modules, if required.
if (!variable_get('workbench_access_custom_form', 1) && array_key_exists($active, $info) && empty($info[$active]['form_field'])) {
$form['field_elements'] = array(
'#type' => 'fieldset',
'#title' => t('Access control fields'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
'#description' => t('Set the field elements that control access to each content type.'),
);
if (!module_exists('field_property')) {
$form['field_elements']['#collapsed'] = FALSE;
$form['field_elements']['#description'] = '<strong>' . t('Installing and enabling the <a href="!url">Field Property module</a> is recommended.', array(
'!url' => 'http://drupal.org/project/field_property',
)) . '</strong><br />' . $form['field_elements']['#description'];
}
foreach ($types as $type => $data) {
$fields = workbench_access_get_assigned_fields($type);
$available = workbench_access_get_available_fields($type);
$name = node_type_get_name($type);
$controlled = variable_get('workbench_access_node_type_' . $type, 1);
if (empty($controlled)) {
$form['field_elements'][$type] = array(
'#type' => 'item',
'#title' => t('%type content type access control fields', array(
'%type' => $name,
)),
'#markup' => t('This content type is not under access control.'),
);
}
elseif (empty($available)) {
$message = t('The %type content type does not have any fields that can be used for access control.', array(
'%type' => $name,
));
drupal_set_message($message, 'warning', FALSE);
$form['field_elements'][$type] = array(
'#type' => 'item',
'#title' => t('%type content type fields', array(
'%type' => $name,
)),
'#markup' => $message,
);
}
else {
$field_options = array();
$default_options = array();
$message = '';
if (empty($fields)) {
$message = t('The %type content type does not have an access field configured.', array(
'%type' => $name,
));
drupal_set_message($message, 'warning', FALSE);
$field_options['wa-no-access-field'] = t('No access control field');
$default_options[] = 'wa-no-access-field';
}
foreach ($available as $field => $info) {
$field_options[$field] = t('!label (!field)', array(
'!label' => $info['instance_info']['label'],
'!field' => $field,
));
if (!empty($info['instance_info']['workbench_access_field'])) {
$default_options[$field] = $field;
}
}
$form['field_elements'][$type] = array(
'#type' => 'select',
'#title' => t('%type content type access control fields', array(
'%type' => $name,
)),
'#options' => $field_options,
'#default_value' => $default_options,
'#multiple' => variable_get('workbench_access_allow_multiple', 0),
'#description' => $message,
);
}
}
}
}
$form['workbench_access_label'] = array(
'#type' => 'textfield',
'#title' => t('Workbench Access message label'),
'#default_value' => variable_get('workbench_access_label', 'Section'),
'#description' => t('Text that will be shown in front of Workbench Access messages.'),
);
$form['workbench_access_auto_assign'] = array(
'#type' => 'checkbox',
'#title' => t('Automated section assignment'),
'#default_value' => variable_get('workbench_access_auto_assign', 1),
'#description' => t('Enable all sections automatically for the active scheme.'),
);
$form['workbench_access_allow_multiple'] = array(
'#type' => 'checkbox',
'#title' => t('Allow multiple section assignments'),
'#default_value' => variable_get('workbench_access_allow_multiple', 0),
'#description' => t('Let content be assigned to multiple sections.'),
);
$form['workbench_access_custom_form'] = array(
'#type' => 'checkbox',
'#title' => t('Require a Workbench Access form element'),
'#default_value' => variable_get('workbench_access_custom_form', 1),
'#description' => t('If not selected, Workbench Access settings will inherit from the standard node form.'),
);
$form = system_settings_form($form);
$form['#validate'][] = 'workbench_access_settings_validate';
$form['#submit'][] = 'workbench_access_settings_submit';
return $form;
}