You are here

public function LdapUserMappingToDrupalForm::buildForm in Lightweight Directory Access Protocol (LDAP) 8.4

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 ConfigFormBase::buildForm

File

ldap_user/src/Form/LdapUserMappingToDrupalForm.php, line 59

Class

LdapUserMappingToDrupalForm
Provides the form to configure user configuration and field mapping.

Namespace

Drupal\ldap_user\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) : array {
  $form['header'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Mappings synced from LDAP to Drupal'),
    '#description' => $this
      ->t('See also the <a href="@wiki_link">Drupal.org wiki page</a> for further information on using LDAP tokens.', [
      '@wiki_link' => 'https://drupal.org/node/1245736',
    ]),
  ];
  $form['mappings'] = [
    '#type' => 'table',
    '#header' => [
      $this
        ->t('Label'),
      $this
        ->t('Machine name'),
      $this
        ->t('Weight'),
      $this
        ->t('Operations'),
    ],
    '#attributes' => [
      'class' => [
        'mappings-table',
      ],
    ],
    '#prefix' => '<div id="ldap-user-mappings-wrapper">',
    '#suffix' => '</div>',
  ];
  $form['mappings']['#header'] = [
    [
      'data' => $this
        ->t('Source LDAP tokens'),
      'rowspan' => 1,
    ],
    [
      'data' => $this
        ->t('Convert from binary'),
    ],
    [
      'data' => $this
        ->t('Target Drupal attribute'),
      'rowspan' => 1,
    ],
    [
      'data' => $this
        ->t('Synchronization event'),
      'colspan' => 2,
      'rowspan' => 1,
    ],
    [
      'data' => $this
        ->t('Delete'),
    ],
    [],
  ];
  $form['mappings']['second-header'] = [
    '#attributes' => [
      'class' => 'header',
    ],
    [
      '#title' => $this
        ->t('Examples: [sn], [mail:0], [ou:last], [sn], [givenName].<br> Constants such as <em>17</em> or <em>imported</em> should not be enclosed in [].'),
      '#type' => 'item',
      '#colspan' => 2,
    ],
    [],
    [],
    [
      '#title' => $this
        ->t('On Drupal User Creation'),
      '#type' => 'item',
      '#class' => 'header-provisioning',
      '#rowspan' => 2,
    ],
    [
      '#title' => $this
        ->t('On Sync to Drupal User'),
      '#type' => 'item',
      '#class' => 'header-provisioning',
    ],
    [],
    [],
  ];
  $mappings_to_add = $this
    ->getServerMappingFields($form_state);
  if ($mappings_to_add) {
    $form['mappings'] += $mappings_to_add;
  }
  $form['mappings'][]['mappings_add_another'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Add Another'),
    '#submit' => [
      '::mappingsAddAnother',
    ],
    '#limit_validation_errors' => [],
    '#ajax' => [
      'callback' => '::mappingsAjaxCallback',
      'wrapper' => 'ldap-user-mappings-wrapper',
    ],
    '#weight' => 103,
    '#wrapper_attributes' => [
      'colspan' => 7,
    ],
  ];
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => 'Save',
  ];
  return $form;
}