class EmailRegistrationLogin in Email Registration 8
Provides the email registration login pane.
Plugin annotation
@CommerceCheckoutPane(
id = "email_registration_login",
label = @Translation("Login with email registration or continue as guest"),
default_step = "_disabled",
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase implements CheckoutPaneInterface, ContainerFactoryPluginInterface
- class \Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\Login implements CheckoutPaneInterface, ContainerFactoryPluginInterface
- class \Drupal\email_registration\Plugin\Commerce\CheckoutPane\EmailRegistrationLogin
- class \Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\Login implements CheckoutPaneInterface, ContainerFactoryPluginInterface
- class \Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase implements CheckoutPaneInterface, ContainerFactoryPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of EmailRegistrationLogin
File
- src/
Plugin/ Commerce/ CheckoutPane/ EmailRegistrationLogin.php, line 27
Namespace
Drupal\email_registration\Plugin\Commerce\CheckoutPaneView source
class EmailRegistrationLogin extends Login {
/**
* Constructs a new EmailRegistrationLogin object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowInterface $checkout_flow
* The parent checkout flow.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\commerce\CredentialsCheckFloodInterface $credentials_check_flood
* The credentials check flood controller.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\user\UserAuthInterface $user_auth
* The user authentication object.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param \Drupal\Core\Config\ImmutableConfig $config
* The email registration settings.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, CheckoutFlowInterface $checkout_flow, EntityTypeManagerInterface $entity_type_manager, CredentialsCheckFloodInterface $credentials_check_flood, AccountInterface $current_user, UserAuthInterface $user_auth, RequestStack $request_stack, ImmutableConfig $config) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $checkout_flow, $entity_type_manager, $credentials_check_flood, $current_user, $user_auth, $request_stack);
$this->config = $config;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, CheckoutFlowInterface $checkout_flow = NULL) {
return new static($configuration, $plugin_id, $plugin_definition, $checkout_flow, $container
->get('entity_type.manager'), $container
->get('commerce.credentials_check_flood'), $container
->get('current_user'), $container
->get('user.auth'), $container
->get('request_stack'), $container
->get('config.factory')
->get('email_registration.settings'));
}
/**
* {@inheritdoc}
*/
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
$pane_form = parent::buildPaneForm($pane_form, $form_state, $complete_form);
$login_with_username = $this->config
->get('login_with_username');
$pane_form['returning_customer']['name']['#title'] = $login_with_username ? $this
->t('Email address or username') : $this
->t('Email address');
$pane_form['returning_customer']['name']['#description'] = $login_with_username ? $this
->t('Enter your email address or username.') : $this
->t('Enter your email address.');
$pane_form['returning_customer']['name']['#element_validate'][] = 'email_registration_user_login_validate';
$pane_form['returning_customer']['name']['#type'] = $login_with_username ? 'textfield' : 'email';
$pane_form['returning_customer']['name']['#maxlength'] = Email::EMAIL_MAX_LENGTH;
$pane_form['returning_customer']['password']['#description'] = $this
->t('Enter the password that accompanies your email address.');
$complete_form['#cache']['tags'][] = 'config:email_registration.settings';
$pane_form['register']['name']['#type'] = 'value';
$pane_form['register']['name']['#value'] = 'email_registration_' . user_password();
$pane_form['register']['mail']['#title'] = $this
->t('Email');
return $pane_form;
}
/**
* {@inheritdoc}
*/
public function validatePaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
$subformId = $pane_form['#parents'][0];
$values = $form_state
->getValue($pane_form['#parents']);
$triggering_element = $form_state
->getTriggeringElement();
if ($triggering_element['#op'] === 'login') {
$mail = $values['returning_customer']['name'];
if (!empty($mail)) {
// Try to load the user by mail.
$user = user_load_by_mail($mail);
}
if (empty($user)) {
// Check if users are allowed to login with username as well.
if (!$this->config
->get('login_with_username')) {
// Users are not allowed to login with username. Since no user was
// found with the specified mail address, fail with an error and
// bail out.
$user_input = $form_state
->getUserInput();
$query = isset($user_input[$subformId]['returning_customer']['name']) ? [
'name' => $user_input[$subformId]['returning_customer']['name'],
] : [];
$form_state
->setError($pane_form['returning_customer'], $this
->t('Unrecognized email address or password. <a href=":password">Forgot your password?</a>', [
':password' => Url::fromRoute('user.pass', [], [
'query' => $query,
])
->toString(),
]));
return;
}
}
else {
// We have found an user! Save username on the form state, as that is
// what the parent class expects in their submit handler.
$username = $user
->getAccountName();
$form_state
->setValue([
$subformId,
'returning_customer',
'name',
], $username);
// Perform several checks for this user account
// Copied from parent to override error messages.
$name_element = $pane_form['returning_customer']['name'];
$password = trim($values['returning_customer']['password']);
// Generate the "reset password" url.
$query = !empty($username) ? [
'name' => $username,
] : [];
$password_url = Url::fromRoute('user.pass', [], [
'query' => $query,
])
->toString();
if (user_is_blocked($username)) {
$form_state
->setError($name_element, $this
->t('The account with email address %mail has not been activated or is blocked.', [
'%mail' => $mail,
]));
return;
}
$uid = $this->userAuth
->authenticate($username, $password);
if (!$uid) {
$this->credentialsCheckFlood
->register($this->clientIp, $username);
// Changing the wrong credentials error message.
if (!$this->config
->get('login_with_username')) {
$form_state
->setError($name_element, $this
->t('Unrecognized email address or password. <a href=":password">Forgot your password?</a>', [
':password' => $password_url,
]));
// Adding return to avoid the parent error when password is empty.
return;
}
else {
$form_state
->setError($name_element, $this
->t('Unrecognized username, email, or password. <a href=":url">Have you forgotten your password?</a>', [
':url' => $password_url,
]));
}
}
}
}
parent::validatePaneForm($pane_form, $form_state, $complete_form);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CheckoutPaneBase:: |
protected | property | The parent checkout flow. | |
CheckoutPaneBase:: |
protected | property | The entity type manager. | |
CheckoutPaneBase:: |
protected | property | The current order. | |
CheckoutPaneBase:: |
public | function |
Builds a summary of the pane values. Overrides CheckoutPaneInterface:: |
3 |
CheckoutPaneBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
CheckoutPaneBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
CheckoutPaneBase:: |
public | function |
Gets the pane display label. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Gets the pane ID. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Gets the pane label. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Gets the pane step ID. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Gets the pane weight. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Gets the pane wrapper element. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
CheckoutPaneBase:: |
public | function |
Sets the current order. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Sets the pane step ID. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Sets the pane weight. Overrides CheckoutPaneInterface:: |
|
CheckoutPaneBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
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 | |
EmailRegistrationLogin:: |
public | function |
Builds the pane form. Overrides Login:: |
|
EmailRegistrationLogin:: |
public static | function |
Creates an instance of the plugin. Overrides Login:: |
|
EmailRegistrationLogin:: |
public | function |
Validates the pane form. Overrides Login:: |
|
EmailRegistrationLogin:: |
public | function |
Constructs a new EmailRegistrationLogin object. Overrides Login:: |
|
Login:: |
protected | property | The client IP address. | |
Login:: |
protected | property | The credentials check flood controller. | |
Login:: |
protected | property | The current user. | |
Login:: |
protected | property | The language manager. | |
Login:: |
protected | property | The user authentication object. | |
Login:: |
public | function |
Form constructor. Overrides CheckoutPaneBase:: |
|
Login:: |
public | function |
Builds a summary of the pane configuration. Overrides CheckoutPaneBase:: |
|
Login:: |
protected | function | Checks whether guests can register after checkout is complete. | |
Login:: |
public | function |
Gets default configuration for this plugin. Overrides CheckoutPaneBase:: |
|
Login:: |
public | function |
Determines whether the pane is visible. Overrides CheckoutPaneBase:: |
|
Login:: |
public | function |
Form submission handler. Overrides CheckoutPaneBase:: |
|
Login:: |
public | function |
Handles the submission of an pane form. Overrides CheckoutPaneBase:: |
|
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. | |
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. |