You are here

public function TypogrifyFilter::settingsForm in Typogrify 8

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/TypogrifyFilter.php, line 105

Class

TypogrifyFilter
Provides a filter to restrict images to site.

Namespace

Drupal\typogrify\Plugin\Filter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $settings = $this->settings;
  static::settingsUnserialize($settings);
  $form['help'] = [
    '#type' => 'markup',
    '#value' => '<p>' . $this
      ->t('Enable the following typographic refinements:') . '</p>',
  ];

  // Smartypants settings.
  $form['smartypants_enabled'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Use typographers quotation marks and dashes (<a href="@smarty-pants-url">SmartyPants</a>)', [
      '@smarty-pants-url' => 'http://daringfireball.net/projects/smartypants',
    ]),
    '#default_value' => $settings['smartypants_enabled'],
  ];

  // Smartypants hyphenation settings.
  // Uses the same values as the parse attributes in the
  // SmartyPants::process() function.
  $form['smartypants_hyphens'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Dash replacement settings for SmartyPants'),
    '#default_value' => $settings['smartypants_hyphens'],
    '#options' => [
      1 => $this
        ->t('“--” for em-dashes; no en-dash support'),
      3 => $this
        ->t('“--” for em-dashes; “---” for en-dashes'),
      2 => $this
        ->t('“---” for em-dashes; “--” for en-dashes'),
    ],
  ];

  // Replace space_hyphens with em-dash.
  $form['space_hyphens'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Replace stand-alone dashes (normal dashes between whitespace) em-dashes.'),
    '#description' => $this
      ->t('" - " will turn into " — ".'),
    '#default_value' => $settings['space_hyphens'],
  ];

  // Remove widows settings.
  $form['widont_enabled'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Remove widows'),
    '#default_value' => $settings['widont_enabled'],
  ];

  // Remove widows settings.
  $form['hyphenate_shy'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Replace <code>=</code> with <code>&amp;shy;</code>'),
    '#description' => $this
      ->t('Words may be broken at the hyphenation points marked by “=”.'),
    '#default_value' => $settings['hyphenate_shy'],
  ];

  // Replace normal spaces with non-breaking spaces before "double punctuation
  // marks". This is especially useful in french.
  $form['space_to_nbsp'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Replace normal spaces with non-breaking spaces before "double punctuation marks" <code>!?:;</code>.'),
    '#description' => $this
      ->t('This is especially useful for french.'),
    '#default_value' => $settings['space_to_nbsp'],
  ];

  // Wrap caps settings.
  $form['wrap_caps'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Wrap caps'),
    '#default_value' => $settings['wrap_caps'],
  ];

  // Wrap ampersand settings.
  $form['wrap_ampersand'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Wrap ampersands'),
    '#default_value' => $settings['wrap_ampersand'],
  ];
  $form['wrap_abbr'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Thin space in abbreviations'),
    '#description' => $this
      ->t('Wraps abbreviations with <code>@wrapper-code</code> and inserts space after the dots.', [
      '@wrapper-code' => '<span class="abbr">…</span>',
    ]),
    '#default_value' => $settings['wrap_abbr'],
    '#options' => [
      0 => $this
        ->t('Do nothing'),
      4 => $this
        ->t('Insert no space'),
      1 => $this
        ->t('“U+202F“ Narrow no-break space'),
      2 => $this
        ->t('“U+2009“ Thin space'),
      3 => $this
        ->t('span with margin-left: 0.167em'),
    ],
  ];
  $form['wrap_numbers'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Digit grouping in numbers'),
    '#description' => $this
      ->t('Wraps numbers with <code>@wrapper-code</code> and inserts thin space for digit grouping.', [
      '@wrapper-code' => '<span class="number">…</span>',
    ]),
    '#default_value' => $settings['wrap_numbers'],
    '#options' => [
      0 => $this
        ->t('Do nothing'),
      1 => $this
        ->t('“U+202F“ Narrow no-break space'),
      2 => $this
        ->t('“U+2009“ Thin space'),
      3 => $this
        ->t('span with margin-left: 0.167em'),
      4 => $this
        ->t('just wrap numbers'),
    ],
  ];

  // Wrap initial quotes settings.
  $form['wrap_initial_quotes'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Wrap quotation marks'),
    '#default_value' => $settings['wrap_initial_quotes'],
  ];

  // Ligature conversion settings.
  $ligature_options = [];
  foreach (UnicodeConversion::map('ligature') as $ascii => $unicode) {
    $ligature_options[$ascii] = $this
      ->t('Convert <code>@ascii</code> to <code>@unicode</code>', [
      '@ascii' => $ascii,
      '@unicode' => $unicode,
    ]);
  }
  $form['ligatures'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Ligatures'),
    '#options' => $ligature_options,
    '#default_value' => $settings['ligatures'],
  ];

  // Arrow conversion settings.
  $arrow_options = [];
  foreach (UnicodeConversion::map('arrow') as $ascii => $unicode) {
    $arrow_options[$ascii] = $this
      ->t('Convert <code>@ascii</code> to <code>@unicode</code>', [
      '@ascii' => $this
        ->unquote($ascii),
      '@unicode' => $unicode,
    ]);
  }
  $form['arrows'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Arrows'),
    '#options' => $arrow_options,
    '#default_value' => $settings['arrows'],
  ];

  // Fraction conversion settings.
  $fraction_options = [];
  foreach (UnicodeConversion::map('fraction') as $ascii => $unicode) {
    $fraction_options[$ascii] = $this
      ->t('Convert <code>@ascii</code> to <code>@unicode</code>', [
      '@ascii' => $ascii,
      '@unicode' => $unicode,
    ]);
  }
  $form['fractions'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Fractions'),
    '#options' => $fraction_options,
    '#default_value' => $settings['fractions'],
  ];

  // Quotes conversion settings.
  $quotes_options = [];
  foreach (UnicodeConversion::map('quotes') as $quotes => $unicode) {
    $quotes_options[$quotes] = $this
      ->t('Convert <code>@ascii</code> to <code>@unicode</code>', [
      '@ascii' => $this
        ->unquote($quotes),
      '@unicode' => $unicode,
    ]);
  }
  $form['quotes'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Quotes'),
    '#options' => $quotes_options,
    '#default_value' => $settings['quotes'],
  ];

  // Version Information Settings.
  $version_strings = [];
  $version_strings[] = $this
    ->t('SmartyPants PHP version: <a href=":smarty-pants-url">@version</a>', [
    ':smarty-pants-url' => 'http://www.michelf.com/projects/php-smartypants/',
    '@version' => SmartyPants::SMARTYPANTS_PHP_VERSION,
  ]);
  $version_strings[] = $this
    ->t('PHP Typogrify Version: <a href=":php-typogrify-url">@version</a>', [
    ':php-typogrify-url' => 'http://blog.hamstu.com/',
    '@version' => static::TYPOGRIFY_VERSION,
  ]);
  $form['info']['typogrify_status'] = [
    '#theme' => 'item_list',
    '#items' => $version_strings,
    '#title' => $this
      ->t('Versions'),
  ];
  return $form;
}