Chris@14: dateFormatter = $date_formatter; Chris@14: $this->languageManager = $language_manager; Chris@14: $this->thumbnailStyleExists = !empty($image_style_storage->load('thumbnail')); Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { Chris@18: $entity_type_manager = $container->get('entity_type.manager'); Chris@14: return new static( Chris@14: $entity_type, Chris@18: $entity_type_manager->getStorage($entity_type->id()), Chris@14: $container->get('date.formatter'), Chris@14: $container->get('language_manager'), Chris@18: $entity_type_manager->getStorage('image_style') Chris@14: ); Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public function buildHeader() { Chris@14: $header = []; Chris@14: if ($this->thumbnailStyleExists) { Chris@14: $header['thumbnail'] = [ Chris@14: 'data' => $this->t('Thumbnail'), Chris@14: 'class' => [RESPONSIVE_PRIORITY_LOW], Chris@14: ]; Chris@14: } Chris@14: $header += [ Chris@14: 'name' => $this->t('Media Name'), Chris@14: 'type' => [ Chris@14: 'data' => $this->t('Type'), Chris@14: 'class' => [RESPONSIVE_PRIORITY_MEDIUM], Chris@14: ], Chris@14: 'author' => [ Chris@14: 'data' => $this->t('Author'), Chris@14: 'class' => [RESPONSIVE_PRIORITY_LOW], Chris@14: ], Chris@14: 'status' => $this->t('Status'), Chris@14: 'changed' => [ Chris@14: 'data' => $this->t('Updated'), Chris@14: 'class' => [RESPONSIVE_PRIORITY_LOW], Chris@14: ], Chris@14: ]; Chris@14: // Enable language column if multiple languages are added. Chris@14: if ($this->languageManager->isMultilingual()) { Chris@14: $header['language'] = [ Chris@14: 'data' => $this->t('Language'), Chris@14: 'class' => [RESPONSIVE_PRIORITY_LOW], Chris@14: ]; Chris@14: } Chris@14: return $header + parent::buildHeader(); Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public function buildRow(EntityInterface $entity) { Chris@14: /** @var \Drupal\media\MediaInterface $entity */ Chris@14: if ($this->thumbnailStyleExists) { Chris@14: $row['thumbnail'] = []; Chris@17: if ($thumbnail_uri = $entity->getSource()->getMetadata($entity, 'thumbnail_uri')) { Chris@14: $row['thumbnail']['data'] = [ Chris@14: '#theme' => 'image_style', Chris@14: '#style_name' => 'thumbnail', Chris@17: '#uri' => $thumbnail_uri, Chris@14: '#height' => 50, Chris@14: ]; Chris@14: } Chris@14: } Chris@14: $row['name']['data'] = [ Chris@14: '#type' => 'link', Chris@14: '#title' => $entity->label(), Chris@14: '#url' => $entity->toUrl(), Chris@14: ]; Chris@14: $row['type'] = $entity->bundle->entity->label(); Chris@14: $row['author']['data'] = [ Chris@14: '#theme' => 'username', Chris@14: '#account' => $entity->getOwner(), Chris@14: ]; Chris@14: $row['status'] = $entity->isPublished() ? $this->t('Published') : $this->t('Unpublished'); Chris@14: $row['changed'] = $this->dateFormatter->format($entity->getChangedTime(), 'short'); Chris@14: Chris@14: if ($this->languageManager->isMultilingual()) { Chris@14: $row['language'] = $this->languageManager->getLanguageName($entity->language()->getId()); Chris@14: } Chris@14: return $row + parent::buildRow($entity); Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: protected function getEntityIds() { Chris@14: $query = $this->getStorage()->getQuery() Chris@14: ->sort('changed', 'DESC'); Chris@14: Chris@14: // Only add the pager if a limit is specified. Chris@14: if ($this->limit) { Chris@14: $query->pager($this->limit); Chris@14: } Chris@14: return $query->execute(); Chris@14: } Chris@14: Chris@14: }