Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / pathologic / src / Plugin / Filter / FilterPathologic.php
1 <?php
2
3 namespace Drupal\pathologic\Plugin\Filter;
4
5 use Drupal\filter\FilterProcessResult;
6 use Drupal\filter\Plugin\FilterBase;
7 use Drupal\Component\Utility\Crypt;
8 use Drupal\Core\Form\FormStateInterface;
9 use Drupal\pathologic\PathologicSettingsCommon;
10 use Drupal\Core\Url;
11
12 /**
13  * Attempts to correct broken paths in content.
14  *
15  * We give the filter a weight of 50 in the annotation below because in almost
16  * all cases Pathologic should be the last filter in the filter list. Is it
17  * possible to put a comment inside an annotation? Man, annotations are such a
18  * stupid idea.
19  *
20  * @Filter(
21  *   id = "filter_pathologic",
22  *   title = @Translation("Correct URLs with Pathologic"),
23  *   type = Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
24  *   settings = {
25  *     "settings_source" = "global",
26  *     "local_settings" = {
27  *       "protocol_style" = "full",
28  *       "local_paths" = ""
29  *     }
30  *   },
31  *   weight = 50
32  * )
33  */
34 class FilterPathologic extends FilterBase {
35
36   /**
37    * {@inheritdoc}
38    */
39   public function settingsForm(array $form, FormStateInterface $form_state) {
40     $form['reminder'] = [
41       '#type' => 'markup',
42       '#markup' => $this->t('In most cases, Pathologic should be the <em>last</em> filter in the &ldquo;Filter processing order&rdquo; list.'),
43       '#weight' => 0,
44     ];
45     $form['settings_source'] = [
46       '#type' => 'radios',
47       '#title' => $this->t('Settings source'),
48       '#description' => $this->t('Select whether Pathologic should use the <a href=":config">global Pathologic settings</a> or custom &ldquo;local&rdquo; settings when filtering text in this text format.', [':config' => Url::fromRoute('pathologic.config_form')->toString()]),
49       '#weight' => 10,
50       '#default_value' => $this->settings['settings_source'],
51       '#options' => [
52         'global' => $this->t('Use global Pathologic settings'),
53         'local' => $this->t('Use custom settings for this text format'),
54       ],
55     ];
56     // Fields in fieldsets areā€¦ awkward to implement.
57     // @see https://www.drupal.org/node/2378437
58     $form['local_settings'] = [
59       '#type' => 'fieldset',
60       '#title' => $this->t('Custom settings for this text format'),
61       '#weight' => 20,
62       '#collapsible' => FALSE,
63       '#collapsed' => FALSE,
64       '#description' => $this->t('These settings are ignored if &ldquo;Use global Pathologic settings&rdquo; is selected above.'),
65       // @todo Fix the #states magic (or see if it's a core D8 bug)
66       '#states' => [
67         'visible' => [
68           ':input[name="filters[filter_pathologic][settings][settings_source]"]' => ['value' => 'local'],
69         ],
70       ],
71     ];
72
73     $common = new PathologicSettingsCommon();
74     $form['local_settings'] += $common->commonSettingsForm($this->settings['local_settings']);
75
76     return $form;
77   }
78
79   /**
80    * {@inheritdoc}
81    */
82   public function process($text, $langcode) {
83     $settings = $this->settings;
84     if ($settings['settings_source'] === 'global') {
85       $config = \Drupal::config('pathologic.settings');
86       $settings['protocol_style'] = $config->get('protocol_style');
87       $settings['local_paths'] = $config->get('local_paths');
88     }
89     else {
90       $settings = $settings['local_settings'];
91     }
92     // @todo Move code from .module file to inside here.
93     return new FilterProcessResult(_pathologic_filter($text, $settings, Crypt::hashBase64(serialize($settings))));
94   }
95
96 }