You are here

function pm_permission_admin in Drupal PM (Project Management) 8

Same name and namespace in other branches
  1. 7.3 includes/pm.permission.inc \pm_permission_admin()

Admin settings form.

1 string reference to 'pm_permission_admin'
pm_menu in ./pm.module
Implements hook_menu().

File

includes/pm.permission.inc, line 10
Main module file for the pm_permission module.

Code

function pm_permission_admin() {
  $form = array();
  $form['pm_permission_node'] = array(
    '#type' => 'fieldset',
    '#title' => t('Select node bundles where you want to enable PM permissions'),
  );
  $form['pm_permission_field'] = array(
    '#type' => 'fieldset',
    '#title' => t('Configure reference fields'),
  );
  $node_types = array();
  foreach (node_type_get_types() as $type => $info) {
    $name = node_type_get_name($type);
    $node_types[$type] = $name;
    $form['pm_permission_node']["pm_permission_node_{$type}_enabled"] = array(
      '#type' => 'checkbox',
      '#title' => $name,
      '#default_value' => variable_get("pm_permission_node_{$type}_enabled", FALSE),
    );
    $options = _pm_permission_get_field_names_per_field_type('entityreference', 'node', $type);
    if (count($options['node']) < 2) {
      $form['pm_permission_field']["pm_permission_field_parent_reference_for_{$type}_message"] = array(
        '#type' => 'item',
        '#markup' => t('No configuration available for "@name"', array(
          '@name' => $name,
        )),
        '#states' => array(
          'visible' => array(
            ":input[name='pm_permission_node_{$type}_enabled']" => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
    }
    else {
      $form['pm_permission_field']["pm_permission_field_parent_reference_for_{$type}"] = array(
        '#type' => 'select',
        '#title' => t('Select parent reference field for "@name"', array(
          '@name' => $name,
        )),
        '#options' => $options['node'],
        '#default_value' => variable_get("pm_permission_field_parent_reference_for_{$type}", ''),
        '#states' => array(
          'visible' => array(
            ":input[name='pm_permission_node_{$type}_enabled']" => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
    }
  }
  $options = _pm_permission_get_field_names_per_field_type('entityreference');
  $form['pm_permission_field']['pm_permission_field_assigned_reference'] = array(
    '#type' => 'select',
    '#title' => t('Assigned reference field'),
    '#options' => $options['user'],
    '#disabled' => TRUE,
    '#default_value' => variable_get("pm_permission_field_assigned_reference", ''),
  );
  $form['pm_permission_field']['pm_permission_field_pm_reference'] = array(
    '#type' => 'select',
    '#title' => t('Project Manager reference field'),
    '#options' => $options['user'],
    '#disabled' => TRUE,
    '#default_value' => variable_get("pm_permission_field_pm_reference", ''),
  );
  $form['pm_permission_field']['pm_permission_field_org_member_reference'] = array(
    '#type' => 'select',
    '#title' => t('Organization member reference field'),
    '#options' => $options['user'],
    '#disabled' => TRUE,
    '#default_value' => variable_get("pm_permission_field_org_member_reference", ''),
  );
  $form['pm_permission_advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced Configuration'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['pm_permission_advanced']['pm_permission_override_core_permissions_agree'] = array(
    '#type' => 'checkbox',
    '#title' => t('I agree to override default core node permissions'),
    '#description' => t("Drupal core doesn't provide a UI to alter these settings. So make sure you revert the settings before you uninstall this module."),
    '#default_value' => FALSE,
  );
  $form['pm_permission_advanced']['pm_permission_override_core_permissions'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Node default core permission override'),
    '#default_value' => variable_get("pm_permission_override_core_permissions", array()),
    '#options' => $node_types,
    '#states' => array(
      'enabled' => array(
        ':input[name="pm_permission_override_core_permissions_agree"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form = system_settings_form($form);
  $form['#submit'][] = 'pm_permission_admin_submit';
  return $form;
}