You are here

function _acl_edit_form in ACL 8

Same name and namespace in other branches
  1. 6 acl.admin.inc \_acl_edit_form()
  2. 7 acl.admin.inc \_acl_edit_form()

Implementation of acl_edit_form().

1 call to _acl_edit_form()
acl_edit_form in ./acl.module
Provide a form to edit the ACL that can be embedded in other forms.

File

./acl.admin.inc, line 15
Implementations of administration functions for the acl module.

Code

function _acl_edit_form($acl_id, $label = NULL, $new_acl = FALSE) {
  $database = \Drupal::database();
  $accounts = array();
  if (!$new_acl) {

    // Ensure the ACL in question even exists.
    if (!($record = $database
      ->query("SELECT name, figure FROM {acl} WHERE acl_id = :acl_id", [
      'acl_id' => $acl_id,
    ])
      ->fetchAssoc())) {
      return array();
    }
    $result = $database
      ->query("SELECT u.uid, ud.name FROM {users} u INNER JOIN {users_field_data} ud ON u.uid = ud.uid LEFT JOIN {acl_user} aclu ON aclu.uid = u.uid WHERE acl_id = :acl_id", [
      'acl_id' => $acl_id,
    ]);
    foreach ($result as $account) {
      $accounts[$account->uid] = $account->name;
    }
  }
  if (!isset($label)) {
    if (isset($record['name'])) {
      $label = $record['name'];
    }
    elseif (isset($record['figure'])) {
      $label = $record['figure'];
    }
    else {
      $label = $acl_id;
    }
  }
  $form = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#title' => Html::escape($label),
    '#tree' => TRUE,
  );
  $form['acl_id'] = array(
    '#type' => 'value',
    '#value' => $acl_id,
  );
  $form['deletions'] = array(
    '#type' => 'checkboxes',
    '#options' => array(),
  );
  $form['delete_button'] = array(
    '#type' => 'button',
    '#name' => 'acl_' . $acl_id,
    '#value' => t('Remove Checked'),
    '#submit' => array(),
  );
  $form['add'] = array(
    '#type' => 'entity_autocomplete',
    '#target_type' => 'user',
    '#title' => t('Add user'),
    '#maxlength' => 60,
    '#size' => 40,
    '#selection_settings' => [
      'include_anonymous' => FALSE,
    ],
  );
  $form['add_button'] = array(
    '#type' => 'button',
    '#name' => 'acl_' . $acl_id,
    '#value' => t('Add User'),
    '#submit' => array(),
  );
  $form['user_list'] = array(
    '#type' => 'hidden',
    '#default_value' => serialize($accounts),
  );
  $form['#after_build'] = [
    '_acl_edit_form_after_build',
  ];
  return $form;
}