You are here

class Book in Sitemap 2.0.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/Sitemap/Book.php \Drupal\sitemap\Plugin\Sitemap\Book

Provides a sitemap for a book.

Plugin annotation


@Sitemap(
  id = "book",
  title = @Translation("Book name"),
  description = @Translation("Book type"),
  settings = {
    "title" = "",
    "show_expanded" = TRUE,
  },
  deriver = "Drupal\sitemap\Plugin\Derivative\BookSitemapDeriver",
  enabled = FALSE,
  book = "",
)

Hierarchy

Expanded class hierarchy of Book

File

src/Plugin/Sitemap/Book.php, line 24

Namespace

Drupal\sitemap\Plugin\Sitemap
View source
class Book extends SitemapBase {

  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    if (\Drupal::moduleHandler()
      ->moduleExists('book')) {
      $form = parent::settingsForm($form, $form_state);

      // Provide the book name as the default title.
      $bid = $this
        ->getPluginDefinition()['book'];
      $book = \Drupal::entityTypeManager()
        ->getStorage('node')
        ->load($bid);
      $form['title']['#default_value'] = $this->settings['title'] ?: $book
        ->label();
      $form['show_expanded'] = [
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Show expanded'),
        '#default_value' => $this->settings['show_expanded'],
        '#description' => $this
          ->t('Disable if you do not want to display the entire book outline on the sitemap.'),
      ];
    }
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function view() {

    /** @var \Drupal\book\BookManagerInterface $book_manager */
    $book_manager = \Drupal::service('book.manager');
    $book_id = $this->pluginDefinition['book'];
    $max_depth = $this->settings['show_expanded'] ? NULL : 1;
    $tree = $book_manager
      ->bookTreeAllData($book_id, NULL, $max_depth);
    $content = $book_manager
      ->bookTreeOutput($tree);
    return [
      '#theme' => 'sitemap_item',
      '#title' => $this->settings['title'],
      '#content' => $content,
      '#sitemap' => $this,
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Book::settingsForm public function Returns a form to configure settings for the mapping. Overrides SitemapBase::settingsForm
Book::view public function Builds a renderable array for a sitemap item. Overrides SitemapInterface::view
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 2
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::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::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
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
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.