You are here

abstract class SitemapBase in Sitemap 8.2

Same name and namespace in other branches
  1. 2.0.x src/SitemapBase.php \Drupal\sitemap\SitemapBase

Base class for Sitemap plugin implementations.

Hierarchy

Expanded class hierarchy of SitemapBase

4 files declare their use of SitemapBase
Book.php in src/Plugin/Sitemap/Book.php
Frontpage.php in src/Plugin/Sitemap/Frontpage.php
Menu.php in src/Plugin/Sitemap/Menu.php
Vocabulary.php in src/Plugin/Sitemap/Vocabulary.php

File

src/SitemapBase.php, line 15

Namespace

Drupal\sitemap
View source
abstract class SitemapBase extends PluginBase implements SitemapInterface {
  use StringTranslationTrait;

  /**
   * An associative array containing the configured settings of the sitemap_map.
   *
   * @var array
   */
  public $settings = [];

  /**
   * A Boolean indicating whether this mapping is enabled.
   *
   * @var bool
   */
  public $enabled = FALSE;

  /**
   * The weight of this mapping compared to others in the sitemap.
   *
   * @var int
   */
  public $weight = 0;

  /**
   * The name of the provider that owns this mapping.
   *
   * @var string
   */
  public $provider;

  /**
   * The global sitemap config.
   *
   * @var object
   */
  protected $sitemapConfig;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this
      ->setConfiguration($configuration);
    $this->settings = $this->configuration['settings'];
    $this->provider = $this->configuration['provider'];
    $this->sitemapConfig = \Drupal::config('sitemap.settings');
  }

  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    return [
      'module' => 'sitemap',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getLabel() {
    return $this->pluginDefinition['title'];
  }

  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    return $this->pluginDefinition['description'];
  }

  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state) {

    // Provide a section title field for every mapping plugin.
    $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;
  }

  /**
   * {@inheritdoc}
   */
  public function settingsSummary() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getConfiguration() {
    return $this->configuration;
  }

  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) {
    $this->configuration = NestedArray::mergeDeep($this
      ->baseConfigurationDefaults(), $this
      ->defaultConfiguration(), $configuration);
    $this->enabled = $this->configuration['enabled'];
    $this->weight = $this->configuration['weight'];
  }

  /**
   * Returns generic default configuration for sitemap plugins.
   *
   * @return array
   *   An associative array with the default configuration.
   */
  protected function baseConfigurationDefaults() {
    return [
      'id' => $this
        ->getPluginId(),
      'provider' => $this->pluginDefinition['provider'],
      'enabled' => $this->pluginDefinition['enabled'] ?? FALSE,
      'weight' => $this->pluginDefinition['weight'] ?? 0,
      'settings' => $this->pluginDefinition['settings'] ?? [],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
SitemapBase::$enabled public property A Boolean indicating whether this mapping is enabled.
SitemapBase::$provider public property The name of the provider that owns this mapping.
SitemapBase::$settings public property An associative array containing the configured settings of the sitemap_map.
SitemapBase::$sitemapConfig protected property The global sitemap config.
SitemapBase::$weight public property The weight of this mapping compared to others in the sitemap.
SitemapBase::baseConfigurationDefaults protected function Returns generic default configuration for sitemap plugins.
SitemapBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
SitemapBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration
SitemapBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
SitemapBase::getDescription public function Returns the administrative description for this mapping plugin. Overrides SitemapInterface::getDescription
SitemapBase::getLabel public function Returns the administrative label for this mapping plugin. Overrides SitemapInterface::getLabel
SitemapBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
SitemapBase::settingsForm public function Returns a form to configure settings for the mapping. Overrides SitemapInterface::settingsForm 4
SitemapBase::settingsSummary public function Returns a short summary for the current mapping settings. Overrides SitemapInterface::settingsSummary
SitemapBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
SitemapInterface::view public function Builds a renderable array for a sitemap item. 4
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.