You are here

public function Vocabulary::settingsForm in Sitemap 8.2

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Sitemap/Vocabulary.php \Drupal\sitemap\Plugin\Sitemap\Vocabulary::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/Vocabulary.php, line 73

Class

Vocabulary
Provides a sitemap for an taxonomy vocabulary.

Namespace

Drupal\sitemap\Plugin\Sitemap

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $form = parent::settingsForm($form, $form_state);

  // Provide the menu name as the default title.
  $vid = $this
    ->getPluginDefinition()['vocabulary'];
  $vocab = \Drupal::entityTypeManager()
    ->getStorage('taxonomy_vocabulary')
    ->load($vid);
  $form['title']['#default_value'] = $this->settings['title'] ?: $vocab
    ->label();
  $form['show_description'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display vocabulary description'),
    '#default_value' => $this->settings['show_description'],
    '#description' => $this
      ->t('When enabled, this option will show the vocabulary description.'),
  ];
  $form['show_count'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display node counts next to taxonomy terms'),
    '#default_value' => $this->settings['show_count'],
    '#description' => $this
      ->t('When enabled, this option will show the number of nodes in each taxonomy term.'),
  ];
  $form['term_depth'] = [
    // @TODO: Number type not submitting?

    //'#type' = 'number',
    '#type' => 'textfield',
    '#title' => $this
      ->t('Term depth'),
    '#default_value' => $this->settings['term_depth'],
    //'#min' => self::DEPTH_DISABLED,

    //'#max' => self::DEPTH_MAX,
    '#size' => 3,
    '#description' => $this
      ->t('Specify how many levels of taxonomy terms should be included. For instance, enter <code>1</code> to only include top-level terms, or <code>@disabled</code> to include no terms. The maximum depth is <code>@max</code>.', [
      '@disabled' => self::DEPTH_DISABLED,
      '@max' => self::DEPTH_MAX,
    ]),
  ];
  $form['term_count_threshold'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Term count threshold'),
    '#default_value' => $this->settings['term_count_threshold'],
    '#size' => 3,
    '#description' => $this
      ->t('Only show taxonomy terms whose node counts are greater than this threshold. Set to <em>@disabled</em> to disable this threshold. Note that in hierarchical taxonomies, parent items with children will still be shown.', [
      '@disabled' => self::THRESHOLD_DISABLED,
    ]),
  ];
  $form['customize_link'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Customize term links'),
    '#default_value' => $this->settings['customize_link'],
  ];
  $customizeLinkName = 'plugins[vocabulary:' . $vid . '][settings][customize_link]';
  $form['term_link'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Term link route and argument'),
    '#default_value' => $this->settings['term_link'],
    "#description" => $this
      ->t('Provide the route name and route argument name for the link, in the from of <code>route.name|argument.name</code>. The default value of this field is <code>entity.taxonomy_term.canonical|taxonomy_term</code>.'),
    '#states' => [
      'visible' => [
        ':input[name="' . $customizeLinkName . '"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['always_link'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Always link to the taxonomy term.'),
    '#default_value' => $this->settings['always_link'],
    '#description' => $this
      ->t('There are a few cases where a taxonomy term maybe be displayed in the list, but will not have a link created (for example, terms without any tagged content [nodes], or parent terms displayed when the threshold is greater than zero). Check this box to ensure that a link to the taxonomy term is always provided.'),
    '#states' => [
      'visible' => [
        ':input[name="' . $customizeLinkName . '"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['enable_rss'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable RSS feed links'),
    '#default_value' => $this->settings['enable_rss'],
  ];
  $enableRssName = 'plugins[vocabulary:' . $vid . '][settings][enable_rss]';
  $form['rss_link'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('RSS route and argument'),
    '#default_value' => $this->settings['rss_link'],
    "#description" => $this
      ->t('Provide the route name and route argument name for the link, in the from of <code>route.name|argument.name</code>. The default value of this field is <code>view.taxonomy_term.feed_1|arg_0</code>.'),
    '#states' => [
      'visible' => [
        ':input[name="' . $enableRssName . '"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['rss_depth'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('RSS depth'),
    '#default_value' => $this->settings['rss_depth'],
    '#size' => 3,
    '#maxlength' => 10,
    '#description' => $this
      ->t('Specify how many levels of taxonomy terms should have a link to the default RSS feed included. For instance, enter <code>1</code> to include an RSS feed for the top-level terms, or <code>@disabled</code> to not include a feed. The maximum depth is <code>@max</code>.', [
      '@disabled' => self::DEPTH_DISABLED,
      '@max' => self::DEPTH_MAX,
    ]),
    '#states' => [
      'visible' => [
        ':input[name="' . $enableRssName . '"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  return $form;
}