public function ViewsUrlGenerator::getDataSets in Simple XML sitemap (Views integration) 8
File
- src/
Plugin/ simple_sitemap/ UrlGenerator/ ViewsUrlGenerator.php, line 141 - Contains Views URL generator.
Class
- ViewsUrlGenerator
- Views URL generator plugin.
Namespace
Drupal\simple_sitemap_views\Plugin\simple_sitemap\UrlGeneratorCode
public function getDataSets() {
// Load views with display plugins that use the route.
$query = $this->viewStorage
->getQuery();
$query
->condition('status', TRUE);
$query
->condition("display.*.display_plugin", $this->simpleSitemapViews
->getDisplayPathPluginIds(), 'IN');
$view_ids = $query
->execute();
// If there are no such views, then return an empty array.
if (empty($view_ids)) {
return [];
}
// Get data sets.
$data_sets = [];
/** @var \Drupal\views\ViewEntityInterface $view_entity */
foreach ($this->viewStorage
->loadMultiple($view_ids) as $view_entity) {
$displays = array_filter($view_entity
->get('display'), [
$this->simpleSitemapViews,
'isValidDisplay',
]);
foreach ($displays as $display_id => $display) {
$view = Views::executableFactory()
->get($view_entity);
// Ensure the display was correctly set.
if (!$view
->setDisplay($display_id)) {
$view
->destroy();
continue;
}
// Check that the display is enabled and indexed.
if ($view->display_handler
->isEnabled() && ($settings = $this->simpleSitemapViews
->getSitemapSettings($view))) {
// View path without arguments.
$base_data_set = [
'view' => $view,
'settings' => $settings,
];
$data_sets[] = $base_data_set + [
'arguments' => NULL,
];
// Process indexed arguments.
if ($args_ids = $this->simpleSitemapViews
->getIndexableArguments($view)) {
// Form the condition according to the variants of the
// indexable arguments.
$args_ids = $this->simpleSitemapViews
->getArgumentsStringVariations($args_ids);
$condition = new Condition('AND');
$condition
->condition('view_id', $view
->id());
$condition
->condition('display_id', $view->current_display);
$condition
->condition('arguments_ids', $args_ids, 'IN');
// Get the arguments values from the index.
$max_links = is_numeric($settings['max_links']) ? $settings['max_links'] : NULL;
$indexed_arguments = $this->simpleSitemapViews
->getArgumentsFromIndex($condition, $max_links, TRUE);
// Add the arguments values for processing.
foreach ($indexed_arguments as $index_id => $arguments_info) {
$data_sets[] = $base_data_set + [
'index_id' => $index_id,
'arguments' => $arguments_info['arguments'],
];
}
}
}
}
}
return $data_sets;
}