X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fuser%2Fsrc%2FPlugin%2FBlock%2FUserLoginBlock.php;fp=web%2Fcore%2Fmodules%2Fuser%2Fsrc%2FPlugin%2FBlock%2FUserLoginBlock.php;h=ed0e2eaf1a8a7e12dac4ab85fe28ff52f50d6609;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/user/src/Plugin/Block/UserLoginBlock.php b/web/core/modules/user/src/Plugin/Block/UserLoginBlock.php new file mode 100644 index 000000000..ed0e2eaf1 --- /dev/null +++ b/web/core/modules/user/src/Plugin/Block/UserLoginBlock.php @@ -0,0 +1,131 @@ +routeMatch = $route_match; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('current_route_match') + ); + } + + + /** + * {@inheritdoc} + */ + protected function blockAccess(AccountInterface $account) { + $route_name = $this->routeMatch->getRouteName(); + if ($account->isAnonymous() && !in_array($route_name, ['user.login', 'user.logout'])) { + return AccessResult::allowed() + ->addCacheContexts(['route.name', 'user.roles:anonymous']); + } + return AccessResult::forbidden(); + } + + /** + * {@inheritdoc} + */ + public function build() { + $form = \Drupal::formBuilder()->getForm('Drupal\user\Form\UserLoginForm'); + unset($form['name']['#attributes']['autofocus']); + // When unsetting field descriptions, also unset aria-describedby attributes + // to avoid introducing an accessibility bug. + // @todo Do this automatically in https://www.drupal.org/node/2547063. + unset($form['name']['#description']); + unset($form['name']['#attributes']['aria-describedby']); + unset($form['pass']['#description']); + unset($form['pass']['#attributes']['aria-describedby']); + $form['name']['#size'] = 15; + $form['pass']['#size'] = 15; + $form['#action'] = $this->url('', [], ['query' => $this->getDestinationArray(), 'external' => FALSE]); + // Build action links. + $items = []; + if (\Drupal::config('user.settings')->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) { + $items['create_account'] = [ + '#type' => 'link', + '#title' => $this->t('Create new account'), + '#url' => Url::fromRoute('user.register', [], [ + 'attributes' => [ + 'title' => $this->t('Create a new user account.'), + 'class' => ['create-account-link'], + ], + ]), + ]; + } + $items['request_password'] = [ + '#type' => 'link', + '#title' => $this->t('Reset your password'), + '#url' => Url::fromRoute('user.pass', [], [ + 'attributes' => [ + 'title' => $this->t('Send password reset instructions via email.'), + 'class' => ['request-password-link'], + ], + ]), + ]; + return [ + 'user_login_form' => $form, + 'user_links' => [ + '#theme' => 'item_list', + '#items' => $items, + ], + ]; + } + +}