class MiniorangeMapping in OAuth2 Login 8
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\oauth2_login\Form\MiniorangeMapping
Expanded class hierarchy of MiniorangeMapping
1 string reference to 'MiniorangeMapping'
File
- src/
Form/ MiniorangeMapping.php, line 16 - Contains \Drupal\miniorange_oauth_client\Form\MiniorangeGeneralSettings.
Namespace
Drupal\oauth2_login\FormView source
class MiniorangeMapping extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'miniorange_mapping';
}
public function buildForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
global $base_url;
$form['markup_library'] = [
'#attached' => [
'library' => [
"oauth2_login/oauth2_login.admin",
"oauth2_login/oauth2_login.style_settings",
"oauth2_login/oauth2_login.Vtour",
],
],
];
$form['header_top_style_1'] = [
'#markup' => '<div class="mo_oauth_table_layout_1">',
];
$form['markup_top'] = [
'#markup' => '<div class="mo_oauth_table_layout mo_oauth_container">',
];
$form['markup_top_vt_start'] = [
'#markup' => '<h3>ATTRIBUTE MAPPING</h3><hr><br>',
];
$email_attr = \Drupal::config('oauth2_login.settings')
->get('miniorange_oauth_client_email_attr_val');
$name_attr = \Drupal::config('oauth2_login.settings')
->get('miniorange_oauth_client_name_attr_val');
$form['miniorange_oauth_client_email_attr'] = [
'#type' => 'textfield',
'#title' => t('Email Attribute: '),
'#default_value' => $email_attr,
'#description' => 'This field is mandatory for login',
'#required' => TRUE,
'#attributes' => [
'id' => 'mo_oauth_vt_attrn',
'style' => 'width:73%;',
'placeholder' => 'Enter Email Attribute',
],
];
$form['miniorange_oauth_client_name_attr'] = [
'#type' => 'textfield',
'#title' => t('Username Attribute: '),
'#description' => "<b>Note:</b> If this text field is empty, then by default email id will be the user's username",
'#default_value' => $name_attr,
'#attributes' => [
'id' => 'mo_oauth_vt_attre',
'style' => 'width:73%;',
'placeholder' => 'Enter Username Attribute',
],
];
$form['miniorange_oauth_client_attr_setup_button_2'] = [
'#type' => 'submit',
'#id' => 'button_config_center',
'#value' => t('Save Configuration'),
'#submit' => [
'::miniorange_oauth_client_attr_setup_submit',
],
];
$form['markup_cam'] = [
'#markup' => '<br><h3>CUSTOM ATTRIBUTE MAPPING</h3><hr><br>
<div class="mo_saml_highlight_background_note_1">Define your mapping in hook_oauth2_login_field_mapping(). See the example:<br>function MYMODULE_hook_oauth2_login_field_mapping(){
<br>return [\'REMOTE_FIELD\', \'LOCAL FIELD\'];
<br>} </div><br>',
];
$output = '';
$hook1 = 'oauth2_login_field_mapping';
$implementations = \Drupal::moduleHandler()
->getImplementations($hook1);
foreach ($implementations as $implementation) {
$func = $implementation . '_' . $hook1;
$output = '<li>' . $func . '</li>';
}
$form['markup_hook'] = [
'#markup' => '<h3>Hooks found.</h3><ul>' . $output . '</ul>',
];
$form['markup_role'] = [
'#markup' => '<br><h3>Custom Role Mapping</h3><hr><br>',
];
$form['miniorange_disable_attribute'] = [
'#type' => 'checkbox',
'#default_value' => \Drupal::config('oauth2_login.settings')
->get('miniorange_disable_attribute'),
'#title' => t('Do not update existing user's role.'),
];
$form['miniorange_oauth_disable_role_update'] = [
'#type' => 'checkbox',
'#default_value' => \Drupal::config('oauth2_login.settings')
->get('miniorange_oauth_disable_role_update'),
'#title' => t('Check this option if you do not want to update user role if roles not mapped. '),
];
$form['miniorange_oauth_disable_autocreate_users'] = [
'#type' => 'checkbox',
'#default_value' => \Drupal::config('oauth2_login.settings')
->get('miniorange_oauth_disable_autocreate_users'),
'#title' => t('Check this option if you want to disable <b>auto creation</b> of users if user does not exist. '),
];
$mrole = user_role_names($membersonly = TRUE);
$drole = array_values($mrole);
$form['miniorange_oauth_default_mapping'] = [
'#type' => 'select',
'#id' => 'miniorange_oauth_client_app',
'#title' => t('Select default group for the new users'),
'#options' => $mrole,
'#default_value' => \Drupal::config('oauth2_login.settings')
->get('miniorange_oauth_default_mapping'),
'#attributes' => [
'style' => 'width:73%;',
],
];
foreach ($mrole as $roles) {
$rolelabel = str_replace(' ', '', $roles);
$form['miniorange_oauth_role_' . $rolelabel] = [
'#type' => 'textfield',
'#title' => t($roles),
'#default_value' => \Drupal::config('oauth2_login.settings')
->get('miniorange_oauth_role_' . $rolelabel, ''),
'#attributes' => [
'style' => 'width:73%;background-color: hsla(0,0%,0%,0.08) !important;',
'placeholder' => 'Semi-colon(;) separated Group/Role value for ' . $roles,
],
];
}
$form['markup_role_signin'] = [
'#markup' => '<br><h3>Custom Login/Logout (Optional)</h3><hr>',
];
$form['miniorange_oauth_client_login_url'] = [
'#type' => 'textfield',
'#id' => 'text_field2',
'#default_value' => \Drupal::config('oauth2_login.settings')
->get('miniorange_oauth_client_login_url'),
'#required' => FALSE,
'#attributes' => [
'style' => 'width:73%;background-color: hsla(0,0%,0%,0.08) !important;',
'placeholder' => 'Enter Login URL',
],
];
$form['miniorange_oauth_client_logout_url'] = [
'#type' => 'textfield',
'#id' => 'text_field3',
'#required' => FALSE,
'#default_value' => \Drupal::config('oauth2_login.settings')
->get('miniorange_oauth_client_logout_url'),
'#attributes' => [
'style' => 'width:73%;background-color: hsla(0,0%,0%,0.08) !important;',
'placeholder' => 'Enter Logout URL',
],
];
$form['markup_role_break'] = [
'#markup' => '<br>',
];
$form['miniorange_oauth_client_attr_setup_button'] = [
'#type' => 'submit',
'#id' => 'button_config_center',
'#value' => t('Save Configuration'),
'#submit' => [
'::miniorange_oauth_client_attr_setup_submit2',
],
];
$form['mo_header_style_end'] = [
'#markup' => '</div>',
];
Utilities::show_attr_list_from_idp($form, $form_state);
$form['miniorange_idp_guide_link_end'] = [
'#markup' => '</div>',
];
Utilities::AddSupportButton($form, $form_state);
return $form;
}
public function submitForm(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) {
}
function miniorange_oauth_client_attr_setup_submit($form, $form_state) {
$email_attr = trim($form['miniorange_oauth_client_email_attr']['#value']);
$name_attr = trim($form['miniorange_oauth_client_name_attr']['#value']);
\Drupal::configFactory()
->getEditable('oauth2_login.settings')
->set('miniorange_oauth_client_email_attr_val', $email_attr)
->save();
\Drupal::configFactory()
->getEditable('oauth2_login.settings')
->set('miniorange_oauth_client_name_attr_val', $name_attr)
->save();
$app_values = \Drupal::config('oauth2_login.settings')
->get('miniorange_oauth_client_appval');
$app_values['miniorange_oauth_client_email_attr'] = $email_attr;
$app_values['miniorange_oauth_client_name_attr'] = $name_attr;
\Drupal::configFactory()
->getEditable('oauth2_login.settings')
->set('miniorange_oauth_client_appval', $app_values)
->save();
\Drupal::messenger()
->addMessage(t('Attribute Mapping saved successfully.'));
}
function miniorange_oauth_client_attr_setup_submit2($form, $form_state) {
$settings = \Drupal::configFactory()
->getEditable('oauth2_login.settings');
$settings
->set('miniorange_oauth_client_logout_url', $form['miniorange_oauth_client_logout_url']['#value'])
->save();
$settings
->set('miniorange_oauth_client_login_url', $form['miniorange_oauth_client_login_url']['#value'])
->save();
$settings
->set('miniorange_oauth_default_mapping', $form['miniorange_oauth_default_mapping']['#value'])
->save();
$settings
->set('miniorange_disable_attribute', $form['miniorange_disable_attribute']['#value'])
->save();
$settings
->set('miniorange_oauth_disable_role_update', $form['miniorange_oauth_disable_role_update']['#value'])
->save();
$settings
->set('miniorange_oauth_disable_autocreate_users', $form['miniorange_oauth_disable_autocreate_users']['#value'])
->save();
\Drupal::messenger()
->addMessage(t('Role Mapping saved successfully.'));
}
/**
* Send support query.
*/
public function saved_support(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) {
$email = trim($form['miniorange_oauth_client_email_address']['#value']);
$phone = trim($form['miniorange_oauth_client_phone_number']['#value']);
$query = trim($form['miniorange_oauth_client_support_query']['#value']);
Utilities::send_support_query($email, $phone, $query);
}
function clear_attr_list(&$form, $form_state) {
\Drupal::configFactory()
->getEditable('oauth2_login.settings')
->clear('miniorange_oauth_client_attr_list_from_server')
->save();
Utilities::show_attr_list_from_idp($form, $form_state);
}
public function rfd(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) {
global $base_url;
$response = new RedirectResponse($base_url . "/admin/config/people/oauth2_login/request_for_demo");
$response
->send();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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 | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
87 |
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. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
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. | |
MiniorangeMapping:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
MiniorangeMapping:: |
function | |||
MiniorangeMapping:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
MiniorangeMapping:: |
function | |||
MiniorangeMapping:: |
function | |||
MiniorangeMapping:: |
public | function | ||
MiniorangeMapping:: |
public | function | Send support query. | |
MiniorangeMapping:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
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. |