class LdapUserMappingToLdapForm in Lightweight Directory Access Protocol (LDAP) 8.4
Provides the form to configure user configuration and field mapping.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\ldap_user\Form\LdapUserMappingBaseForm implements LdapUserAttributesInterface
- class \Drupal\ldap_user\Form\LdapUserMappingToLdapForm
- class \Drupal\ldap_user\Form\LdapUserMappingBaseForm implements LdapUserAttributesInterface
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
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\FormView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LdapUserAttributesInterface:: |
public | constant | Event config. | |
LdapUserAttributesInterface:: |
public | constant | Config. | |
LdapUserAttributesInterface:: |
public | constant | Event config. | |
LdapUserAttributesInterface:: |
public | constant | Event config. | |
LdapUserAttributesInterface:: |
public | constant | Event config. | |
LdapUserAttributesInterface:: |
public | constant | Event config. | |
LdapUserAttributesInterface:: |
public | constant | Event config. | |
LdapUserAttributesInterface:: |
public | constant | Config. | |
LdapUserAttributesInterface:: |
public | constant | Config. | |
LdapUserAttributesInterface:: |
public | constant | Config. | |
LdapUserAttributesInterface:: |
public | constant | Config. | |
LdapUserAttributesInterface:: |
public | constant | Provision config. | |
LdapUserAttributesInterface:: |
public | constant | Provision config. | |
LdapUserAttributesInterface:: |
public | constant | Provision config. | |
LdapUserAttributesInterface:: |
public | constant | Provision config. | |
LdapUserAttributesInterface:: |
public | constant | Provision config. | |
LdapUserAttributesInterface:: |
public | constant | Provision config. | |
LdapUserAttributesInterface:: |
constant | Provision config. | ||
LdapUserAttributesInterface:: |
public | constant | Provision config. | |
LdapUserAttributesInterface:: |
public | constant | Provision config. | |
LdapUserAttributesInterface:: |
public | constant | Provision config. | |
LdapUserAttributesInterface:: |
public | constant | Config. | |
LdapUserAttributesInterface:: |
public | constant | Config. | |
LdapUserMappingBaseForm:: |
protected | property | Current config. | |
LdapUserMappingBaseForm:: |
protected | property | Entity type manager. | |
LdapUserMappingBaseForm:: |
protected | property | Field provider. | |
LdapUserMappingBaseForm:: |
protected | property | Module handler. | |
LdapUserMappingBaseForm:: |
protected | property | Server. | |
LdapUserMappingBaseForm:: |
private | function | Warn about fields without associated events. | |
LdapUserMappingBaseForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
LdapUserMappingBaseForm:: |
public | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
LdapUserMappingBaseForm:: |
protected | function | Return the server mappings for the fields. | |
LdapUserMappingBaseForm:: |
protected | function | Derive synchronization mappings from configuration. | |
LdapUserMappingBaseForm:: |
public | function | Functionality for our ajax callback. | |
LdapUserMappingBaseForm:: |
public | function | Ajax Callback for the form. | |
LdapUserMappingBaseForm:: |
private | function | Sanitize machine name. | |
LdapUserMappingBaseForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
LdapUserMappingBaseForm:: |
protected | function | Extract sync mappings array from mapping table in admin form. | |
LdapUserMappingBaseForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
LdapUserMappingToLdapForm:: |
protected | property |
Direction. Overrides LdapUserMappingBaseForm:: |
|
LdapUserMappingToLdapForm:: |
protected | property |
Events. Overrides LdapUserMappingBaseForm:: |
|
LdapUserMappingToLdapForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
LdapUserMappingToLdapForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
LdapUserMappingToLdapForm:: |
protected | function |
Get mapping form row to LDAP user provisioning mapping admin form table. Overrides LdapUserMappingBaseForm:: |
|
LdapUserMappingToLdapForm:: |
protected | function |
Set specific mapping. Overrides LdapUserMappingBaseForm:: |
|
LdapUserMappingToLdapForm:: |
public | function |
Constructs a \Drupal\system\ConfigFormBase object. Overrides LdapUserMappingBaseForm:: |
|
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |