You are here

public function SamlauthMappingListForm::buildForm in SAML Authentication 8.3

Same name and namespace in other branches
  1. 4.x modules/samlauth_user_fields/src/Form/SamlauthMappingListForm.php \Drupal\samlauth_user_fields\Form\SamlauthMappingListForm::buildForm()

Form for adding or editing a mapping.

Parameters

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

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

int $mapping_id: (optional) The numeric ID of the mapping.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

modules/samlauth_user_fields/src/Form/SamlauthMappingListForm.php, line 82

Class

SamlauthMappingListForm
Displays the list of attribute-field mappings; edits related configuration.

Namespace

Drupal\samlauth_user_fields\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $mapping_id = NULL) {
  $config = $this
    ->configFactory()
    ->get(UserFieldsEventSubscriber::CONFIG_OBJECT_NAME);

  // The bulk of this page is not a form at all, but a table. We're putting
  // that on the same page as the form options, because we have only two
  // checkboxes - which govern behavior related to the total of those table
  // rows. If this configuration form somehow grows, we'll split the table +
  // form off into separate pages/routes.
  $mappings = $config
    ->get('field_mappings');
  $form = $this
    ->listMappings(is_array($mappings) ? $mappings : []);
  if ($this
    ->configFactory()
    ->get(SamlController::CONFIG_OBJECT_NAME)
    ->get('map_users')) {
    $form['config'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Configuration for linking'),
    ];
    $form['config']['link_first_user'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Link first user if multiple found'),
      '#description' => $this
        ->t("If a link attempt matches multiple/'duplicate' users, link the first one and ignore the others. By default, login is denied and a Drupal administrator needs to decide what to do. (This never happens if matching is done on unique fields only, which is hopefully the case.)"),
      '#default_value' => $config
        ->get('link_first_user'),
    ];
    $form['config']['ignore_blocked'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Ignore blocked users'),
      '#description' => $this
        ->t("Never match/link blocked users. This may result in creating new users equal to a blocked user and granting them access - but enabling it (temporarily?) could help linking a correct user if 'duplicates' are matched. By default, if a blocked user is matched, it is linked then denied access."),
      '#default_value' => $config
        ->get('ignore_blocked'),
    ];
  }

  // @todo Do we also want a "Configuration for synchronization" section with
  //   one checkbox "Only take action on first login", like we have for roles?
  //   We also have separate checkboxes (but the inverse) for the name and
  //   email values. We could implement this option per field, but would that
  //   be overkill?
  return parent::buildForm($form, $form_state);
}