Commit 346acab4 authored by Roderik Muit's avatar Roderik Muit
Browse files

Issue #3284901: fix configuration screen to not show (and save) hardcoded configuration.

parent 9bf0a5d4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ class SamlauthMappingDeleteForm extends ConfirmFormBase {
   */
  public function buildForm(array $form, FormStateInterface $form_state, $mapping_id = NULL) {
    if ($mapping_id !== NULL) {
      $mappings = $this->configFactory()->get(UserFieldsEventSubscriber::CONFIG_OBJECT_NAME)->get('field_mappings');
      $mappings = $this->configFactory()->getEditable(UserFieldsEventSubscriber::CONFIG_OBJECT_NAME)->get('field_mappings');

      // Set these values for the confirm message to pick up on them.
      $this->attributeName = $mappings[$mapping_id]['attribute_name'];
+2 −2
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ class SamlauthMappingEditForm extends FormBase {
   */
  public function buildForm(array $form, FormStateInterface $form_state, $mapping_id = NULL) {
    $user_fields = $this->entityFieldManager->getFieldDefinitions('user', 'user');
    $mappings = $this->configFactory()->get(UserFieldsEventSubscriber::CONFIG_OBJECT_NAME)->get('field_mappings');
    $mappings = $this->configFactory()->getEditable(UserFieldsEventSubscriber::CONFIG_OBJECT_NAME)->get('field_mappings');

    // @todo make code that captures all attributes from a SAML authentication
    //   message (only if enabled here via a special temporary option) and
@@ -190,7 +190,7 @@ class SamlauthMappingEditForm extends FormBase {

    // If this is a new mapping, check to make sure a 'same' one isn't already
    // defined.
    $mappings = $this->configFactory()->get(UserFieldsEventSubscriber::CONFIG_OBJECT_NAME)->get('field_mappings');
    $mappings = $this->configFactory()->getEditable(UserFieldsEventSubscriber::CONFIG_OBJECT_NAME)->get('field_mappings');
    if (is_array($mappings)) {
      $our_mapping_id = $form_state->getValue('mapping_id');
      $our_match_id = $form_state->getValue('link_user_order');
+5 −10
Original line number Diff line number Diff line
@@ -51,12 +51,7 @@ class SamlauthMappingListForm extends ConfigFormBase {
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    // I'm using ConfigFormBase for the unified save button / message, but
    // don't want to use ConfigFormBase::config(), to keep a unified way of
    // getting config values in forms / not obfuscate call structures and get
    // confused later. So this method/value is unneeded, but ConfigFormBase
    // requires it. Let's make it empty.
    return [];
    return [UserFieldsEventSubscriber::CONFIG_OBJECT_NAME];
  }

  /**
@@ -80,7 +75,7 @@ class SamlauthMappingListForm extends ConfigFormBase {
   *   The form structure.
   */
  public function buildForm(array $form, FormStateInterface $form_state, $mapping_id = NULL) {
    $config = $this->configFactory()->get(UserFieldsEventSubscriber::CONFIG_OBJECT_NAME);
    $config = $this->config(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
@@ -90,7 +85,7 @@ class SamlauthMappingListForm extends ConfigFormBase {
    $mappings = $config->get('field_mappings');
    $form = $this->listMappings(is_array($mappings) ? $mappings : []);

    if ($this->configFactory()->get(SamlController::CONFIG_OBJECT_NAME)->get('map_users')) {
    if ($this->config(SamlController::CONFIG_OBJECT_NAME)->get('map_users')) {
      $form['config'] = [
        '#type' => 'fieldset',
        '#title' => $this->t('Configuration for linking'),
@@ -123,7 +118,7 @@ class SamlauthMappingListForm extends ConfigFormBase {
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->configFactory()->getEditable(UserFieldsEventSubscriber::CONFIG_OBJECT_NAME)
    $this->config(UserFieldsEventSubscriber::CONFIG_OBJECT_NAME)
      ->set('link_first_user', $form_state->getValue('link_first_user'))
      ->set('ignore_blocked', $form_state->getValue('ignore_blocked'))
      ->save();
@@ -141,7 +136,7 @@ class SamlauthMappingListForm extends ConfigFormBase {
   *   A renderable content array.
   */
  public function listMappings(array $mappings) {
    $linking_enabled = $this->configFactory()->get(SamlController::CONFIG_OBJECT_NAME)->get('map_users');
    $linking_enabled = $this->config(SamlController::CONFIG_OBJECT_NAME)->get('map_users');

    $output['table'] = [
      '#theme' => 'table',
+3 −8
Original line number Diff line number Diff line
@@ -49,12 +49,7 @@ class SamlauthRoleMappingForm extends ConfigFormBase {
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    // I'm using ConfigFormBase for the unified save button / message, but
    // don't want to use ConfigFormBase::config(), to keep a unified way of
    // getting config values in forms / not obfuscate call structures and get
    // confused later. So this method/value is unneeded, but ConfigFormBase
    // requires it. Let's make it empty.
    return [];
    return [UserRolesEventSubscriber::CONFIG_OBJECT_NAME];
  }

  /**
@@ -68,7 +63,7 @@ class SamlauthRoleMappingForm extends ConfigFormBase {
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this->configFactory()->get(UserRolesEventSubscriber::CONFIG_OBJECT_NAME);
    $config = $this->config(UserRolesEventSubscriber::CONFIG_OBJECT_NAME);
    $roles = $this->getRoleLabels();

    $form['only_first_login'] = [
@@ -258,7 +253,7 @@ class SamlauthRoleMappingForm extends ConfigFormBase {
      }
    }

    $this->configFactory()->getEditable(UserRolesEventSubscriber::CONFIG_OBJECT_NAME)
    $this->config(UserRolesEventSubscriber::CONFIG_OBJECT_NAME)
      ->set('only_first_login', $form_state->getValue('only_first_login'))
      ->set('unassign_roles', array_filter($form_state->getValue('unassign_roles')))
      ->set('default_roles', array_filter($form_state->getValue('default_roles')))
+3 −8
Original line number Diff line number Diff line
@@ -93,12 +93,7 @@ class SamlauthConfigureForm extends ConfigFormBase {
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    // I'm using ConfigFormBase for the unified save button / message, but
    // don't want to use ConfigFormBase::config(), to keep a unified way of
    // getting config values in forms / not obfuscate call structures and get
    // confused later. So this method/value is unneeded, but ConfigFormBase
    // requires it. Let's make it empty.
    return [];
    return [SamlController::CONFIG_OBJECT_NAME];
  }

  /**
@@ -112,7 +107,7 @@ class SamlauthConfigureForm extends ConfigFormBase {
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this->configFactory()->get(SamlController::CONFIG_OBJECT_NAME);
    $config = $this->config(SamlController::CONFIG_OBJECT_NAME);

    $form['saml_login_logout'] = [
      '#type' => 'details',
@@ -1420,7 +1415,7 @@ class SamlauthConfigureForm extends ConfigFormBase {
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $config = $this->configFactory()->getEditable(SamlController::CONFIG_OBJECT_NAME);
    $config = $this->config(SamlController::CONFIG_OBJECT_NAME);

    $sp_key_type = $form_state->getValue('sp_key_cert_type');
    if ($sp_key_type) {