You are here

public function PermissionsLockForm::buildForm in Permissions Lock 8

.

Overrides ConfigFormBase::buildForm

File

src/Form/PermissionsLockForm.php, line 92

Class

PermissionsLockForm

Namespace

Drupal\permissions_lock\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = \Drupal::config('permissions_lock.settings');
  $default_roles = $config
    ->get('permissions_lock_locked_roles');
  $default_perms = $config
    ->get('permissions_lock_locked_perm');

  //$message = $config->get('permissions_lock_locked_roles');

  //echo '<pre>'; die(print_r());
  $permissions = array();
  foreach ($this->permissionHandler
    ->getPermissions() as $key => $value) {

    // echo '<pre>'; die(print_r($key));
    $permissions[$key] = $key;
  }
  $form['permissions_lock_roles'] = array(
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Roles'),
    '#weight' => 0,
    '#collapsible' => TRUE,
  );

  //$hook_lock_roles = permissions_lock_get_hook_data('role');
  $form['permissions_lock_roles']['permissions_lock_locked_roles'] = array(
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Locked roles'),
    '#description' => $this
      ->t("Users without the 'manage permissions unrestricted' permission will not be able to change permissions for the selected roles."),
    "#default_value" => $default_roles,
    '#options' => user_role_names(),
  );

  //if ($hook_lock_roles) {

  //}
  $form['permissions_lock_permissions'] = array(
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Permissions'),
    '#weight' => 0,
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['permissions_lock_permissions']['permissions_lock_locked_perm'] = array(
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Locked permissions'),
    '#description' => $this
      ->t("Specify which permissions will not be changeable by users without the 'manage permissions unrestricted' permission"),
    "#default_value" => $default_perms,
    '#options' => $permissions,
  );

  /* $hook_locks = permissions_lock_get_hook_data('permission');
      if ($hook_locks) {

      } */
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
    '#weight' => 15,
  );
  return $form;
}