public function UserLoginBlock::build

Builds and returns the renderable array for this block plugin.

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockRenderController

File

drupal/core/modules/user/lib/Drupal/user/Plugin/Block/UserLoginBlock.php, line 35
Contains \Drupal\user\Plugin\Block\UserLoginBlock.

Class

UserLoginBlock
Provides a 'User login' block.

Namespace

Drupal\user\Plugin\Block

Code

public function build() {
  $form = drupal_get_form('user_login_form');
  unset($form['name']['#attributes']['autofocus']);
  unset($form['name']['#description']);
  unset($form['pass']['#description']);
  $form['name']['#size'] = 15;
  $form['pass']['#size'] = 15;
  $form['#action'] = url(current_path(), array(
    'query' => drupal_get_destination(),
    'external' => FALSE,
  ));

  // Build action links.
  $items = array();
  if (config('user.settings')
    ->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) {
    $items['create_account'] = l(t('Create new account'), 'user/register', array(
      'attributes' => array(
        'title' => t('Create a new user account.'),
        'class' => array(
          'create-account-link',
        ),
      ),
    ));
  }
  $items['request_password'] = l(t('Request new password'), 'user/password', array(
    'attributes' => array(
      'title' => t('Request new password via e-mail.'),
      'class' => array(
        'request-password-link',
      ),
    ),
  ));
  return array(
    'user_login_form' => $form,
    'user_links' => array(
      '#theme' => 'item_list',
      '#items' => $items,
    ),
  );
}