Skip to content
Snippets Groups Projects
Commit 020433e7 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3516676 by alexpott: If the link text matches the URL it should also be removed

parent 7deace54
No related branches found
No related tags found
1 merge request!26Remove URL text if it contains the URL
Pipeline #462597 passed
parameters:
ignoreErrors:
-
message: "#^Method Drupal\\\\entity_usage_updater\\\\EntityUsageUpdater\\:\\:finish\\(\\) has no return type specified\\.$#"
message: '#^Method Drupal\\entity_usage_updater\\EntityUsageUpdater\:\:finish\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: src/EntityUsageUpdater.php
-
message: "#^Method Drupal\\\\entity_usage_updater\\\\EntityUsageUpdater\\:\\:updateReferences\\(\\) has no return type specified\\.$#"
message: '#^Method Drupal\\entity_usage_updater\\EntityUsageUpdater\:\:updateReferences\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: src/EntityUsageUpdater.php
-
message: "#^Method Drupal\\\\entity_usage_updater\\\\Form\\\\SettingsForm\\:\\:create\\(\\) has no return type specified\\.$#"
message: '#^Method Drupal\\entity_usage_updater\\Form\\SettingsForm\:\:create\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: src/Form/SettingsForm.php
-
message: "#^If condition is always true\\.$#"
message: '#^If condition is always true\.$#'
identifier: if.alwaysTrue
count: 1
path: src/Plugin/EntityUsageUpdater/HtmlLink.php
-
message: "#^Method Drupal\\\\entity_usage_updater\\\\Plugin\\\\EntityUsageUpdater\\\\HtmlLink\\:\\:getUuid\\(\\) has parameter \\$entity_id with no type specified\\.$#"
message: '#^Method Drupal\\entity_usage_updater\\Plugin\\EntityUsageUpdater\\HtmlLink\:\:getUuid\(\) has parameter \$entity_id with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: src/Plugin/EntityUsageUpdater/HtmlLink.php
-
message: "#^Method Drupal\\\\entity_usage_updater\\\\Plugin\\\\EntityUsageUpdater\\\\HtmlLink\\:\\:parseEntitiesFromText\\(\\) has no return type specified\\.$#"
message: '#^Method Drupal\\entity_usage_updater\\Plugin\\EntityUsageUpdater\\HtmlLink\:\:parseEntitiesFromText\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: src/Plugin/EntityUsageUpdater/HtmlLink.php
-
message: "#^Method Drupal\\\\entity_usage_updater\\\\Plugin\\\\EntityUsageUpdater\\\\HtmlLink\\:\\:submitConfigurationForm\\(\\) has no return type specified\\.$#"
message: '#^Method Drupal\\entity_usage_updater\\Plugin\\EntityUsageUpdater\\HtmlLink\:\:submitConfigurationForm\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: src/Plugin/EntityUsageUpdater/HtmlLink.php
-
message: "#^Method Drupal\\\\entity_usage_updater\\\\Plugin\\\\EntityUsageUpdater\\\\HtmlLink\\:\\:validateConfigurationForm\\(\\) has no return type specified\\.$#"
message: '#^Method Drupal\\entity_usage_updater\\Plugin\\EntityUsageUpdater\\HtmlLink\:\:validateConfigurationForm\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: src/Plugin/EntityUsageUpdater/HtmlLink.php
-
message: "#^Parameter \\#4 \\$text of method Drupal\\\\entity_usage_updater\\\\Plugin\\\\EntityUsageUpdater\\\\LinkIt\\:\\:updateItemProperty\\(\\) expects Drupal\\\\Core\\\\TypedData\\\\Type\\\\StringInterface, Drupal\\\\Core\\\\TypedData\\\\TypedDataInterface given\\.$#"
message: '#^Parameter \#4 \$text of method Drupal\\entity_usage_updater\\Plugin\\EntityUsageUpdater\\LinkIt\:\:updateItemProperty\(\) expects Drupal\\Core\\TypedData\\Type\\StringInterface, Drupal\\Core\\TypedData\\TypedDataInterface given\.$#'
identifier: argument.type
count: 2
path: src/Plugin/EntityUsageUpdater/LinkIt.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityInterface\\:\\:set\\(\\)\\.$#"
message: '#^Call to an undefined method Drupal\\Core\\Entity\\EntityInterface\:\:set\(\)\.$#'
identifier: method.notFound
count: 1
path: tests/src/Kernel/EntityUsageUpdaterParagraphsTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\RevisionableInterface\\:\\:set\\(\\)\\.$#"
message: '#^Call to an undefined method Drupal\\Core\\Entity\\RevisionableInterface\:\:set\(\)\.$#'
identifier: method.notFound
count: 2
path: tests/src/Kernel/EntityUsageUpdaterParagraphsTest.php
-
message: "#^Access to an undefined property Drupal\\\\Core\\\\Entity\\\\TranslatableInterface\\:\\:\\$field_reference\\.$#"
message: '#^Access to an undefined property Drupal\\Core\\Entity\\TranslatableInterface\:\:\$field_reference\.$#'
identifier: property.notFound
count: 7
path: tests/src/Kernel/EntityUsageUpdaterSimpleMulRevTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\TranslatableRevisionableInterface\\:\\:set\\(\\)\\.$#"
message: '#^Call to an undefined method Drupal\\Core\\Entity\\TranslatableRevisionableInterface\:\:set\(\)\.$#'
identifier: method.notFound
count: 1
path: tests/src/Kernel/EntityUsageUpdaterSimpleMulRevTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityInterface\\:\\:get\\(\\)\\.$#"
message: '#^Call to an undefined method Drupal\\Core\\Entity\\EntityInterface\:\:get\(\)\.$#'
identifier: method.notFound
count: 1
path: tests/src/Kernel/EntityUsageUpdaterSimpleRevTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\RevisionableInterface\\:\\:set\\(\\)\\.$#"
message: '#^Call to an undefined method Drupal\\Core\\Entity\\RevisionableInterface\:\:set\(\)\.$#'
identifier: method.notFound
count: 1
path: tests/src/Kernel/EntityUsageUpdaterSimpleRevTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityInterface\\:\\:set\\(\\)\\.$#"
message: '#^Call to an undefined method Drupal\\Core\\Entity\\EntityInterface\:\:set\(\)\.$#'
identifier: method.notFound
count: 1
path: tests/src/Kernel/EntityUsageUpdaterSimpleTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityInterface\\:\\:set\\(\\)\\.$#"
message: '#^Call to an undefined method Drupal\\Core\\Entity\\EntityInterface\:\:set\(\)\.$#'
identifier: method.notFound
count: 1
path: tests/src/Kernel/EntityUsageUpdaterViolationTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityInterface\\:\\:get\\(\\)\\.$#"
message: '#^Call to an undefined method Drupal\\Core\\Entity\\EntityInterface\:\:get\(\)\.$#'
identifier: method.notFound
count: 4
path: tests/src/Kernel/Plugin/EntityReferencePluginTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityInterface\\:\\:set\\(\\)\\.$#"
message: '#^Call to an undefined method Drupal\\Core\\Entity\\EntityInterface\:\:set\(\)\.$#'
identifier: method.notFound
count: 2
path: tests/src/Kernel/Plugin/EntityReferencePluginTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityInterface\\:\\:get\\(\\)\\.$#"
message: '#^Call to an undefined method Drupal\\Core\\Entity\\EntityInterface\:\:get\(\)\.$#'
identifier: method.notFound
count: 2
path: tests/src/Kernel/Plugin/HtmlLinkPluginLinkItTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityInterface\\:\\:set\\(\\)\\.$#"
message: '#^Call to an undefined method Drupal\\Core\\Entity\\EntityInterface\:\:set\(\)\.$#'
identifier: method.notFound
count: 1
path: tests/src/Kernel/Plugin/HtmlLinkPluginLinkItTest.php
-
message: "#^Method Drupal\\\\Tests\\\\entity_usage_updater\\\\Kernel\\\\Plugin\\\\HtmlLinkPluginLinkItTest\\:\\:updateLinkTexts\\(\\) return type has no value type specified in iterable type iterable\\.$#"
message: '#^Method Drupal\\Tests\\entity_usage_updater\\Kernel\\Plugin\\HtmlLinkPluginLinkItTest\:\:updateLinkTexts\(\) return type has no value type specified in iterable type iterable\.$#'
identifier: missingType.iterableValue
count: 1
path: tests/src/Kernel/Plugin/HtmlLinkPluginLinkItTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityInterface\\:\\:addTranslation\\(\\)\\.$#"
message: '#^Call to an undefined method Drupal\\Core\\Entity\\EntityInterface\:\:addTranslation\(\)\.$#'
identifier: method.notFound
count: 1
path: tests/src/Kernel/Plugin/HtmlLinkPluginTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityInterface\\:\\:get\\(\\)\\.$#"
count: 6
message: '#^Call to an undefined method Drupal\\Core\\Entity\\EntityInterface\:\:get\(\)\.$#'
identifier: method.notFound
count: 8
path: tests/src/Kernel/Plugin/HtmlLinkPluginTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityInterface\\:\\:set\\(\\)\\.$#"
count: 3
message: '#^Call to an undefined method Drupal\\Core\\Entity\\EntityInterface\:\:set\(\)\.$#'
identifier: method.notFound
count: 4
path: tests/src/Kernel/Plugin/HtmlLinkPluginTest.php
-
message: "#^Method Drupal\\\\Tests\\\\entity_usage_updater\\\\Kernel\\\\Plugin\\\\HtmlLinkPluginTest\\:\\:removeLinkTexts\\(\\) return type has no value type specified in iterable type iterable\\.$#"
message: '#^Method Drupal\\Tests\\entity_usage_updater\\Kernel\\Plugin\\HtmlLinkPluginTest\:\:removeLinkTexts\(\) return type has no value type specified in iterable type iterable\.$#'
identifier: missingType.iterableValue
count: 1
path: tests/src/Kernel/Plugin/HtmlLinkPluginTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityInterface\\:\\:get\\(\\)\\.$#"
message: '#^Call to an undefined method Drupal\\Core\\Entity\\EntityInterface\:\:get\(\)\.$#'
identifier: method.notFound
count: 4
path: tests/src/Kernel/Plugin/LinkItPluginTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityInterface\\:\\:set\\(\\)\\.$#"
message: '#^Call to an undefined method Drupal\\Core\\Entity\\EntityInterface\:\:set\(\)\.$#'
identifier: method.notFound
count: 2
path: tests/src/Kernel/Plugin/LinkItPluginTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityInterface\\:\\:get\\(\\)\\.$#"
message: '#^Call to an undefined method Drupal\\Core\\Entity\\EntityInterface\:\:get\(\)\.$#'
identifier: method.notFound
count: 4
path: tests/src/Kernel/Plugin/LinkPluginTest.php
-
message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityInterface\\:\\:set\\(\\)\\.$#"
message: '#^Call to an undefined method Drupal\\Core\\Entity\\EntityInterface\:\:set\(\)\.$#'
identifier: method.notFound
count: 2
path: tests/src/Kernel/Plugin/LinkPluginTest.php
-
message: "#^Method Drupal\\\\Tests\\\\entity_usage_updater\\\\Tools\\\\TestLogger\\:\\:alert\\(\\) has parameter \\$message with no type specified\\.$#"
message: '#^Method Drupal\\Tests\\entity_usage_updater\\Tools\\TestLogger\:\:alert\(\) has parameter \$message with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/src/Tools/TestLogger.php
-
message: "#^Method Drupal\\\\Tests\\\\entity_usage_updater\\\\Tools\\\\TestLogger\\:\\:critical\\(\\) has parameter \\$message with no type specified\\.$#"
message: '#^Method Drupal\\Tests\\entity_usage_updater\\Tools\\TestLogger\:\:critical\(\) has parameter \$message with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/src/Tools/TestLogger.php
-
message: "#^Method Drupal\\\\Tests\\\\entity_usage_updater\\\\Tools\\\\TestLogger\\:\\:debug\\(\\) has parameter \\$message with no type specified\\.$#"
message: '#^Method Drupal\\Tests\\entity_usage_updater\\Tools\\TestLogger\:\:debug\(\) has parameter \$message with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/src/Tools/TestLogger.php
-
message: "#^Method Drupal\\\\Tests\\\\entity_usage_updater\\\\Tools\\\\TestLogger\\:\\:emergency\\(\\) has parameter \\$message with no type specified\\.$#"
message: '#^Method Drupal\\Tests\\entity_usage_updater\\Tools\\TestLogger\:\:emergency\(\) has parameter \$message with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/src/Tools/TestLogger.php
-
message: "#^Method Drupal\\\\Tests\\\\entity_usage_updater\\\\Tools\\\\TestLogger\\:\\:error\\(\\) has parameter \\$message with no type specified\\.$#"
message: '#^Method Drupal\\Tests\\entity_usage_updater\\Tools\\TestLogger\:\:error\(\) has parameter \$message with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/src/Tools/TestLogger.php
-
message: "#^Method Drupal\\\\Tests\\\\entity_usage_updater\\\\Tools\\\\TestLogger\\:\\:info\\(\\) has parameter \\$message with no type specified\\.$#"
message: '#^Method Drupal\\Tests\\entity_usage_updater\\Tools\\TestLogger\:\:info\(\) has parameter \$message with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/src/Tools/TestLogger.php
-
message: "#^Method Drupal\\\\Tests\\\\entity_usage_updater\\\\Tools\\\\TestLogger\\:\\:log\\(\\) has parameter \\$message with no type specified\\.$#"
message: '#^Method Drupal\\Tests\\entity_usage_updater\\Tools\\TestLogger\:\:log\(\) has parameter \$message with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/src/Tools/TestLogger.php
-
message: "#^Method Drupal\\\\Tests\\\\entity_usage_updater\\\\Tools\\\\TestLogger\\:\\:notice\\(\\) has parameter \\$message with no type specified\\.$#"
message: '#^Method Drupal\\Tests\\entity_usage_updater\\Tools\\TestLogger\:\:notice\(\) has parameter \$message with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/src/Tools/TestLogger.php
-
message: "#^Method Drupal\\\\Tests\\\\entity_usage_updater\\\\Tools\\\\TestLogger\\:\\:warning\\(\\) has parameter \\$message with no type specified\\.$#"
message: '#^Method Drupal\\Tests\\entity_usage_updater\\Tools\\TestLogger\:\:warning\(\) has parameter \$message with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: tests/src/Tools/TestLogger.php
......@@ -3,6 +3,7 @@
namespace Drupal\entity_usage_updater;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\TypedData\Type\StringInterface;
......@@ -67,9 +68,14 @@ trait LinkRemoverTrait {
) {
// Copy inner HTML to a new fragment.
$fragment = $dom->createDocumentFragment();
$parsed_url = UrlHelper::parse($href);
// If the text content contains the href then remove it completely.
if (!str_contains($element->textContent, $parsed_url['path'])) {
$fragment->appendXML(
array_reduce(iterator_to_array($element->childNodes), fn(string $carry, \DomNode $child) => $carry . $dom->saveXML($child), '')
);
}
// Replace link with fragment.
$element->parentNode->replaceChild($fragment, $element);
$elements_replaced = TRUE;
......
......
......@@ -38,6 +38,7 @@ abstract class EntityUsageUpdaterKernelTestBase extends EntityKernelTestBase {
protected function setUp(): void {
parent::setUp();
$this->installConfig(['entity_usage']);
$this->config('entity_usage.settings')->set('site_domains', ['http://localhost'])->save();
$this->installSchema('entity_usage', ['entity_usage']);
$this->installEntitySchema(static::$entityTypeId);
$this->storage = $this->container->get('entity_type.manager')
......
......
......@@ -105,6 +105,10 @@ class HtmlLinkPluginTest extends HtmlLinkPluginTestBase {
'<p>Invalid markup (missing closing p tag).',
];
yield 'Correct markup with link in the link text' => [
'<p>Some text with <a href="%%ENTITY_URL%%?foo=bar#fragment">%%ENTITY_URL%%</a>.</p>',
'<p>Some text with .</p>',
];
}
/**
......@@ -125,4 +129,22 @@ class HtmlLinkPluginTest extends HtmlLinkPluginTestBase {
$this->assertSame($expected, $this->entity->get('test_field')->value);
}
/**
* Tests removing a link in a text field.
*
* @dataProvider removeLinkTexts
*/
public function testRemoveAbsolute(string $initial, string $expected): void {
$target = $this->storage->create();
$target->save();
$new_entity = $this->storage->create();
$new_entity->save();
$initial_text = str_replace('%%ENTITY_URL%%', $target->toUrl()->setAbsolute()->toString(), $initial);
$this->entity->set('test_field', $initial_text);
$this->plugin->remove($target, $this->entity->get('test_field')[0]);
$this->assertSame($expected, $this->entity->get('test_field')->value);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment