Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / simple_sitemap / src / Plugin / simple_sitemap / UrlGenerator / ArbitraryUrlGenerator.php
1 <?php
2
3 namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;
4
5 use Drupal\simple_sitemap\EntityHelper;
6 use Drupal\simple_sitemap\Logger;
7 use Drupal\simple_sitemap\Simplesitemap;
8 use Drupal\simple_sitemap\SitemapGenerator;
9 use Drupal\Core\Language\LanguageManagerInterface;
10 use Drupal\Core\Entity\EntityTypeManagerInterface;
11 use Drupal\Core\Extension\ModuleHandler;
12 use Symfony\Component\DependencyInjection\ContainerInterface;
13
14 /**
15  * Class ArbitraryUrlGenerator
16  * @package Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator
17  *
18  * @UrlGenerator(
19  *   id = "arbitrary",
20  *   title = @Translation("Arbitrary URL generator"),
21  *   description = @Translation("Generates URLs from data sets collected in the hook_arbitrary_links_alter hook."),
22  *   weight = 20,
23  * )
24  */
25 class ArbitraryUrlGenerator extends UrlGeneratorBase {
26
27   protected $moduleHandler;
28
29   /**
30    * ArbitraryUrlGenerator constructor.
31    * @param array $configuration
32    * @param string $plugin_id
33    * @param mixed $plugin_definition
34    * @param \Drupal\simple_sitemap\Simplesitemap $generator
35    * @param \Drupal\simple_sitemap\SitemapGenerator $sitemap_generator
36    * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
37    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
38    * @param \Drupal\simple_sitemap\Logger $logger
39    * @param \Drupal\simple_sitemap\EntityHelper $entityHelper
40    * @param \Drupal\Core\Extension\ModuleHandler $module_handler
41    */
42   public function __construct(
43     array $configuration,
44     $plugin_id,
45     $plugin_definition,
46     Simplesitemap $generator,
47     SitemapGenerator $sitemap_generator,
48     LanguageManagerInterface $language_manager,
49     EntityTypeManagerInterface $entity_type_manager,
50     Logger $logger,
51     EntityHelper $entityHelper,
52     ModuleHandler $module_handler
53   ) {
54     parent::__construct(
55       $configuration,
56       $plugin_id,
57       $plugin_definition,
58       $generator,
59       $sitemap_generator,
60       $language_manager,
61       $entity_type_manager,
62       $logger,
63       $entityHelper
64     );
65     $this->moduleHandler = $module_handler;
66   }
67
68   public static function create(
69     ContainerInterface $container,
70     array $configuration,
71     $plugin_id,
72     $plugin_definition) {
73     return new static(
74       $configuration,
75       $plugin_id,
76       $plugin_definition,
77       $container->get('simple_sitemap.generator'),
78       $container->get('simple_sitemap.sitemap_generator'),
79       $container->get('language_manager'),
80       $container->get('entity_type.manager'),
81       $container->get('simple_sitemap.logger'),
82       $container->get('simple_sitemap.entity_helper'),
83       $container->get('module_handler')
84     );
85   }
86
87
88   /**
89    * @inheritdoc
90    */
91   public function getDataSets() {
92     $arbitrary_links = [];
93     $this->moduleHandler->alter('simple_sitemap_arbitrary_links', $arbitrary_links);
94     return array_values($arbitrary_links);
95   }
96
97   /**
98    * @inheritdoc
99    */
100   protected function processDataSet($data_set) {
101     return $data_set;
102   }
103 }