Commit ab18db04 authored by Sam152's avatar Sam152 Committed by gbyte.co

Issue #2685383 by Sam152: Inject the simple sitemap service into SimplesitemapController

parent c8085d85
......@@ -7,12 +7,21 @@
namespace Drupal\simple_sitemap\Controller;
use Drupal\Core\Cache\CacheableResponse;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
/**
* SimplesitemapController.
*/
class SimplesitemapController {
class SimplesitemapController extends ControllerBase {
/**
* The sitemap generator.
*
* @var \Drupal\simple_sitemap\Simplesitemap
*/
protected $sitemapGenerator;
/**
* Returns the whole sitemap, a requested sitemap chunk, or the sitemap index file.
......@@ -25,8 +34,7 @@ class SimplesitemapController {
* Returns an XML response.
*/
public function getSitemap($sitemap_id = NULL) {
$sitemap = \Drupal::service('simple_sitemap.generator');
$output = $sitemap->getSitemap($sitemap_id);
$output = $this->sitemapGenerator->getSitemap($sitemap_id);
$output = !$output ? '' : $output;
// Display sitemap with correct xml header.
......@@ -35,4 +43,22 @@ class SimplesitemapController {
$meta_data->addCacheTags(['simple_sitemap']);
return $response;
}
/**
* SimplesitemapController constructor.
*
* @param \Drupal\simple_sitemap\Simplesitemap $sitemap_generator
* The sitemap generator.
*/
public function __construct($sitemap_generator) {
$this->sitemapGenerator = $sitemap_generator;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('simple_sitemap.generator'));
}
}
<?php
/**
* @file
* Contains \Drupal\simple_sitemap\LinkGeneratorBase.
......@@ -47,5 +46,4 @@ abstract class LinkGeneratorBase extends PluginBase implements LinkGeneratorInte
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container->get('database'));
}
}
......@@ -11,7 +11,6 @@ use Drupal\Component\Plugin\PluginInspectionInterface;
/**
* Defines an interface for simple_sitemap plugins.
*/
interface LinkGeneratorInterface extends PluginInspectionInterface {
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment