Book.php in Sitemap 2.0.x
File
src/Plugin/Sitemap/Book.php
View source
<?php
namespace Drupal\sitemap\Plugin\Sitemap;
use Drupal\Core\Form\FormStateInterface;
use Drupal\sitemap\SitemapBase;
class Book extends SitemapBase {
public function settingsForm(array $form, FormStateInterface $form_state) {
if (\Drupal::moduleHandler()
->moduleExists('book')) {
$form = parent::settingsForm($form, $form_state);
$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;
}
public function view() {
$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,
];
}
}
Classes
Name |
Description |
Book |
Provides a sitemap for a book. |