function MediaListBuilder::buildRow

Same name in other branches
  1. 9 core/modules/media/src/MediaListBuilder.php \Drupal\media\MediaListBuilder::buildRow()
  2. 8.9.x core/modules/media/src/MediaListBuilder.php \Drupal\media\MediaListBuilder::buildRow()
  3. 11.x core/modules/media/src/MediaListBuilder.php \Drupal\media\MediaListBuilder::buildRow()

Overrides EntityListBuilder::buildRow

File

core/modules/media/src/MediaListBuilder.php, line 115

Class

MediaListBuilder
Provides a listing of media items.

Namespace

Drupal\media

Code

public function buildRow(EntityInterface $entity) {
    
    /** @var \Drupal\media\MediaInterface $entity */
    if ($this->thumbnailStyleExists) {
        $row['thumbnail'] = [];
        if ($thumbnail_uri = $entity->getSource()
            ->getMetadata($entity, 'thumbnail_uri')) {
            $row['thumbnail']['data'] = [
                '#theme' => 'image_style',
                '#style_name' => 'thumbnail',
                '#uri' => $thumbnail_uri,
                '#height' => 50,
            ];
        }
    }
    $row['name']['data'] = [
        '#type' => 'link',
        '#title' => $entity->label(),
        '#url' => $entity->toUrl(),
    ];
    $row['type'] = $entity->bundle->entity
        ->label();
    $row['author']['data'] = [
        '#theme' => 'username',
        '#account' => $entity->getOwner(),
    ];
    $row['status'] = $entity->isPublished() ? $this->t('Published') : $this->t('Unpublished');
    $row['changed'] = $this->dateFormatter
        ->format($entity->getChangedTime(), 'short');
    if ($this->languageManager
        ->isMultilingual()) {
        $row['language'] = $this->languageManager
            ->getLanguageName($entity->language()
            ->getId());
    }
    return $row + parent::buildRow($entity);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.