e9bc7db3108561b959dfcd37da1b8f3263f172eb
[yaffs-website] / web / modules / contrib / simple_sitemap / src / Plugin / simple_sitemap / UrlGeneratorPluginBase.php
1 <?php
2
3 namespace Drupal\simple_sitemap\Plugin\simple_sitemap;
4
5 use Drupal\Component\Plugin\ConfigurablePluginInterface;
6 use Symfony\Component\DependencyInjection\ContainerInterface;
7
8 /**
9  * Class UrlGeneratorPluginBase
10  * @package Drupal\simple_sitemap\Plugin\simple_sitemap
11  */
12 abstract class UrlGeneratorPluginBase extends SimplesitemapPluginBase  implements ConfigurablePluginInterface {
13
14   /**
15    * @var array
16    */
17   public $settings = [];
18
19   /**
20    * @var bool
21    */
22   public $enabled = TRUE;
23
24   /**
25    * @var int
26    */
27   public $weight = 0;
28
29   /**
30    * @var string
31    */
32   public $provider;
33
34   /**
35    * UrlGeneratorPluginBase constructor.
36    * @param array $configuration
37    * @param string $plugin_id
38    * @param mixed $plugin_definition
39    */
40   public function __construct(array $configuration, $plugin_id, $plugin_definition) {
41     parent::__construct($configuration, $plugin_id, $plugin_definition);
42   }
43
44   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
45     return new static($configuration, $plugin_id, $plugin_definition);
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public function calculateDependencies() {
52     return ['module' => 'simple_sitemap'];
53   }
54
55   /**
56    * {@inheritdoc}
57    */
58   public function getConfiguration() {
59     return [
60       'id' => $this->getPluginId(),
61       'provider' => $this->pluginDefinition['provider'],
62       'status' => $this->enabled,
63       'weight' => $this->weight,
64       'settings' => $this->settings,
65     ];
66   }
67
68   /**
69    * {@inheritdoc}
70    */
71   public function setConfiguration(array $configuration) {
72     if (isset($configuration['enabled'])) {
73       $this->enabled = (bool) $configuration['enabled'];
74     }
75     if (isset($configuration['weight'])) {
76       $this->weight = (int) $configuration['weight'];
77     }
78     if (isset($configuration['settings'])) {
79       $this->settings = (array) $configuration['settings'];
80     }
81     return $this;
82   }
83
84   /**
85    * {@inheritdoc}
86    */
87   public function defaultConfiguration() {
88     return [
89       'enabled' => $this->pluginDefinition['enabled'],
90       'weight' => isset($this->pluginDefinition['weight']) ? $this->pluginDefinition['weight'] : 0,
91       'settings' => isset($this->pluginDefinition['settings']) ? $this->pluginDefinition['settings'] : [],
92     ];
93   }
94 }