You are here

public function RoleForceForm::buildForm in Force Password Change 2.0.x

Same name and namespace in other branches
  1. 8 src/Form/RoleForceForm.php \Drupal\force_password_change\Form\RoleForceForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/RoleForceForm.php, line 75

Class

RoleForceForm

Namespace

Drupal\force_password_change\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, RoleInterface $role = NULL) {
  if ($role) {
    if ($this->configFactory
      ->get('force_password_change.settings')
      ->get('check_login_only')) {
      $description = $this
        ->t('Users will be required to change their password upon their next login.');
    }
    else {
      $description = $this
        ->t('Users who are not signed in will be required to change their password immediately upon login. Users who are currently signed in will be required to change their password upon their next page click, but after changing their password will be redirected back to the page they were attempting to access.');
    }
    $description .= '<br />' . $this
      ->t('Note: When you return to this page, this box will be unchecked. This is because this setting is a trigger, not a persistant state.');
    $form['force_password_change'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Force users in this role to change their password'),
      '#description' => $description,
      '#weight' => -1,
    ];
    $form['role'] = [
      '#type' => 'value',
      '#value' => $role,
    ];
    $form['actions'] = [
      '#type' => 'actions',
    ];
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Force Password Change'),
    ];
  }
  else {
    $form['no_role'] = [
      '#prefix' => '<p>',
      '#suffix' => '</p>',
      '#markup' => $this
        ->t('No role supplied'),
    ];
  }
  return $form;
}