class OpenIDConnectLoginForm in OpenID Connect / OAuth client 8
Same name and namespace in other branches
- 2.x src/Form/OpenIDConnectLoginForm.php \Drupal\openid_connect\Form\OpenIDConnectLoginForm
Provides the OpenID Connect login form.
@package Drupal\openid_connect\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\openid_connect\Form\OpenIDConnectLoginForm implements ContainerInjectionInterface
Expanded class hierarchy of OpenIDConnectLoginForm
File
- src/
Form/ OpenIDConnectLoginForm.php, line 18
Namespace
Drupal\openid_connect\FormView source
class OpenIDConnectLoginForm extends FormBase implements ContainerInjectionInterface {
/**
* The OpenID Connect session service.
*
* @var \Drupal\openid_connect\OpenIDConnectSession
*/
protected $session;
/**
* Drupal\openid_connect\Plugin\OpenIDConnectClientManager definition.
*
* @var \Drupal\openid_connect\Plugin\OpenIDConnectClientManager
*/
protected $pluginManager;
/**
* The OpenID Connect claims.
*
* @var \Drupal\openid_connect\OpenIDConnectClaims
*/
protected $claims;
/**
* The constructor.
*
* @param \Drupal\openid_connect\OpenIDConnectSession $session
* The OpenID Connect session service.
* @param \Drupal\openid_connect\Plugin\OpenIDConnectClientManager $plugin_manager
* The plugin manager.
* @param \Drupal\openid_connect\OpenIDConnectClaims $claims
* The OpenID Connect claims.
*/
public function __construct(OpenIDConnectSession $session, OpenIDConnectClientManager $plugin_manager, OpenIDConnectClaims $claims) {
$this->session = $session;
$this->pluginManager = $plugin_manager;
$this->claims = $claims;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('openid_connect.session'), $container
->get('plugin.manager.openid_connect_client'), $container
->get('openid_connect.claims'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'openid_connect_login_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$definitions = $this->pluginManager
->getDefinitions();
foreach ($definitions as $client_id => $client) {
if (!$this
->config('openid_connect.settings.' . $client_id)
->get('enabled')) {
continue;
}
$form['openid_connect_client_' . $client_id . '_login'] = [
'#type' => 'submit',
'#value' => $this
->t('Log in with @client_title', [
'@client_title' => $client['label'],
]),
'#name' => $client_id,
'#prefix' => '<div>',
'#suffix' => '</div>',
];
}
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->session
->saveDestination();
$client_name = $form_state
->getTriggeringElement()['#name'];
$configuration = $this
->config('openid_connect.settings.' . $client_name)
->get('settings');
/** @var \Drupal\openid_connect\Plugin\OpenIDConnectClientInterface $client */
$client = $this->pluginManager
->createInstance($client_name, $configuration);
$scopes = $this->claims
->getScopes($client);
$_SESSION['openid_connect_op'] = 'login';
$response = $client
->authorize($scopes, $form_state);
$form_state
->setResponse($response);
}
}
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:: |
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. | |
OpenIDConnectLoginForm:: |
protected | property | The OpenID Connect claims. | |
OpenIDConnectLoginForm:: |
protected | property | Drupal\openid_connect\Plugin\OpenIDConnectClientManager definition. | |
OpenIDConnectLoginForm:: |
protected | property | The OpenID Connect session service. | |
OpenIDConnectLoginForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
OpenIDConnectLoginForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
OpenIDConnectLoginForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
OpenIDConnectLoginForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
OpenIDConnectLoginForm:: |
public | function | The constructor. | |
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. |