You are here

public function Book::settingsForm 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::settingsForm()

Returns a form to configure settings for the mapping.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form elements for the sitemap_map's settings.

Overrides SitemapBase::settingsForm

File

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

Class

Book
Provides a sitemap for a book.

Namespace

Drupal\sitemap\Plugin\Sitemap

Code

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;
}