You are here

public function MiconListBuilder::buildRow in Micon 2.x

Same name and namespace in other branches
  1. 8 src/MiconListBuilder.php \Drupal\micon\MiconListBuilder::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

src/MiconListBuilder.php, line 31

Class

MiconListBuilder
Provides a listing of Micon entities.

Namespace

Drupal\micon

Code

public function buildRow(EntityInterface $entity) {

  /* @var $entity \Drupal\micon\Entity\Micon */
  $preview = [];
  if ($icons = $entity
    ->getIcons()) {
    $count = count($icons) >= 12 ? 12 : count($icons);
    foreach (array_rand($icons, $count) as $key) {
      $preview[] = $icons[$key]
        ->toRenderable();
    }
  }
  $row['label'] = Link::fromTextAndUrl($this
    ->t('<strong>@label</strong> <small>(.@machine)</small>', [
    '@label' => $entity
      ->label(),
    '@machine' => $entity
      ->id(),
  ]), new Url('entity.micon.canonical', [
    'micon' => $entity
      ->id(),
  ]));
  $row['preview']['data'] = $preview;
  $row['type']['data']['#markup'] = '<small>' . $this
    ->micon(strtoupper($entity
    ->type())) . '</small>';
  $row['status'] = $entity
    ->status() ? $this
    ->micon('Published')
    ->setIconOnly() : $this
    ->micon('Unpublished')
    ->setIconOnly();
  return $row + parent::buildRow($entity);
}