You are here

public function UserLoginBlock::build in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/Plugin/Block/UserLoginBlock.php \Drupal\user\Plugin\Block\UserLoginBlock::build()

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

core/modules/user/src/Plugin/Block/UserLoginBlock.php, line 90
Contains \Drupal\user\Plugin\Block\UserLoginBlock.

Class

UserLoginBlock
Provides a 'User login' block.

Namespace

Drupal\user\Plugin\Block

Code

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('<current>', [], [
    'query' => $this
      ->getDestinationArray(),
    'external' => FALSE,
  ]);

  // Build action links.
  $items = array();
  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', array(), array(
      'attributes' => array(
        'title' => $this
          ->t('Create a new user account.'),
        'class' => array(
          'create-account-link',
        ),
      ),
    )));
  }
  $items['request_password'] = \Drupal::l($this
    ->t('Reset your password'), new Url('user.pass', array(), array(
    'attributes' => array(
      'title' => $this
        ->t('Send password reset instructions via email.'),
      'class' => array(
        'request-password-link',
      ),
    ),
  )));
  return array(
    'user_login_form' => $form,
    'user_links' => array(
      '#theme' => 'item_list',
      '#items' => $items,
    ),
  );
}