You are here

public function SocialUserLoginBlock::build in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_user/src/Plugin/Block/SocialUserLoginBlock.php \Drupal\social_user\Plugin\Block\SocialUserLoginBlock::build()
  2. 8.2 modules/social_features/social_user/src/Plugin/Block/SocialUserLoginBlock.php \Drupal\social_user\Plugin\Block\SocialUserLoginBlock::build()
  3. 8.3 modules/social_features/social_user/src/Plugin/Block/SocialUserLoginBlock.php \Drupal\social_user\Plugin\Block\SocialUserLoginBlock::build()
  4. 8.4 modules/social_features/social_user/src/Plugin/Block/SocialUserLoginBlock.php \Drupal\social_user\Plugin\Block\SocialUserLoginBlock::build()
  5. 8.5 modules/social_features/social_user/src/Plugin/Block/SocialUserLoginBlock.php \Drupal\social_user\Plugin\Block\SocialUserLoginBlock::build()
  6. 8.6 modules/social_features/social_user/src/Plugin/Block/SocialUserLoginBlock.php \Drupal\social_user\Plugin\Block\SocialUserLoginBlock::build()
  7. 8.7 modules/social_features/social_user/src/Plugin/Block/SocialUserLoginBlock.php \Drupal\social_user\Plugin\Block\SocialUserLoginBlock::build()
  8. 8.8 modules/social_features/social_user/src/Plugin/Block/SocialUserLoginBlock.php \Drupal\social_user\Plugin\Block\SocialUserLoginBlock::build()
  9. 10.3.x modules/social_features/social_user/src/Plugin/Block/SocialUserLoginBlock.php \Drupal\social_user\Plugin\Block\SocialUserLoginBlock::build()
  10. 10.0.x modules/social_features/social_user/src/Plugin/Block/SocialUserLoginBlock.php \Drupal\social_user\Plugin\Block\SocialUserLoginBlock::build()
  11. 10.1.x modules/social_features/social_user/src/Plugin/Block/SocialUserLoginBlock.php \Drupal\social_user\Plugin\Block\SocialUserLoginBlock::build()
  12. 10.2.x modules/social_features/social_user/src/Plugin/Block/SocialUserLoginBlock.php \Drupal\social_user\Plugin\Block\SocialUserLoginBlock::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 UserLoginBlock::build

See also

\Drupal\block\BlockViewBuilder

File

modules/social_features/social_user/src/Plugin/Block/SocialUserLoginBlock.php, line 21

Class

SocialUserLoginBlock
Provides a 'SocialUserLoginBlock' block.

Namespace

Drupal\social_user\Plugin\Block

Code

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,
    ],
  ];
}