You are here

public function UserListBuilder::buildRow in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/user/src/UserListBuilder.php \Drupal\user\UserListBuilder::buildRow()

Builds a row for an entity in the entity listing.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for this row of the list.

Return value

array A render array structure of fields for this entity.

Overrides EntityListBuilder::buildRow

See also

\Drupal\Core\Entity\EntityListBuilder::render()

File

core/modules/user/src/UserListBuilder.php, line 134
Contains \Drupal\user\UserListBuilder.

Class

UserListBuilder
Defines a class to build a listing of user entities.

Namespace

Drupal\user

Code

public function buildRow(EntityInterface $entity) {
  $row['username']['data'] = array(
    '#theme' => 'username',
    '#account' => $entity,
  );
  $row['status'] = $entity
    ->isActive() ? $this
    ->t('active') : $this
    ->t('blocked');
  $roles = user_role_names(TRUE);
  unset($roles[RoleInterface::AUTHENTICATED_ID]);
  $users_roles = array();
  foreach ($entity
    ->getRoles() as $role) {
    if (isset($roles[$role])) {
      $users_roles[] = $roles[$role];
    }
  }
  asort($users_roles);
  $row['roles']['data'] = array(
    '#theme' => 'item_list',
    '#items' => $users_roles,
  );
  $row['member_for'] = $this->dateFormatter
    ->formatTimeDiffSince($entity
    ->getCreatedTime());
  $row['access'] = $entity->access ? $this
    ->t('@time ago', array(
    '@time' => $this->dateFormatter
      ->formatTimeDiffSince($entity
      ->getLastAccessedTime()),
  )) : t('never');
  return $row + parent::buildRow($entity);
}