Verified Commit 86ddddc9 authored by godotislate's avatar godotislate
Browse files

fix: #3607178 Pass LoggerInterface to Error::logException() in EntityLinks filter

By: remco hoeneveld
By: smustgrave
By: longwave
By: godotislate
(cherry picked from commit d99cea20)
parent cc1d1d86
Loading
Loading
Loading
Loading
Loading
−6
Changes for core/.phpstan-baseline.php: 0 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -14445,12 +14445,6 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/filter/src/Form/FilterDisableForm.php',
];
$ignoreErrors[] = [
	'message' => '#^Parameter \\#1 \\$logger of static method Drupal\\\\Core\\\\Utility\\\\Error\\:\\:logException\\(\\) expects Psr\\\\Log\\\\LoggerInterface, string given\\.$#',
	'identifier' => 'argument.type',
	'count' => 1,
	'path' => __DIR__ . '/modules/filter/src/Plugin/Filter/EntityLinks.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\filter\\\\Plugin\\\\Filter\\\\FilterHtml\\:\\:filterElementAttributes\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
+1 −1
Changes for core/modules/filter/src/Plugin/Filter/EntityLinks.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ public function process($text, $langcode): FilterProcessResult {
        $element->removeAttribute('data-entity-metadata');
      }
      catch (\Exception $e) {
        Error::logException('filter', $e);
        Error::logException(\Drupal::logger('filter'), $e);
      }
    }

+16
Changes for core/modules/filter/tests/src/Kernel/EntityLinksTest.php: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -329,6 +329,22 @@ public function testMenuLinkContentEntity(): void {
    );
  }

  /**
   * Tests that an unresolvable entity link does not throw a fatal error.
   */
  public function testProcessLogsExceptionForUnresolvableEntityLink(): void {
    $input = '<a data-entity-type="true" data-entity-uuid="not-a-real-uuid" href="/original">Link text</a>';

    $result = $this->filter->process($input, 'en');

    $this->assertInstanceOf(FilterProcessResult::class, $result);
    $this->assertTrue($this->logger->hasRecords());
    $processed = $result->getProcessedText();
    $this->assertStringContainsString('data-entity-type="true"', $processed);
    $this->assertStringContainsString('data-entity-uuid="not-a-real-uuid"', $processed);
    $this->assertStringContainsString('href="/original"', $processed);
  }

  /**
   * Asserts an input string + langcode yield the expected FilterProcessResult.
   *