You are here

public function BadgeListBuilder::buildRow in User Badges 8

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

src/BadgeListBuilder.php, line 79
Contains \Drupal\user_badges\BadgeListBuilder.

Class

BadgeListBuilder
Defines a class to build a listing of Badge entities.

Namespace

Drupal\user_badges

Code

public function buildRow(EntityInterface $entity) {

  /* @var $entity \Drupal\user_badges\Entity\Badge */
  $row['id'] = $entity
    ->id();
  $row['name'] = Link::fromTextAndUrl($entity
    ->label(), new Url('entity.badge.edit_form', array(
    'badge' => $entity
      ->id(),
  )));
  if ($entity->image->entity) {
    $image = array(
      '#theme' => 'image_style',
      '#style_name' => 'thumbnail',
      '#uri' => $entity->image->entity
        ->getFileUri(),
      '#title' => $entity
        ->label(),
    );
    $row['badge_image'] = $this->renderer
      ->render($image);
  }
  else {
    $row['badge_image'] = $this
      ->t('No Image');
  }
  $row['weight'] = $entity
    ->getBadgeWeight();
  $users_roles = $entity
    ->getBadgeRoleIds();
  $row['roles']['data'] = array(
    '#theme' => 'item_list',
    '#items' => $users_roles,
  );
  return $row + parent::buildRow($entity);
}