You are here

protected function LdapUserMappingToLdapForm::getMappingRow in Lightweight Directory Access Protocol (LDAP) 8.4

Get mapping form row to LDAP user provisioning mapping admin form table.

Parameters

\Drupal\ldap_servers\Mapping $mapping: Is current setting for updates or non-configurable items.

array $target_fields: Attributes of Drupal user target options.

int $row_id: Only needed for LDAP.

Return value

array Row.

Overrides LdapUserMappingBaseForm::getMappingRow

File

ldap_user/src/Form/LdapUserMappingToLdapForm.php, line 165

Class

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

Namespace

Drupal\ldap_user\Form

Code

protected function getMappingRow(Mapping $mapping, array $target_fields, int $row_id) : array {
  $result = [];
  if ($mapping
    ->isConfigurable()) {
    $result['source'] = [
      '#type' => 'select',
      '#title' => 'User attribute',
      '#title_display' => 'invisible',
      '#default_value' => $mapping
        ->getDrupalAttribute(),
      '#options' => $target_fields,
    ];
    $result['user_tokens'] = [
      '#type' => 'textfield',
      '#title' => 'User tokens',
      '#title_display' => 'invisible',
      '#default_value' => $mapping
        ->getUserTokens(),
      '#size' => 20,
      '#maxlength' => 255,
      '#attributes' => [
        'class' => [
          'tokens',
        ],
      ],
      '#states' => [
        'visible' => [
          sprintf('select[name="mappings[%s][source]"]', $row_id) => [
            'value' => 'user_tokens',
          ],
        ],
      ],
    ];
    $result['convert'] = [
      '#type' => 'checkbox',
      '#title' => 'Convert from binary',
      '#title_display' => 'invisible',
      '#default_value' => $mapping
        ->isBinary(),
      '#attributes' => [
        'class' => [
          'convert',
        ],
      ],
    ];
    $result['target'] = [
      '#type' => 'textfield',
      '#title' => 'LDAP attribute',
      '#title_display' => 'invisible',
      '#default_value' => $mapping
        ->getLdapAttribute(),
      '#size' => 20,
      '#maxlength' => 255,
      '#attributes' => [
        'class' => [
          'ldap-attr',
        ],
      ],
    ];
  }
  else {
    $result['source'] = [
      '#type' => 'item',
      '#markup' => $mapping
        ->getLabel(),
    ];
    $result['user_tokens'] = [];
    $result['convert'] = [
      '#type' => 'checkbox',
      '#title' => 'Convert from binary',
      '#title_display' => 'invisible',
      '#default_value' => $mapping
        ->isBinary(),
      '#disabled' => TRUE,
      '#attributes' => [
        'class' => [
          'convert',
        ],
      ],
    ];
    $result['target'] = [
      '#type' => 'item',
      '#default_value' => $mapping
        ->getLdapAttribute(),
      '#markup' => $mapping
        ->getLdapAttribute(),
      '#attributes' => [
        'class' => [
          'source',
        ],
      ],
    ];
  }
  foreach ($this->events as $event) {
    $result[$event] = [
      '#type' => 'checkbox',
      '#title' => $event,
      '#title_display' => 'invisible',
      '#default_value' => $mapping
        ->hasProvisioningEvent($event),
      '#disabled' => !$mapping
        ->isConfigurable(),
      '#attributes' => [
        'class' => [
          'sync-method',
        ],
      ],
    ];
  }
  $result['delete'] = [
    '#type' => 'checkbox',
    '#default_value' => 0,
  ];
  $result['configured_mapping'] = [
    '#type' => 'value',
    '#value' => $mapping
      ->isConfigurable(),
  ];
  return $result;
}