You are here

public function MediaSitemapController::listMediaSitemap in Media Sitemap 8

List.

Return value

string Return Hello string.

1 string reference to 'MediaSitemapController::listMediaSitemap'
media_sitemap.routing.yml in ./media_sitemap.routing.yml
media_sitemap.routing.yml

File

src/Controller/MediaSitemapController.php, line 61
Contains \Drupal\media_sitemap\Controller\MediaSitemapController.

Class

MediaSitemapController
Class MediaSitemapController.

Namespace

Drupal\media_sitemap\Controller

Code

public function listMediaSitemap() {
  $output = '';
  $header = array(
    t('SITEMAP URL'),
    t('CREATED DATE'),
    t('TOTAL LINKS'),
    t('ACTIONS'),
  );
  $rows = array();
  $url = 'public://media_sitemap/image_sitemap.xml';
  $url = file_create_url($url);

  // Rows of table.
  $image_sitemap_created = $this
    ->config('media_sitemap.settings')
    ->get('image_sitemap_created');
  $image_sitemap_number_of_urls = $this
    ->config('media_sitemap.settings')
    ->get('image_sitemap_number_of_urls');
  if (isset($image_sitemap_created) && isset($image_sitemap_number_of_urls)) {
    $rows[] = array(
      $build_link = Link::fromTextAndUrl($url, Url::fromUri($url)),
      date('d-M-Y ', $image_sitemap_created),
      $image_sitemap_number_of_urls,
      Link::fromTextAndUrl(t('Re-generate'), Url::fromRoute('media_sitemap.media_sitemap_batch_controller_generate'))
        ->toString(),
    );
  }
  $output = [
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => Link::fromTextAndUrl(t('Add a new media sitemap'), Url::fromRoute('media_sitemap.media_sitemap_batch_controller_generate')),
  ];
  return $output;
}