dateFormatter = $date_formatter; $this->languageManager = $language_manager; $this->thumbnailStyleExists = !empty($image_style_storage->load('thumbnail')); } /** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { return new static( $entity_type, $container->get('entity.manager')->getStorage($entity_type->id()), $container->get('date.formatter'), $container->get('language_manager'), $container->get('entity_type.manager')->getStorage('image_style') ); } /** * {@inheritdoc} */ public function buildHeader() { $header = []; if ($this->thumbnailStyleExists) { $header['thumbnail'] = [ 'data' => $this->t('Thumbnail'), 'class' => [RESPONSIVE_PRIORITY_LOW], ]; } $header += [ 'name' => $this->t('Media Name'), 'type' => [ 'data' => $this->t('Type'), 'class' => [RESPONSIVE_PRIORITY_MEDIUM], ], 'author' => [ 'data' => $this->t('Author'), 'class' => [RESPONSIVE_PRIORITY_LOW], ], 'status' => $this->t('Status'), 'changed' => [ 'data' => $this->t('Updated'), 'class' => [RESPONSIVE_PRIORITY_LOW], ], ]; // Enable language column if multiple languages are added. if ($this->languageManager->isMultilingual()) { $header['language'] = [ 'data' => $this->t('Language'), 'class' => [RESPONSIVE_PRIORITY_LOW], ]; } return $header + parent::buildHeader(); } /** * {@inheritdoc} */ 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); } /** * {@inheritdoc} */ protected function getEntityIds() { $query = $this->getStorage()->getQuery() ->sort('changed', 'DESC'); // Only add the pager if a limit is specified. if ($this->limit) { $query->pager($this->limit); } return $query->execute(); } }