View source
<?php
namespace Drupal\sitemap;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
abstract class SitemapBase extends PluginBase implements SitemapInterface {
use StringTranslationTrait;
public $settings = [];
public $enabled = FALSE;
public $weight = 0;
public $provider;
protected $sitemapConfig;
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->provider = $this->pluginDefinition['provider'];
if (empty($configuration)) {
$configuration = $this
->defaultConfiguration();
}
$this
->setConfiguration($configuration);
$this->sitemapConfig = \Drupal::config('sitemap.settings');
}
public function calculateDependencies() {
return [
'module' => 'sitemap',
];
}
public function getLabel() {
return $this->pluginDefinition['title'];
}
public function getDescription() {
return $this->pluginDefinition['description'];
}
public function settingsForm(array $form, FormStateInterface $form_state) {
$form['title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Title'),
'#default_value' => $this->settings['title'],
'#description' => $this
->t('If you do not wish to display a title, leave this field blank.'),
'#weight' => -10,
];
return $form;
}
public function settingsSummary() {
return [];
}
public function getConfiguration() {
return [
'id' => $this
->getPluginId(),
'provider' => $this->pluginDefinition['provider'],
'status' => $this->enabled,
'weight' => $this->weight,
'settings' => $this->settings,
];
}
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;
}
public function defaultConfiguration() {
return [
'provider' => $this->pluginDefinition['provider'],
'enabled' => $this->pluginDefinition['enabled'],
'weight' => isset($this->pluginDefinition['weight']) ? $this->pluginDefinition['weight'] : '',
'settings' => isset($this->pluginDefinition['settings']) ? $this->pluginDefinition['settings'] : [],
];
}
}