Verified Commit ec8c0566 authored by Andrei Mateescu's avatar Andrei Mateescu
Browse files

task: #3226806 Move filter implementations from filter.module to plugin classes

By: claudiu.cristea
By: nicxvan
By: longwave
By: joachim
By: amateescu
By: larowlan
parent f14dbcc2
Loading
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -14749,12 +14749,6 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/filter/filter.module',
];
$ignoreErrors[] = [
	'message' => '#^Parameter \\#1 \\$match of function _filter_url_escape_comments expects array, string given\\.$#',
	'identifier' => 'argument.type',
	'count' => 2,
	'path' => __DIR__ . '/modules/filter/filter.module',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\filter\\\\Element\\\\TextFormat\\:\\:currentUser\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
+85 −262

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ public function help($route_name, RouteMatchInterface $route_match): ?string {
   *
   * Formats an image DOM element that has an invalid source.
   *
   * @see _filter_html_image_secure_process()
   * @see \Drupal\filter\Plugin\Filter\FilterHtmlImageSecure::process()
   */
  #[Hook('filter_secure_image_alter')]
  public function filterSecureImageAlter(&$image): void {
+89 −1
Original line number Diff line number Diff line
@@ -22,7 +22,95 @@ class FilterAutoP extends FilterBase {
   * {@inheritdoc}
   */
  public function process($text, $langcode) {
    return new FilterProcessResult(_filter_autop($text));
    // All block level tags.
    $block = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|input|p|h[1-6]|fieldset|legend|hr|article|aside|details|figcaption|figure|footer|header|hgroup|menu|nav|section|summary)';

    // Split at opening and closing PRE, SCRIPT, STYLE, OBJECT, IFRAME tags and
    // comments. We don't apply any processing to the contents of these tags to
    // avoid messing up code. We look for matched pairs and allow basic nesting.
    // For example,
    // "processed<pre>ignored<script>ignored</script>ignored</pre>processed".
    $chunks = preg_split('@(<!--.*?-->|</?(?:pre|script|style|object|iframe|drupal-media|svg|!--)[^>]*>)@i', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    // Note: PHP ensures the array consists of alternating delimiters and
    // literals and begins and ends with a literal (inserting NULL as required).
    $ignore = FALSE;
    $ignore_tag = '';
    $output = '';
    foreach ($chunks as $i => $chunk) {
      if ($i % 2) {
        if (str_starts_with($chunk, '<!--')) {
          // Nothing to do, this is a comment.
          $output .= $chunk;
          continue;
        }
        // Opening or closing tag?
        $open = ($chunk[1] != '/');
        [$tag] = preg_split('/[ >]/', substr($chunk, 2 - $open), 2);
        if (!$ignore) {
          if ($open) {
            $ignore = TRUE;
            $ignore_tag = $tag;
          }
        }
        // Only allow a matching tag to close it.
        elseif (!$open && $ignore_tag == $tag) {
          $ignore = FALSE;
          $ignore_tag = '';
        }
      }
      elseif (!$ignore) {
        // Skip if the next chunk starts with Twig theme debug.
        // @see twig_render_template()
        if (isset($chunks[$i + 1]) && $chunks[$i + 1] === '<!-- THEME DEBUG -->') {
          $chunk = rtrim($chunk, "\n");
          $output .= $chunk;
          continue;
        }

        // Skip if the preceding chunk was the end of a Twig theme debug.
        // @see \Drupal\Core\Template\TwigThemeEngine::renderTemplate()
        if (isset($chunks[$i - 1])) {
          if (
            str_starts_with($chunks[$i - 1], '<!-- BEGIN OUTPUT from ')
            || str_starts_with($chunks[$i - 1], '<!-- 💡 BEGIN CUSTOM TEMPLATE OUTPUT from ')
          ) {
            $chunk = ltrim($chunk, "\n");
            $output .= $chunk;
            continue;
          }
        }

        // Just to make things a little easier, pad the end.
        $chunk = preg_replace('|\n*$|', '', $chunk) . "\n\n";
        $chunk = preg_replace('|<br />\s*<br />|', "\n\n", $chunk);
        // Space things out a little.
        $chunk = preg_replace('!(<' . $block . '[^>]*>)!', "\n$1", $chunk);
        // Space things out a little.
        $chunk = preg_replace('!(</' . $block . '>)!', "$1\n\n", $chunk);
        // Take care of duplicates.
        $chunk = preg_replace("/\n\n+/", "\n\n", $chunk);
        $chunk = preg_replace('/^\n|\n\s*\n$/', '', $chunk);
        // Make paragraphs, including one at the end.
        $chunk = '<p>' . preg_replace('/\n\s*\n\n?(.)/', "</p>\n<p>$1", $chunk) . "</p>\n";
        // Problem with nested lists.
        $chunk = preg_replace("|<p>(<li.+?)</p>|", "$1", $chunk);
        $chunk = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $chunk);
        $chunk = str_replace('</blockquote></p>', '</p></blockquote>', $chunk);
        // Under certain strange conditions it could create a P of entirely
        // whitespace.
        $chunk = preg_replace('|<p>\s*</p>\n?|', '', $chunk);
        $chunk = preg_replace('!<p>\s*(</?' . $block . '[^>]*>)!', "$1", $chunk);
        $chunk = preg_replace('!(</?' . $block . '[^>]*>)\s*</p>!', "$1", $chunk);
        // Make line breaks.
        $chunk = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $chunk);
        $chunk = preg_replace('!(</?' . $block . '[^>]*>)\s*<br />!', "$1", $chunk);
        $chunk = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)!', '$1', $chunk);
        $chunk = preg_replace('/&([^#])(?![A-Za-z0-9]{1,8};)/', '&amp;$1', $chunk);
      }
      $output .= $chunk;
    }

    return new FilterProcessResult($output);
  }

  /**
+2 −1

File changed.

Preview size limit exceeded, changes collapsed.

Loading