You are here

class LdapUserMappingToLdapForm in Lightweight Directory Access Protocol (LDAP) 8.4

Provides the form to configure user configuration and field mapping.

Hierarchy

Expanded class hierarchy of LdapUserMappingToLdapForm

1 string reference to 'LdapUserMappingToLdapForm'
ldap_user.routing.yml in ldap_user/ldap_user.routing.yml
ldap_user/ldap_user.routing.yml

File

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

Namespace

Drupal\ldap_user\Form
View source
class LdapUserMappingToLdapForm extends LdapUserMappingBaseForm {

  /**
   * Direction.
   *
   * @var string
   */
  protected $direction = self::PROVISION_TO_LDAP;

  /**
   * Events.
   *
   * @var array
   */
  protected $events = [
    self::EVENT_CREATE_LDAP_ENTRY,
    self::EVENT_SYNC_TO_LDAP_ENTRY,
  ];

  /**
   * {@inheritdoc}
   */
  public function __construct(ConfigFactoryInterface $config_factory, ModuleHandler $module_handler, EntityTypeManagerInterface $entity_type_manager, FieldProvider $field_provider) {
    parent::__construct($config_factory, $module_handler, $entity_type_manager, $field_provider);
    $this->server = $this->currentConfig
      ->get('ldapEntryProvisionServer');
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() : string {
    return 'ldap_user_admin_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) : array {
    $form['header'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Mappings synced from Drupal to LDAP'),
      '#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 Drupal user attribute'),
        'rowspan' => 1,
        'colspan' => 3,
      ],
      [
        'data' => $this
          ->t('Target LDAP token'),
      ],
      [
        'data' => $this
          ->t('Synchronization event'),
        'colspan' => 2,
        'rowspan' => 1,
      ],
      [
        'data' => $this
          ->t('Delete'),
      ],
      [],
    ];
    $form['mappings']['second-header'] = [
      '#attributes' => [
        'class' => 'header',
      ],
      [
        '#title' => $this
          ->t('Note: Select <em>user tokens</em> to use token field.'),
        '#type' => 'item',
      ],
      [
        '#title' => $this
          ->t('Source Drupal user tokens such as: <ul><li>[property.name]</li><li>[field.field_fname]</li><li>[field.field_lname]</li></ul> Constants such as <em>from_drupal</em> or <em>18</em> should not be enclosed in [].'),
        '#type' => 'item',
      ],
      [
        '#title' => $this
          ->t('Convert From binary'),
        '#type' => 'item',
      ],
      [
        '#title' => $this
          ->t('Use singular token format such as: <ul><li>[sn]</li><li>[givenName]</li></ul>'),
        '#type' => 'item',
      ],
      [
        '#title' => $this
          ->t('On LDAP Entry Creation'),
        '#type' => 'item',
        '#class' => 'header-provisioning',
        '#rowspan' => 2,
      ],
      [
        '#title' => $this
          ->t('On Sync to LDAP Entry'),
        '#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' => 5,
      ],
    ];
    $form['actions']['#type'] = 'actions';
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => 'Save',
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * Set specific mapping.
   *
   * @param \Drupal\ldap_servers\Mapping $mapping
   *   Mapping.
   * @param array $row
   *   Row.
   */
  protected function setSpecificMapping(Mapping $mapping, array $row) : void {
    $mapping
      ->setDrupalAttribute(trim($row['source']));
    $mapping
      ->setLdapAttribute(trim($row['target']));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
LdapUserAttributesInterface::ACCOUNT_CREATION_LDAP_BEHAVIOUR public constant Event config.
LdapUserAttributesInterface::ACCOUNT_CREATION_USER_SETTINGS_FOR_LDAP public constant Config.
LdapUserAttributesInterface::EVENT_CREATE_DRUPAL_USER public constant Event config.
LdapUserAttributesInterface::EVENT_CREATE_LDAP_ENTRY public constant Event config.
LdapUserAttributesInterface::EVENT_LDAP_ASSOCIATE_DRUPAL_USER public constant Event config.
LdapUserAttributesInterface::EVENT_SYNC_TO_DRUPAL_USER public constant Event config.
LdapUserAttributesInterface::EVENT_SYNC_TO_LDAP_ENTRY public constant Event config.
LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_LDAP_ASSOCIATE public constant Config.
LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_NO_LDAP_ASSOCIATE public constant Config.
LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_REJECT public constant Config.
LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_SHOW_OPTION_ON_FORM public constant Config.
LdapUserAttributesInterface::PROVISION_DRUPAL_USER_ON_USER_AUTHENTICATION public constant Provision config.
LdapUserAttributesInterface::PROVISION_DRUPAL_USER_ON_USER_ON_MANUAL_CREATION public constant Provision config.
LdapUserAttributesInterface::PROVISION_DRUPAL_USER_ON_USER_UPDATE_CREATE public constant Provision config.
LdapUserAttributesInterface::PROVISION_LDAP_ENTRY_ON_USER_ON_USER_AUTHENTICATION public constant Provision config.
LdapUserAttributesInterface::PROVISION_LDAP_ENTRY_ON_USER_ON_USER_DELETE public constant Provision config.
LdapUserAttributesInterface::PROVISION_LDAP_ENTRY_ON_USER_ON_USER_UPDATE_CREATE public constant Provision config.
LdapUserAttributesInterface::PROVISION_TO_ALL constant Provision config.
LdapUserAttributesInterface::PROVISION_TO_DRUPAL public constant Provision config.
LdapUserAttributesInterface::PROVISION_TO_LDAP public constant Provision config.
LdapUserAttributesInterface::PROVISION_TO_NONE public constant Provision config.
LdapUserAttributesInterface::USER_CONFLICT_ATTEMPT_RESOLVE public constant Config.
LdapUserAttributesInterface::USER_CONFLICT_LOG public constant Config.
LdapUserMappingBaseForm::$currentConfig protected property Current config.
LdapUserMappingBaseForm::$entityTypeManager protected property Entity type manager.
LdapUserMappingBaseForm::$fieldProvider protected property Field provider.
LdapUserMappingBaseForm::$moduleHandler protected property Module handler.
LdapUserMappingBaseForm::$server protected property Server.
LdapUserMappingBaseForm::checkEmptyEvents private function Warn about fields without associated events.
LdapUserMappingBaseForm::create public static function Instantiates a new instance of this class. Overrides ConfigFormBase::create
LdapUserMappingBaseForm::getEditableConfigNames public function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
LdapUserMappingBaseForm::getServerMappingFields protected function Return the server mappings for the fields.
LdapUserMappingBaseForm::loadAvailableMappings protected function Derive synchronization mappings from configuration.
LdapUserMappingBaseForm::mappingsAddAnother public function Functionality for our ajax callback.
LdapUserMappingBaseForm::mappingsAjaxCallback public function Ajax Callback for the form.
LdapUserMappingBaseForm::sanitizeMachineName private function Sanitize machine name.
LdapUserMappingBaseForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
LdapUserMappingBaseForm::syncMappingsFromForm protected function Extract sync mappings array from mapping table in admin form.
LdapUserMappingBaseForm::validateForm public function Form validation handler. Overrides FormBase::validateForm
LdapUserMappingToLdapForm::$direction protected property Direction. Overrides LdapUserMappingBaseForm::$direction
LdapUserMappingToLdapForm::$events protected property Events. Overrides LdapUserMappingBaseForm::$events
LdapUserMappingToLdapForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
LdapUserMappingToLdapForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
LdapUserMappingToLdapForm::getMappingRow protected function Get mapping form row to LDAP user provisioning mapping admin form table. Overrides LdapUserMappingBaseForm::getMappingRow
LdapUserMappingToLdapForm::setSpecificMapping protected function Set specific mapping. Overrides LdapUserMappingBaseForm::setSpecificMapping
LdapUserMappingToLdapForm::__construct public function Constructs a \Drupal\system\ConfigFormBase object. Overrides LdapUserMappingBaseForm::__construct
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.