You are here

public function Markdown::settingsForm in Markdown 8

Same name and namespace in other branches
  1. 3.0.x src/Plugin/Filter/Markdown.php \Drupal\markdown\Plugin\Filter\Markdown::settingsForm()

Generates a filter's settings form.

Parameters

array $form: A minimally prepopulated form array.

\Drupal\Core\Form\FormStateInterface $form_state: The state of the (entire) configuration form.

Return value

array The $form array with additional form elements for the settings of this filter. The submitted form values should match $this->settings.

Overrides FilterBase::settingsForm

File

src/Plugin/Filter/Markdown.php, line 31

Class

Markdown
Provides a filter for markdown.

Namespace

Drupal\markdown\Plugin\Filter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $libraries_options = [];
  if (class_exists('Michelf\\MarkdownExtra')) {
    $libraries_options['php-markdown'] = 'PHP Markdown';
  }
  elseif (\Drupal::moduleHandler()
    ->moduleExists('libraries')) {
    $library = libraries_detect('php-markdown');
    if (!empty($library['installed'])) {
      $libraries_options['php-markdown'] = 'PHP Markdown';
    }
  }
  if (class_exists('League\\CommonMark\\CommonMarkConverter')) {
    $libraries_options['commonmark'] = 'Commonmark';
  }
  if (!empty($libraries_options)) {
    $form['markdown_library'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Markdown library'),
      '#options' => $libraries_options,
      '#default_value' => $this->settings['markdown_library'],
    ];
  }
  else {
    $form['markdown_library'] = [
      '#type' => 'item',
      '#title' => $this
        ->t('No Markdown library found'),
      '#description' => $this
        ->t('You need to use composer to install the <a href=":markdown_link">PHP Markdown Lib</a> and/or the <a href=":commonmark_link">CommonMark Lib</a>. Optionally you can use the Library module and place the PHP Markdown Lib in the root library directory, see more in README.', [
        ':markdown_link' => 'https://packagist.org/packages/michelf/php-markdown',
        ':commonmark_link' => 'https://packagist.org/packages/league/commonmark',
      ]),
    ];
  }
  if (isset($library['name'])) {
    $form['markdown_status'] = [
      '#title' => $this
        ->t('Version'),
      '#theme' => 'item_list',
      '#items' => [
        $library['name'] . ' ' . $library['version'],
      ],
    ];
  }
  return $form;
}