ArbitraryUrlGenerator.php 2.07 KB
Newer Older
1 2
<?php

3
namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;
4

5 6 7
use Drupal\simple_sitemap\Logger;
use Drupal\simple_sitemap\Simplesitemap;
use Drupal\Core\Extension\ModuleHandler;
8
use Symfony\Component\DependencyInjection\ContainerInterface;
9

10 11
/**
 * Class ArbitraryUrlGenerator
12 13 14
 * @package Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator
 *
 * @UrlGenerator(
Pawel G's avatar
Pawel G committed
15
 *   id = "arbitrary",
16
 *   label = @Translation("Arbitrary URL generator"),
17
 *   description = @Translation("Generates URLs from data sets collected in the hook_arbitrary_links_alter hook."),
18
 * )
19
 */
20
class ArbitraryUrlGenerator extends UrlGeneratorBase {
21

22 23 24 25
  protected $moduleHandler;

  /**
   * ArbitraryUrlGenerator constructor.
26
   * @param array $configuration
27 28
   * @param $plugin_id
   * @param $plugin_definition
29 30 31 32 33
   * @param \Drupal\simple_sitemap\Simplesitemap $generator
   * @param \Drupal\simple_sitemap\Logger $logger
   * @param \Drupal\Core\Extension\ModuleHandler $module_handler
   */
  public function __construct(
34 35 36
    array $configuration,
    $plugin_id,
    $plugin_definition,
37 38 39 40 41
    Simplesitemap $generator,
    Logger $logger,
    ModuleHandler $module_handler
  ) {
    parent::__construct(
42 43 44
      $configuration,
      $plugin_id,
      $plugin_definition,
45
      $generator,
Pawel G's avatar
Pawel G committed
46
      $logger
47 48 49 50
    );
    $this->moduleHandler = $module_handler;
  }

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
  public static function create(
    ContainerInterface $container,
    array $configuration,
    $plugin_id,
    $plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('simple_sitemap.generator'),
      $container->get('simple_sitemap.logger'),
      $container->get('module_handler')
    );
  }

66
  /**
Pawel G's avatar
Pawel G committed
67
   * @inheritdoc
68
   */
69
  public function getDataSets() {
70
    $arbitrary_links = [];
71 72
    $sitemap_variant = $this->sitemapVariant;
    $this->moduleHandler->alter('simple_sitemap_arbitrary_links', $arbitrary_links, $sitemap_variant);
73
    return array_values($arbitrary_links);
74 75
  }

76
  /**
Pawel G's avatar
Pawel G committed
77
   * @inheritdoc
78
   */
Pawel G's avatar
Pawel G committed
79 80
  protected function processDataSet($data_set) {
    return $data_set;
81 82
  }
}