Loading media_entity_download.views.inc 0 → 100644 +22 −0 Original line number Diff line number Diff line <?php /** * @file * Contains Views integration for the media_entity_download module. */ /** * Implements hook_views_data(). */ function media_entity_download_views_data() { $data = []; $data['media']['media_download_link'] = [ 'title' => t('Link to download media file'), 'help' => t('Provide a link to download the media file.'), 'click sortable' => FALSE, 'field' => [ 'id' => 'media_download_link', ], ]; return $data; } src/Plugin/views/field/DownloadLink.php 0 → 100644 +34 −0 Original line number Diff line number Diff line <?php namespace Drupal\media_entity_download\Plugin\views\field; use Drupal\Core\Url; use Drupal\views\Plugin\views\field\EntityLink; use Drupal\views\ResultRow; /** * Field handler to present a link to download the media file. * * @ingroup views_field_handlers * * @ViewsField("media_download_link") */ class DownloadLink extends EntityLink { /** * {@inheritdoc} */ protected function getUrlInfo(ResultRow $row) { /** @var \Drupal\media\MediaInterface $media */ $media = $this->getEntity($row); return Url::fromRoute('media_entity_download.download', ['media' => $media->id()])->setAbsolute($this->options['absolute'] ?? FALSE); } /** * {@inheritdoc} */ protected function getDefaultLabel() { return $this->t('Download'); } } Loading
media_entity_download.views.inc 0 → 100644 +22 −0 Original line number Diff line number Diff line <?php /** * @file * Contains Views integration for the media_entity_download module. */ /** * Implements hook_views_data(). */ function media_entity_download_views_data() { $data = []; $data['media']['media_download_link'] = [ 'title' => t('Link to download media file'), 'help' => t('Provide a link to download the media file.'), 'click sortable' => FALSE, 'field' => [ 'id' => 'media_download_link', ], ]; return $data; }
src/Plugin/views/field/DownloadLink.php 0 → 100644 +34 −0 Original line number Diff line number Diff line <?php namespace Drupal\media_entity_download\Plugin\views\field; use Drupal\Core\Url; use Drupal\views\Plugin\views\field\EntityLink; use Drupal\views\ResultRow; /** * Field handler to present a link to download the media file. * * @ingroup views_field_handlers * * @ViewsField("media_download_link") */ class DownloadLink extends EntityLink { /** * {@inheritdoc} */ protected function getUrlInfo(ResultRow $row) { /** @var \Drupal\media\MediaInterface $media */ $media = $this->getEntity($row); return Url::fromRoute('media_entity_download.download', ['media' => $media->id()])->setAbsolute($this->options['absolute'] ?? FALSE); } /** * {@inheritdoc} */ protected function getDefaultLabel() { return $this->t('Download'); } }