You are here

protected function VisitorsBlock::_showLastRegisteredUser in Visitors 8.2

Display last registered user to visitors block.

1 call to VisitorsBlock::_showLastRegisteredUser()
VisitorsBlock::build in src/Plugin/Block/VisitorsBlock.php
Builds and returns the renderable array for this block plugin.

File

src/Plugin/Block/VisitorsBlock.php, line 101
Contains \Drupal\visitors\Plugin\Block\VisitorsBlock.

Class

VisitorsBlock
Provides a 'Visitors' block.

Namespace

Drupal\visitors\Plugin\Block

Code

protected function _showLastRegisteredUser() {
  if ($this->config
    ->get('show_last_registered_user')) {
    $last_user_uid = \Drupal::database()
      ->select('users', 'u')
      ->fields('u', array(
      'uid',
    ))
      ->orderBy('uid', 'DESC')
      ->range(0, 1)
      ->execute()
      ->fetchField();
    $user = \Drupal::entityTypeManager()
      ->getStorage('user')
      ->load($last_user_uid);
    $username = array(
      '#theme' => 'username',
      '#account' => $user,
    );
    $this->items[] = t('Last Registered User: @last_user', array(
      '@last_user' => \Drupal::service('renderer')
        ->render($username),
    ));
  }
}