X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fpathologic%2Fsrc%2FPlugin%2FFilter%2FFilterPathologic.php;fp=web%2Fmodules%2Fcontrib%2Fpathologic%2Fsrc%2FPlugin%2FFilter%2FFilterPathologic.php;h=50b7162620996f0ab800ebe9a258cfb05ae8d6c1;hp=0000000000000000000000000000000000000000;hb=2257eb96fa3afedcfba62207e838f49ee9c757e2;hpb=c2dc9563fba7ea2171f5b00e660cc3f03a9333bd diff --git a/web/modules/contrib/pathologic/src/Plugin/Filter/FilterPathologic.php b/web/modules/contrib/pathologic/src/Plugin/Filter/FilterPathologic.php new file mode 100644 index 000000000..50b716262 --- /dev/null +++ b/web/modules/contrib/pathologic/src/Plugin/Filter/FilterPathologic.php @@ -0,0 +1,96 @@ + 'markup', + '#markup' => $this->t('In most cases, Pathologic should be the last filter in the “Filter processing order” list.'), + '#weight' => 0, + ]; + $form['settings_source'] = [ + '#type' => 'radios', + '#title' => $this->t('Settings source'), + '#description' => $this->t('Select whether Pathologic should use the global Pathologic settings or custom “local” settings when filtering text in this text format.', [':config' => Url::fromRoute('pathologic.config_form')->toString()]), + '#weight' => 10, + '#default_value' => $this->settings['settings_source'], + '#options' => [ + 'global' => $this->t('Use global Pathologic settings'), + 'local' => $this->t('Use custom settings for this text format'), + ], + ]; + // Fields in fieldsets are… awkward to implement. + // @see https://www.drupal.org/node/2378437 + $form['local_settings'] = [ + '#type' => 'fieldset', + '#title' => $this->t('Custom settings for this text format'), + '#weight' => 20, + '#collapsible' => FALSE, + '#collapsed' => FALSE, + '#description' => $this->t('These settings are ignored if “Use global Pathologic settings” is selected above.'), + // @todo Fix the #states magic (or see if it's a core D8 bug) + '#states' => [ + 'visible' => [ + ':input[name="filters[filter_pathologic][settings][settings_source]"]' => ['value' => 'local'], + ], + ], + ]; + + $common = new PathologicSettingsCommon(); + $form['local_settings'] += $common->commonSettingsForm($this->settings['local_settings']); + + return $form; + } + + /** + * {@inheritdoc} + */ + public function process($text, $langcode) { + $settings = $this->settings; + if ($settings['settings_source'] === 'global') { + $config = \Drupal::config('pathologic.settings'); + $settings['protocol_style'] = $config->get('protocol_style'); + $settings['local_paths'] = $config->get('local_paths'); + } + else { + $settings = $settings['local_settings']; + } + // @todo Move code from .module file to inside here. + return new FilterProcessResult(_pathologic_filter($text, $settings, Crypt::hashBase64(serialize($settings)))); + } + +}