public function GISController::getList in Google Image Sitemap 8
Same name and namespace in other branches
- 2.0.x src/Controller/GISController.php \Drupal\google_image_sitemap\Controller\GISController::getList()
- 1.0.x src/Controller/GISController.php \Drupal\google_image_sitemap\Controller\GISController::getList()
Function to get available image sitemap.
1 string reference to 'GISController::getList'
File
- src/
Controller/ GISController.php, line 41
Class
- GISController
- Default controller for the google_image_sitemap module.
Namespace
Drupal\google_image_sitemap\ControllerCode
public function getList() {
$output = '';
$header = [
$this
->t('S.NO.'),
$this
->t('SITEMAP URL'),
$this
->t('CONTENT TYPE'),
$this
->t('LAST UPDATED'),
$this
->t('Edit'),
$this
->t('Sitemap'),
];
$query = $this->db
->select('google_image_sitemap', 'g')
->fields('g');
$result = $query
->execute();
$counter = 0;
$rows = [];
while ($gis_obj = $result
->fetchObject()) {
$is_exist = file_exists(\Drupal::service('file_system')
->realpath(file_default_scheme() . "://") . '/google_image_sitemap/sitemap_' . $gis_obj->node_type . '.xml');
$build_url = 'admin/config/search/google_image_sitemap/' . $gis_obj->sid . '/build';
$generate_text = $this
->t('Generate Sitemap');
if ($is_exist) {
$access_url = 'sites/default/files/google_image_sitemap/sitemap_' . $gis_obj->node_type . '.xml';
$url = Url::fromUri('internal:/' . $access_url);
$link_options = [
'attributes' => [
'title' => $this
->t('Open sitemap'),
],
];
$url
->setOptions($link_options);
$generate_text = $this
->t('Re Generate Sitemap');
}
$build_link = Link::fromTextAndUrl($generate_text, url::fromUri('internal:/' . $build_url));
$edit = 'admin/config/search/google_image_sitemap/' . $gis_obj->sid . '/edit';
// Rows of table.
$rows[] = [
++$counter,
$build_link,
$gis_obj->node_type,
empty($gis_obj->last_updated) ? '-' : date('d-M-Y ', $gis_obj->last_updated),
Link::fromTextAndUrl($this
->t('Edit'), Url::fromUri('internal:/' . $edit))
->toString(),
$is_exist ? Link::fromTextAndUrl($this
->t('Url'), $url)
->toString() : $this
->t('Url'),
];
}
$output = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#caption' => Link::fromTextAndUrl($this
->t('Add a new sitemap'), Url::fromUserInput(static::GOOGLE_IMAGE_SITEMAP_ADMIN_PATH . '/add')),
'#empty' => $this
->t('No sitemap available.'),
];
return $output;
}