You are here

private function LdapUserAdminForm::getSyncFormRow in Lightweight Directory Access Protocol (LDAP) 8.3

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

Parameters

string $action: Action is either add, update, or nonconfigurable.

string $direction: LdapUserAttributesInterface::PROVISION_TO_DRUPAL or LdapUserAttributesInterface::PROVISION_TO_LDAP.

array $mapping: Is current setting for updates or nonconfigurable items.

array $userAttributeOptions: Attributes of Drupal user target options.

int $rowId: Is current row in table.

Return value

array A single row

1 call to LdapUserAdminForm::getSyncFormRow()
LdapUserAdminForm::getServerMappingFields in ldap_user/src/Form/LdapUserAdminForm.php
Return the server mappings for the fields.

File

ldap_user/src/Form/LdapUserAdminForm.php, line 849

Class

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

Namespace

Drupal\ldap_user\Form

Code

private function getSyncFormRow($action, $direction, array $mapping, array $userAttributeOptions, $rowId) {
  $result = [];
  $idPrefix = 'mappings__' . $direction . '__table';
  $userAttributeInputeId = $idPrefix . "[{$rowId}][user_attr]";
  if ($action == 'nonconfigurable') {
    $ldapAttribute = [
      '#type' => 'item',
      '#default_value' => isset($mapping['ldap_attr']) ? $mapping['ldap_attr'] : '',
      '#markup' => isset($mapping['source']) ? $mapping['source'] : '?',
      '#attributes' => [
        'class' => [
          'source',
        ],
      ],
    ];
  }
  else {
    $ldapAttribute = [
      '#type' => 'textfield',
      '#title' => 'LDAP attribute',
      '#title_display' => 'invisible',
      '#default_value' => isset($mapping['ldap_attr']) ? $mapping['ldap_attr'] : '',
      '#size' => 20,
      '#maxlength' => 255,
      '#attributes' => [
        'class' => [
          'ldap-attr',
        ],
      ],
    ];

    // Change the visibility rules if provisioning to LDAP.
    if ($direction == self::PROVISION_TO_LDAP) {
      $userTokens = [
        '#type' => 'textfield',
        '#title' => 'User tokens',
        '#title_display' => 'invisible',
        '#default_value' => isset($mapping['user_tokens']) ? $mapping['user_tokens'] : '',
        '#size' => 20,
        '#maxlength' => 255,
        '#disabled' => $action == 'nonconfigurable',
        '#attributes' => [
          'class' => [
            'tokens',
          ],
        ],
      ];
      $userTokens['#states'] = [
        'visible' => [
          'select[name="' . $userAttributeInputeId . '"]' => [
            'value' => 'user_tokens',
          ],
        ],
      ];
    }
  }
  $convert = [
    '#type' => 'checkbox',
    '#title' => 'Convert from binary',
    '#title_display' => 'invisible',
    '#default_value' => isset($mapping['convert']) ? $mapping['convert'] : '',
    '#disabled' => $action == 'nonconfigurable',
    '#attributes' => [
      'class' => [
        'convert',
      ],
    ],
  ];
  if ($action == 'nonconfigurable') {
    $userAttribute = [
      '#type' => 'item',
      '#markup' => isset($mapping['name']) ? $mapping['name'] : '?',
    ];
  }
  else {
    $userAttribute = [
      '#type' => 'select',
      '#title' => 'User attribute',
      '#title_display' => 'invisible',
      '#default_value' => isset($mapping['user_attr']) ? $mapping['user_attr'] : '',
      '#options' => $userAttributeOptions,
    ];
  }

  // Get the order of the columns correctly.
  if ($direction == self::PROVISION_TO_LDAP) {
    $result['user_attr'] = $userAttribute;
    $result['user_tokens'] = $userTokens;
    $result['convert'] = $convert;
    $result['ldap_attr'] = $ldapAttribute;
  }
  else {
    $result['ldap_attr'] = $ldapAttribute;
    $result['convert'] = $convert;
    $result['user_attr'] = $userAttribute;
  }
  $result['#storage']['sync_mapping_fields'][$direction] = [
    'action' => $action,
    'direction' => $direction,
  ];

  // FIXME: Add table selection / ordering back:
  // $col and $row used to be paremeters to $result[$prov_event]. ID possible
  // not need needed anymore. Row used to be a parameter to this function.
  // $col = ($direction == LdapUserAttributesInterface::PROVISION_TO_LDAP) ?
  // 5 : 4;.
  if ($direction == self::PROVISION_TO_DRUPAL) {
    $syncEvents = LdapConfiguration::provisionsDrupalEvents();
  }
  else {
    $syncEvents = $this
      ->provisionsLdapEvents();
  }
  foreach ($syncEvents as $prov_event => $prov_event_name) {

    // @FIXME: Leftover code.
    // See above.
    // $col++;
    // $id = $id_prefix . implode('__', array('sm', $prov_event, $row));.
    $result[$prov_event] = [
      '#type' => 'checkbox',
      '#title' => $prov_event,
      '#title_display' => 'invisible',
      '#default_value' => isset($mapping['prov_events']) ? (int) in_array($prov_event, $mapping['prov_events']) : '',
      '#disabled' => !$this
        ->provisionEventConfigurable($prov_event, $mapping) || $action == 'nonconfigurable',
      '#attributes' => [
        'class' => [
          'sync-method',
        ],
      ],
    ];
  }

  // This one causes the extra column.
  $result['configurable_to_drupal'] = [
    '#type' => 'hidden',
    '#default_value' => $action != 'nonconfigurable' ? 1 : 0,
    '#class' => '',
  ];
  return $result;
}