You are here

protected function LdapUserMappingBaseForm::getServerMappingFields in Lightweight Directory Access Protocol (LDAP) 8.4

Return the server mappings for the fields.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: Form State.

Return value

array Returns the mappings

2 calls to LdapUserMappingBaseForm::getServerMappingFields()
LdapUserMappingToDrupalForm::buildForm in ldap_user/src/Form/LdapUserMappingToDrupalForm.php
Form constructor.
LdapUserMappingToLdapForm::buildForm in ldap_user/src/Form/LdapUserMappingToLdapForm.php
Form constructor.

File

ldap_user/src/Form/LdapUserMappingBaseForm.php, line 298

Class

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

Namespace

Drupal\ldap_user\Form

Code

protected function getServerMappingFields(FormStateInterface $form_state) : array {
  $rows = [];
  $user_attribute_options = [
    '0' => $this
      ->t('Select option'),
  ];
  if (!$this->server) {
    $this
      ->messenger()
      ->addWarning('You do not have a server configured for mapping.');
    return $rows;
  }
  $available_mappings = $this
    ->loadAvailableMappings($this->direction, $this->server);

  // Potential mappings (i.e. fields provided for the user entity) are
  // aggregated so that they can be input for user-defined mappings.
  // The difference being that these available mappings are not *enabled*.
  // Ideally, those would be split into something like a MappingProposal and
  // a MappingRule.

  /** @var \Drupal\ldap_servers\Mapping $mapping */
  foreach ($available_mappings as $target_id => $mapping) {
    if (!empty($mapping
      ->getId()) && $mapping
      ->isConfigurable()) {
      $user_attribute_options[$target_id] = $mapping
        ->getLabel();
    }
  }
  if ($this->direction === self::PROVISION_TO_LDAP) {
    $user_attribute_options['user_tokens'] = '-- user tokens --';
  }
  $index = 0;
  foreach ($available_mappings as $mapping) {
    if ($mapping
      ->isEnabled()) {
      $rows[$index] = $this
        ->getMappingRow($mapping, $user_attribute_options, $index);
      $index++;
    }
  }
  if (empty($form_state
    ->get('row_count'))) {
    $form_state
      ->set('row_count', $index + 1);
  }
  for ($i = $index; $i < $form_state
    ->get('row_count'); $i++) {
    $empty_mapping = new Mapping('', '', TRUE, TRUE, [], 'ldap_user', 'ldap_user');
    $rows[$i] = $this
      ->getMappingRow($empty_mapping, $user_attribute_options, $i);
  }
  return $rows;
}