You are here

SocialUserLoginBlock.php in Open Social 8

File

modules/social_features/social_user/src/Plugin/Block/SocialUserLoginBlock.php
View source
<?php

namespace Drupal\social_user\Plugin\Block;

use Drupal\user\Plugin\Block\UserLoginBlock;
use Drupal\Core\Url;

/**
 * Provides a 'SocialUserLoginBlock' block.
 *
 * @Block(
 *  id = "social_user_login_block",
 *  admin_label = @Translation("Social user login block"),
 * )
 */
class SocialUserLoginBlock extends UserLoginBlock {

  /**
   * {@inheritdoc}
   */
  public function build() {
    $form = \Drupal::formBuilder()
      ->getForm('Drupal\\social_user\\Form\\SocialUserLoginForm');
    unset($form['name_or_mail']['#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_or_mail']['#description']);
    unset($form['name_or_mail']['#attributes']['aria-describedby']);
    unset($form['pass']['#description']);
    unset($form['pass']['#attributes']['aria-describedby']);
    $form['name_or_mail']['#size'] = 15;
    $form['pass']['#size'] = 15;
    $form['#action'] = $this
      ->url('<current>', [], [
      'query' => $this
        ->getDestinationArray(),
      'external' => FALSE,
    ]);

    // Build action links.
    $items = [];
    if (\Drupal::config('user.settings')
      ->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) {
      $items['create_account'] = \Drupal::l($this
        ->t('Create new account'), new Url('user.register', [], [
        'attributes' => [
          'title' => $this
            ->t('Create a new user account.'),
          'class' => [
            'create-account-link',
          ],
        ],
      ]));
    }
    $items['request_password'] = \Drupal::l($this
      ->t('Reset your password'), new Url('user.pass', [], [
      'attributes' => [
        'title' => $this
          ->t('Send password reset instructions via email.'),
        'class' => [
          'request-password-link',
        ],
      ],
    ]));
    return [
      'social_user_login_form' => $form,
      'user_links' => [
        '#theme' => 'item_list',
        '#items' => $items,
      ],
    ];
  }

}

Classes

Namesort descending Description
SocialUserLoginBlock Provides a 'SocialUserLoginBlock' block.