Commit aa852b87 authored by gbyte.co's avatar gbyte.co

Improve plugin structure

parent c27a3f89
......@@ -46,7 +46,7 @@ class UrlGenerator extends Plugin {
*
* @var int
*/
public $weight;
public $weight = 0;
/**
* Whether this plugin is enabled or disabled by default.
......
......@@ -2,7 +2,7 @@
namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;
use Drupal\simple_sitemap\Plugin\simple_sitemap\SimplesitemapPluginBase;
use Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGeneratorPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\ContentEntityBase;
......@@ -19,7 +19,7 @@ use Drupal\Core\Language\Language;
* Class UrlGeneratorBase
* @package Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator
*/
abstract class UrlGeneratorBase extends SimplesitemapPluginBase implements UrlGeneratorInterface {
abstract class UrlGeneratorBase extends UrlGeneratorPluginBase implements UrlGeneratorInterface {
const ANONYMOUS_USER_ID = 0;
const PROCESSING_PATH_MESSAGE = 'Processing path #@current out of @max: @path';
......@@ -115,11 +115,7 @@ abstract class UrlGeneratorBase extends SimplesitemapPluginBase implements UrlGe
->load(self::ANONYMOUS_USER_ID);
}
public static function create(
ContainerInterface $container,
array $configuration,
$plugin_id,
$plugin_definition) {
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
......@@ -354,7 +350,7 @@ abstract class UrlGeneratorBase extends SimplesitemapPluginBase implements UrlGe
}
}
}
protected function setProgressInfo() {
if ($this->context['sandbox']['progress'] != $this->context['sandbox']['max']) {
......
<?php
namespace Drupal\simple_sitemap\Plugin\simple_sitemap;
use Drupal\Component\Plugin\ConfigurablePluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class UrlGeneratorPluginBase
* @package Drupal\simple_sitemap\Plugin\simple_sitemap
*/
abstract class UrlGeneratorPluginBase extends SimplesitemapPluginBase implements ConfigurablePluginInterface {
/**
* @var array
*/
public $settings = [];
/**
* @var bool
*/
public $enabled = TRUE;
/**
* @var int
*/
public $weight = 0;
/**
* @var string
*/
public $provider;
/**
* UrlGeneratorPluginBase constructor.
* @param array $configuration
* @param string $plugin_id
* @param mixed $plugin_definition
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
return ['module' => 'simple_sitemap'];
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return [
'id' => $this->getPluginId(),
'provider' => $this->pluginDefinition['provider'],
'status' => $this->enabled,
'weight' => $this->weight,
'settings' => $this->settings,
];
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
if (isset($configuration['enabled'])) {
$this->enabled = (bool) $configuration['enabled'];
}
if (isset($configuration['weight'])) {
$this->weight = (int) $configuration['weight'];
}
if (isset($configuration['settings'])) {
$this->settings = (array) $configuration['settings'];
}
return $this;
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'enabled' => $this->pluginDefinition['enabled'],
'weight' => isset($this->pluginDefinition['weight']) ? $this->pluginDefinition['weight'] : 0,
'settings' => isset($this->pluginDefinition['settings']) ? $this->pluginDefinition['settings'] : [],
];
}
}
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