class UloginWidget in uLogin (advanced version) 8
Provides Ulogin widget.
Plugin annotation
@FormElement("ulogin_widget");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\Core\Render\Element\FormElement implements FormElementInterface
- class \Drupal\ulogin\Element\UloginWidget
- class \Drupal\Core\Render\Element\FormElement implements FormElementInterface
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of UloginWidget
3 #type uses of UloginWidget
- Ulogin::build in src/
Plugin/ Block/ Ulogin.php - Builds and returns the renderable array for this block plugin.
- ulogin_form_alter in ./
ulogin.module - Implements hook_form_alter().
- UserIdentity::buildForm in src/
Form/ UserIdentity.php - Form constructor.
File
- src/
Element/ UloginWidget.php, line 14
Namespace
Drupal\ulogin\ElementView source
class UloginWidget extends FormElement {
/**
* {@inheritdoc}
*/
public function getInfo() {
$enabled_providers = [
'vkontakte',
'odnoklassniki',
'mailru',
'facebook',
'twitter',
'google',
'yandex',
'livejournal',
'openid',
];
$enabled_providers = array_filter(\Drupal::config('ulogin.settings')
->get('providers_enabled') ?: array_combine($enabled_providers, $enabled_providers));
$main_providers = [
'vkontakte',
'odnoklassniki',
'mailru',
'facebook',
];
$main_providers = array_filter(\Drupal::config('ulogin.settings')
->get('providers_main') ?: array_combine($main_providers, $main_providers));
$required_fields = [
'first_name',
'last_name',
'email',
'nickname',
'bdate',
'sex',
'photo',
'photo_big',
'country',
'city',
];
$required_fields = array_filter(\Drupal::config('ulogin.settings')
->get('fields_required') ?: array_combine($required_fields, $required_fields));
$optional_fields = array_filter(\Drupal::config('ulogin.settings')
->get('fields_optional') ?: array_combine([
'phone',
], [
'phone',
]));
$class = get_class($this);
return [
'#input' => FALSE,
'#pre_render' => [
[
$class,
'preRenderUloginWidget',
],
],
'#theme' => 'ulogin_widget',
'#theme_wrappers' => [
'form_element',
],
'#ulogin_id' => 'ulogin',
'#ulogin_widget_id' => \Drupal::config('ulogin.settings')
->get('widget_id') ?: '',
'#title' => \Drupal::config('ulogin.settings')
->get('widget_title') ?: '',
'#weight' => \Drupal::config('ulogin.settings')
->get('widget_weight') ?: -100,
'#ulogin_display' => \Drupal::config('ulogin.settings')
->get('display') ?: 'panel',
'#ulogin_fields_required' => implode(',', $required_fields),
'#ulogin_fields_optional' => implode(',', $optional_fields),
'#ulogin_providers' => implode(',', array_intersect_assoc($main_providers, $enabled_providers)),
'#ulogin_hidden' => implode(',', array_diff_assoc($enabled_providers, $main_providers)),
'#ulogin_destination' => \Drupal::config('ulogin.settings')
->get('destination') ?: '',
'#ulogin_redirect' => \Drupal::config('ulogin.settings')
->get('redirect') ?: 0,
'#ulogin_icons_path' => \Drupal::config('ulogin.settings')
->get('icons_path') ?: '',
'#ulogin_icons' => [],
'#attached' => [
'library' => [
'ulogin/async',
],
],
];
}
/**
* Render API callback: Hides display of the upload or remove controls.
*
* Upload controls are hidden when a file is already uploaded. Remove controls
* are hidden when there is no file attached. Controls are hidden here instead
* of in \Drupal\file\Element\ManagedFile::processManagedFile(), because
* #access for these buttons depends on the managed_file element's #value. See
* the documentation of \Drupal\Core\Form\FormBuilderInterface::doBuildForm()
* for more detailed information about the relationship between #process,
* #value, and #access.
*
* Because #access is set here, it affects display only and does not prevent
* JavaScript or other untrusted code from submitting the form as though
* access were enabled. The form processing functions for these elements
* should not assume that the buttons can't be "clicked" just because they are
* not displayed.
*
* @see \Drupal\file\Element\ManagedFile::processManagedFile()
* @see \Drupal\Core\Form\FormBuilderInterface::doBuildForm()
*/
public static function preRenderUloginWidget($element) {
// If we already have a file, we don't want to show the upload controls.
$element['#ulogin_id'] = Html::getId($element['#ulogin_id']);
$element['#attached']['drupalSettings']['ulogin'][] = $element['#ulogin_id'];
if ($element['#ulogin_widget_id']) {
$element['#theme'] = 'ulogin_widget_id';
return $element;
}
if ($element['#ulogin_redirect']) {
$callback = 'Drupalulogintoken';
$redirect = '';
$element['#attached']['library'][] = 'ulogin/ulogin';
}
else {
$callback = '';
$redirect = UloginHelper::tokenUrl($element['#ulogin_destination']);
}
$element['#ulogin_data'] = 'display=' . $element['#ulogin_display'] . ';fields=' . $element['#ulogin_fields_required'] . ';optional=' . $element['#ulogin_fields_optional'] . ';callback=' . $callback . ';redirect_uri=' . $redirect;
if ($element['#ulogin_display'] == 'window') {
$element['#theme'] = 'ulogin_widget_window';
return $element;
}
if ($element['#ulogin_display'] == 'buttons') {
$element['#theme'] = 'ulogin_widget_buttons';
$icons = [];
if (!empty($element['#ulogin_icons_path'])) {
foreach (file_scan_directory($element['#ulogin_icons_path'], '//') as $icon) {
$icons[$icon->name] = $icon->uri;
}
}
if (empty($icons)) {
$icons = $element['#ulogin_icons'];
}
$element['icons'] = [];
foreach ($icons as $key => $value) {
$image_info = \Drupal::service('image.factory')
->get($value);
$element['icons'][] = [
'#theme' => 'image',
'#uri' => $value,
'#alt' => $key,
'#title' => $key,
'#width' => $image_info
->getWidth(),
'#height' => $image_info
->getHeight(),
'#attributes' => [
'data-uloginbutton' => $key,
'class' => 'ulogin-icon-' . $key,
],
];
}
return $element;
}
$element['#ulogin_data'] .= ';providers=' . $element['#ulogin_providers'] . ';hidden=' . $element['#ulogin_hidden'];
return $element;
}
}
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 | |
FormElement:: |
public static | function | Adds autocomplete functionality to elements. | |
FormElement:: |
public static | function | #process callback for #pattern form element property. | |
FormElement:: |
public static | function | #element_validate callback for #pattern form element property. | |
FormElement:: |
public static | function |
Determines how user input is mapped to an element's #value property. Overrides FormElementInterface:: |
15 |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
RenderElement:: |
public static | function | Adds Ajax information about an element to communicate with JavaScript. | |
RenderElement:: |
public static | function | Adds members of this group as actual elements for rendering. | |
RenderElement:: |
public static | function | Form element processing handler for the #ajax form property. | 1 |
RenderElement:: |
public static | function | Arranges elements into groups. | |
RenderElement:: |
public static | function |
Sets a form element's class attribute. Overrides ElementInterface:: |
|
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. | |
UloginWidget:: |
public | function |
Returns the element properties for this element. Overrides ElementInterface:: |
|
UloginWidget:: |
public static | function | Render API callback: Hides display of the upload or remove controls. |