From d59abf12ca3f6d2e931b31f941f1590ff658ce4d Mon Sep 17 00:00:00 2001
From: Stephen Mustgrave <smustgrave@gmail.com>
Date: Fri, 21 Mar 2025 16:42:08 -0400
Subject: [PATCH 1/4] Issue #3224980 by mariacha1, smustgrave: Add ability to
 search link fields

---
 src/Form/ScannerAdminForm.php              |  2 +-
 src/Plugin/Scanner/Node.php                | 57 ++++++++++++++++++-
 src/Plugin/Scanner/Paragraph.php           | 24 +++++++-
 tests/src/Functional/ScannerAdminTest.php  |  6 ++
 tests/src/Functional/ScannerTestBase.php   | 54 ++++++++++++++++--
 tests/src/Functional/SearchReplaceTest.php | 66 +++++++++++++++++-----
 6 files changed, 188 insertions(+), 21 deletions(-)

diff --git a/src/Form/ScannerAdminForm.php b/src/Form/ScannerAdminForm.php
index dcb4828..4855913 100644
--- a/src/Form/ScannerAdminForm.php
+++ b/src/Form/ScannerAdminForm.php
@@ -279,7 +279,7 @@ class ScannerAdminForm extends ConfigFormBase {
         }
         $allowed_field_type = [
           // @todo Why no string_long?
-          'string', 'text_with_summary', 'text', 'text_long',
+          'string', 'text_with_summary', 'text', 'text_long', 'link'
         ];
         // We are only interested in certain field types.
         if (in_array($field_definition->getType(), $allowed_field_type, TRUE)) {
diff --git a/src/Plugin/Scanner/Node.php b/src/Plugin/Scanner/Node.php
index c2742ac..4d940cb 100644
--- a/src/Plugin/Scanner/Node.php
+++ b/src/Plugin/Scanner/Node.php
@@ -80,7 +80,7 @@ class Node extends Entity {
           }
           $title_collect[$id]['field'] = $newValues;
         }
-        elseif ($fieldType == 'string') {
+        elseif (in_array($fieldType, ['string', 'link'])) {
           $title_collect[$id]['title'] = $node->getTitle();
           preg_match($conditionVals['phpRegex'], $nodeField->getString(), $matches, PREG_OFFSET_CAPTURE);
           $match = $matches[0][0];
@@ -194,6 +194,61 @@ class Node extends Entity {
           $node->save();
           $data["node:$id"]['new_vid'] = $node->vid->getString();
         }
+        elseif ($fieldType == 'link') {
+          if (!isset($data["node:$id"]['new_vid'])) {
+            if ($values['language'] === 'all') {
+              $all_languages = AdminHelper::getAllEnabledLanguages();
+              foreach ($all_languages as $langcode => $languageName) {
+                if ($node->hasTranslation($langcode)) {
+                  $node = $node->getTranslation($langcode);
+                  $nodeField = $node->get($fieldname);
+                }
+                $new_value = [];
+                foreach($nodeField->getValue() as $delta => $field_value) {
+                  foreach ($field_value as $field_element => $field_element_value) {
+                    if (is_string($field_element_value)) {
+                      $fieldValue = preg_replace($conditionVals['phpRegex'], $values['replace'], $field_element_value);
+                    }
+                    else {
+                      $fieldValue = $field_element_value;
+                    }
+                    $new_value[$delta][$field_element] = $fieldValue;
+                  }
+                }
+                $node->$fieldname = $new_value;
+              }
+              $data["node:$id"]['old_vid'] = $node->vid->getString();
+              $node->setNewRevision(TRUE);
+              $node->revision_log = $this->t('Replaced %search with %replace via Scanner Search and Replace module.', ['%search' => $values['search'], '%replace' => $values['replace']]);
+            }
+            else {
+              $requested_lang = $values['language'];
+              if ($node->hasTranslation($requested_lang)) {
+                // $nodeField = $nodeField->getTranslation($requested_lang);
+                $node = $node->getTranslation($requested_lang);
+                $nodeField = $node->get($fieldname);
+              }
+              $new_value = [];
+              foreach($nodeField->getValue() as $delta => $field_value) {
+                foreach ($field_value as $field_element => $field_element_value) {
+                  if (is_string($field_element_value)) {
+                    $fieldValue = preg_replace($conditionVals['phpRegex'], $values['replace'], $field_element_value);
+                  }
+                  else {
+                    $fieldValue = $field_element_value;
+                  }
+                  $new_value[$delta][$field_element] = $fieldValue;
+                }
+              }
+              $node->$fieldname = $new_value;
+              $data["node:$id"]['old_vid'] = $node->vid->getString();
+              $node->setNewRevision(TRUE);
+              $node->revision_log = $this->t('Replaced %search with %replace via Scanner Search and Replace module.', ['%search' => $values['search'], '%replace' => $values['replace']]);
+            }
+          }
+          $node->save();
+          $data["node:$id"]['new_vid'] = $node->vid->getString();
+        }
       }
     }
     catch (InvalidPluginDefinitionException | PluginNotFoundException | EntityStorageException $e) {
diff --git a/src/Plugin/Scanner/Paragraph.php b/src/Plugin/Scanner/Paragraph.php
index f2ef46f..0c90793 100644
--- a/src/Plugin/Scanner/Paragraph.php
+++ b/src/Plugin/Scanner/Paragraph.php
@@ -107,7 +107,7 @@ class Paragraph extends Entity {
                 }
                 $title_collect[$id]['field'] = $newValues;
               }
-              elseif ($fieldType == 'string') {
+              elseif (in_array($fieldType, ['string', 'link'])) {
                 $title_collect[$id]['title'] = $parentEntity->getTitle();
                 preg_match($conditionVals['phpRegex'], $paraField->getString(), $matches, PREG_OFFSET_CAPTURE);
                 $match = $matches[0][0];
@@ -177,6 +177,28 @@ class Paragraph extends Entity {
           $data["paragraph:$pid"]['new_vid'] = $paragraph->getRevisionId();
           $this->handleParentRelationship($paragraph, $values, $data);
         }
+        elseif ($fieldType == 'link') {
+          $new_value = [];
+          foreach($paraField->getValue() as $delta => $field_value) {
+            foreach ($field_value as $field_element => $field_element_value) {
+              if (is_string($field_element_value)) {
+                $fieldValue = preg_replace($conditionVals['phpRegex'], $values['replace'], $field_element_value);
+              }
+              else {
+                $fieldValue = $field_element_value;
+              }
+              $new_value[$delta][$field_element] = $fieldValue;
+            }
+          }
+          $paragraph->$fieldname = $new_value;
+          if (!isset($data["paragraph:$pid"]['new_vid'])) {
+            $data["paragraph:$pid"]['old_vid'] = $paragraph->getRevisionId();
+            $paragraph->setNewRevision(TRUE);
+          }
+          $paragraph->save();
+          $data["paragraph:$pid"]['new_vid'] = $paragraph->getRevisionId();
+          $this->handleParentRelationship($paragraph, $values, $data);
+        }
       }
     }
     catch (InvalidPluginDefinitionException | PluginNotFoundException | EntityStorageException $e) {
diff --git a/tests/src/Functional/ScannerAdminTest.php b/tests/src/Functional/ScannerAdminTest.php
index 64664c5..ab0f887 100644
--- a/tests/src/Functional/ScannerAdminTest.php
+++ b/tests/src/Functional/ScannerAdminTest.php
@@ -11,6 +11,7 @@ class ScannerAdminTest extends ScannerTestBase {
 
   /**
    * {@inheritdoc}
+   * @throws \Drupal\Core\Entity\EntityStorageException
    */
   protected function setUp(): void {
     // Make sure to complete the normal setup steps first.
@@ -42,6 +43,9 @@ class ScannerAdminTest extends ScannerTestBase {
 
   /**
    * Tests that the base admin settings form is functional.
+   *
+   * @throws \Behat\Mink\Exception\ElementNotFoundException
+   * @throws \Behat\Mink\Exception\ExpectationException
    */
   public function testAdminSettingsForm() {
     // Confirm the settings form loads.
@@ -66,6 +70,8 @@ class ScannerAdminTest extends ScannerTestBase {
 
   /**
    * Tests that the supported entity fields are present.
+   *
+   * @throws \Behat\Mink\Exception\ExpectationException
    */
   public function testAdminSettingsEntityTypeFields(): void {
     // Confirm the settings form loads.
diff --git a/tests/src/Functional/ScannerTestBase.php b/tests/src/Functional/ScannerTestBase.php
index 1d6be8d..4e1aba6 100644
--- a/tests/src/Functional/ScannerTestBase.php
+++ b/tests/src/Functional/ScannerTestBase.php
@@ -3,9 +3,14 @@
 namespace Drupal\Tests\scanner\Functional;
 
 use Drupal\Component\Render\FormattableMarkup;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\field\Entity\FieldConfig;
+use Drupal\field\Entity\FieldStorageConfig;
+use Drupal\link\LinkItemInterface;
 use Drupal\node\NodeInterface;
 use Drupal\taxonomy\Entity\Term;
 use Drupal\taxonomy\Entity\Vocabulary;
+use Drupal\taxonomy\TermInterface;
 use Drupal\Tests\BrowserTestBase;
 use Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsTestBaseTrait;
 use Drupal\user\Entity\User;
@@ -27,7 +32,13 @@ abstract class ScannerTestBase extends BrowserTestBase {
    *
    * @var array
    */
-  protected static $modules = ['node', 'paragraphs', 'views', 'scanner'];
+  protected static $modules = [
+    'node',
+    'link',
+    'paragraphs',
+    'views',
+    'scanner',
+  ];
 
   /**
    * Log in as user 1.
@@ -79,7 +90,7 @@ abstract class ScannerTestBase extends BrowserTestBase {
     $vocab = Vocabulary::create($values);
     $status = $vocab->save();
 
-    $this->assertEquals($status, SAVED_NEW, (new FormattableMarkup('Created vocabulary %type.', ['%type' => $vocab->id()]))->__toString());
+    $this->assertEquals(SAVED_NEW, $status, (new FormattableMarkup('Created vocabulary %type.', ['%type' => $vocab->id()]))->__toString());
 
     return $vocab;
   }
@@ -95,7 +106,7 @@ abstract class ScannerTestBase extends BrowserTestBase {
    *
    * @throws \Drupal\Core\Entity\EntityStorageException
    */
-  protected function createTerm(array $values = []) {
+  protected function createTerm(array $values = []): TermInterface|EntityInterface {
     // Populate defaults array.
     $values += [
       'description' => [
@@ -109,7 +120,7 @@ abstract class ScannerTestBase extends BrowserTestBase {
     $term = Term::create($values);
     $status = $term->save();
 
-    $this->assertEquals($status, SAVED_NEW, (new FormattableMarkup('Created term %name.', ['%name' => $term->label()]))->__toString());
+    $this->assertEquals(SAVED_NEW, $status, (new FormattableMarkup('Created term %name.', ['%name' => $term->label()]))->__toString());
 
     return $term;
   }
@@ -128,6 +139,8 @@ abstract class ScannerTestBase extends BrowserTestBase {
    *
    * @return \Drupal\node\NodeInterface
    *   A fully formatted node object.
+   *
+   * @throws \Drupal\Core\Entity\EntityStorageException
    */
   protected function createContentTypeNode(string $title, string $body, string $content_type, string $content_type_label): NodeInterface {
     $args = [
@@ -136,6 +149,34 @@ abstract class ScannerTestBase extends BrowserTestBase {
     ];
     $this->createContentType($args);
 
+    $field_name = 'link_field';
+    // Create a field with settings to validate.
+    $fieldStorage = FieldStorageConfig::create([
+      'field_name' => $field_name,
+      'entity_type' => 'node',
+      'type' => 'link',
+    ]);
+    $fieldStorage->save();
+    $linkField = FieldConfig::create([
+      'field_storage' => $fieldStorage,
+      'bundle' => $content_type,
+      'settings' => [
+        'title' => DRUPAL_DISABLED,
+        'link_type' => LinkItemInterface::LINK_GENERIC,
+      ],
+    ]);
+    $linkField->save();
+    /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
+    $display_repository = \Drupal::service('entity_display.repository');
+    $display_repository->getFormDisplay('node', $content_type)
+      ->setComponent($field_name, [
+        'type' => 'link_default',
+      ])->save();
+    $display_repository->getViewDisplay('node', $content_type)
+      ->setComponent($field_name, [
+        'type' => 'link',
+      ])->save();
+
     $args = [
       'body' => [
         [
@@ -143,6 +184,11 @@ abstract class ScannerTestBase extends BrowserTestBase {
           'format' => filter_default_format(),
         ],
       ],
+      'link_field' => [
+        [
+          'uri' => 'https://example.com'
+        ],
+      ],
       'title' => $title,
       'type' => $content_type,
     ];
diff --git a/tests/src/Functional/SearchReplaceTest.php b/tests/src/Functional/SearchReplaceTest.php
index deaa511..db52b91 100644
--- a/tests/src/Functional/SearchReplaceTest.php
+++ b/tests/src/Functional/SearchReplaceTest.php
@@ -11,6 +11,8 @@ class SearchReplaceTest extends ScannerTestBase {
 
   /**
    * {@inheritdoc}
+   * @throws \Behat\Mink\Exception\ExpectationException
+   * @throws \Drupal\Core\Entity\EntityStorageException
    */
   protected function setUp(): void {
     // Make sure to complete the normal setup steps first.
@@ -32,11 +34,12 @@ class SearchReplaceTest extends ScannerTestBase {
     $this->submitForm($edit, 'Save configuration');
     $edit = [
       'fields_of_selected_content_type[node:scanner_test_node_type:body]' => 'node:scanner_test_node_type:body',
+      'fields_of_selected_content_type[node:scanner_test_node_type:link_field]' => 'node:scanner_test_node_type:link_field',
     ];
     $this->submitForm($edit, 'Save configuration');
     $this->assertSession()->statusCodeEquals(200);
 
-    // Log in as a user that can use the replace system.
+    // Log in as a user that can use the replacement system.
     $user = $this->createUser([
       // 'administer nodes',
       'perform search only',
@@ -46,13 +49,11 @@ class SearchReplaceTest extends ScannerTestBase {
   }
 
   /**
-   * Test the complete search & replace operation in one go.
+   * Test the search form.
+   *
+   * @throws \Behat\Mink\Exception\ExpectationException
    */
-  public function testSearchReplace(): void {
-    $this->drupalGet('node/1');
-    $this->assertSession()->statusCodeEquals(200);
-    $this->assertSession()->pageTextContains('Body test');
-
+  public function testSearchReplaceForm(): void {
     // Load the main scanner form.
     $this->drupalGet('admin/content/scanner');
     $session_assert = $this->assertSession();
@@ -69,8 +70,46 @@ class SearchReplaceTest extends ScannerTestBase {
     $session_assert->fieldExists('published');
     $session_assert->fieldExists('language');
 
+  }
+
+  /**
+   * Test the complete search & replace operation in one go.
+   *
+   * @throws \Behat\Mink\Exception\ExpectationException
+   */
+  public function testSearchReplaceBody(): void {
+    $this->searchAndReplace('Body test', 'scanner');
+  }
+
+  /**
+   * Test the complete search & replace operation for link fields.
+   *
+   * @throws \Behat\Mink\Exception\ExpectationException
+   */
+  public function testSearchReplaceLink(): void {
+    $this->searchAndReplace('https://example.com', 'https://exampleNew.com');
+  }
+
+  /**
+   * Re-usable function test search and replace.
+   *
+   * @param string $search
+   *   Text to search for.
+   * @param string $replace
+   *   Text to replace search text with.
+   *
+   * @throws \Behat\Mink\Exception\ResponseTextException
+   * @throws \Behat\Mink\Exception\ExpectationException
+   */
+  private function searchAndReplace(string $search, string $replace): void {
+    $this->drupalGet('node/1');
+    $this->assertSession()->statusCodeEquals(200);
+    $this->assertSession()->pageTextContains($search);
+
+    $this->drupalGet('admin/content/scanner');
+
     // Test the search operation.
-    $this->submitForm(['search' => 'Body test'], 'Search');
+    $this->submitForm(['search' => $search], 'Search');
     $this->assertSession()->statusCodeEquals(200);
     // Make sure no errors were reported.
     $this->assertSession()->pageTextNotContains('An error has occurred.');
@@ -82,25 +121,24 @@ class SearchReplaceTest extends ScannerTestBase {
     $this->assertSession()->pageTextContains('Found 0 matches in 0 entities.');
 
     // Test the replacement operation.
-    $this->submitForm(['search' => 'Body test', 'replace' => 'scanner'], 'Replace');
+    $this->submitForm(['search' => $search, 'replace' => $replace], 'Replace');
     $this->assertSession()->statusCodeEquals(200);
     $this->submitForm([], 'Confirm');
     $this->assertSession()->statusCodeEquals(200);
     $this->assertSession()->pageTextContains('1 entities processed.');
 
     // Verify that the string changed.
-    $this->submitForm(['search' => 'Body test'], 'Search');
+    $this->submitForm(['search' => $search], 'Search');
     $this->assertSession()->statusCodeEquals(200);
     $this->assertSession()->pageTextContains('Found 0 matches in 0 entities.');
-    $this->submitForm(['search' => 'scanner'], 'Search');
+    $this->submitForm(['search' => $replace], 'Search');
     $this->assertSession()->statusCodeEquals(200);
     $this->assertSession()->pageTextContains('Found 1 matches in 1 entities.');
 
     // Verify that the node's text has changed.
     $this->drupalGet('node/1');
     $this->assertSession()->statusCodeEquals(200);
-    $this->assertSession()->pageTextNotContains('Body test');
-    $this->assertSession()->pageTextContains('scanner');
+    $this->assertSession()->pageTextNotContains($search);
+    $this->assertSession()->pageTextContains($replace);
   }
-
 }
-- 
GitLab


From 44a73f6ecb0b0bfa243b4f55d3718626f9bb909f Mon Sep 17 00:00:00 2001
From: Stephen Mustgrave <smustgrave@gmail.com>
Date: Fri, 21 Mar 2025 16:49:50 -0400
Subject: [PATCH 2/4] Fix pipeline

---
 src/Form/ScannerAdminForm.php              |  2 +-
 src/Plugin/Scanner/Node.php                | 16 +++++++++++-----
 src/Plugin/Scanner/Paragraph.php           |  2 +-
 tests/src/Functional/ScannerAdminTest.php  |  1 +
 tests/src/Functional/ScannerTestBase.php   |  6 +++---
 tests/src/Functional/SearchReplaceTest.php |  2 ++
 6 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/Form/ScannerAdminForm.php b/src/Form/ScannerAdminForm.php
index 4855913..273bf20 100644
--- a/src/Form/ScannerAdminForm.php
+++ b/src/Form/ScannerAdminForm.php
@@ -279,7 +279,7 @@ class ScannerAdminForm extends ConfigFormBase {
         }
         $allowed_field_type = [
           // @todo Why no string_long?
-          'string', 'text_with_summary', 'text', 'text_long', 'link'
+          'string', 'text_with_summary', 'text', 'text_long', 'link',
         ];
         // We are only interested in certain field types.
         if (in_array($field_definition->getType(), $allowed_field_type, TRUE)) {
diff --git a/src/Plugin/Scanner/Node.php b/src/Plugin/Scanner/Node.php
index 4d940cb..0dcf973 100644
--- a/src/Plugin/Scanner/Node.php
+++ b/src/Plugin/Scanner/Node.php
@@ -204,7 +204,7 @@ class Node extends Entity {
                   $nodeField = $node->get($fieldname);
                 }
                 $new_value = [];
-                foreach($nodeField->getValue() as $delta => $field_value) {
+                foreach ($nodeField->getValue() as $delta => $field_value) {
                   foreach ($field_value as $field_element => $field_element_value) {
                     if (is_string($field_element_value)) {
                       $fieldValue = preg_replace($conditionVals['phpRegex'], $values['replace'], $field_element_value);
@@ -219,7 +219,10 @@ class Node extends Entity {
               }
               $data["node:$id"]['old_vid'] = $node->vid->getString();
               $node->setNewRevision(TRUE);
-              $node->revision_log = $this->t('Replaced %search with %replace via Scanner Search and Replace module.', ['%search' => $values['search'], '%replace' => $values['replace']]);
+              $node->revision_log = $this->t('Replaced %search with %replace via Scanner Search and Replace module.', [
+                '%search' => $values['search'],
+                '%replace' => $values['replace'],
+              ]);
             }
             else {
               $requested_lang = $values['language'];
@@ -229,7 +232,7 @@ class Node extends Entity {
                 $nodeField = $node->get($fieldname);
               }
               $new_value = [];
-              foreach($nodeField->getValue() as $delta => $field_value) {
+              foreach ($nodeField->getValue() as $delta => $field_value) {
                 foreach ($field_value as $field_element => $field_element_value) {
                   if (is_string($field_element_value)) {
                     $fieldValue = preg_replace($conditionVals['phpRegex'], $values['replace'], $field_element_value);
@@ -242,8 +245,11 @@ class Node extends Entity {
               }
               $node->$fieldname = $new_value;
               $data["node:$id"]['old_vid'] = $node->vid->getString();
-              $node->setNewRevision(TRUE);
-              $node->revision_log = $this->t('Replaced %search with %replace via Scanner Search and Replace module.', ['%search' => $values['search'], '%replace' => $values['replace']]);
+              $node->setNewRevision();
+              $node->revision_log = $this->t('Replaced %search with %replace via Scanner Search and Replace module.', [
+                '%search' => $values['search'],
+                '%replace' => $values['replace'],
+              ]);
             }
           }
           $node->save();
diff --git a/src/Plugin/Scanner/Paragraph.php b/src/Plugin/Scanner/Paragraph.php
index 0c90793..3162429 100644
--- a/src/Plugin/Scanner/Paragraph.php
+++ b/src/Plugin/Scanner/Paragraph.php
@@ -179,7 +179,7 @@ class Paragraph extends Entity {
         }
         elseif ($fieldType == 'link') {
           $new_value = [];
-          foreach($paraField->getValue() as $delta => $field_value) {
+          foreach ($paraField->getValue() as $delta => $field_value) {
             foreach ($field_value as $field_element => $field_element_value) {
               if (is_string($field_element_value)) {
                 $fieldValue = preg_replace($conditionVals['phpRegex'], $values['replace'], $field_element_value);
diff --git a/tests/src/Functional/ScannerAdminTest.php b/tests/src/Functional/ScannerAdminTest.php
index ab0f887..39a0668 100644
--- a/tests/src/Functional/ScannerAdminTest.php
+++ b/tests/src/Functional/ScannerAdminTest.php
@@ -11,6 +11,7 @@ class ScannerAdminTest extends ScannerTestBase {
 
   /**
    * {@inheritdoc}
+   *
    * @throws \Drupal\Core\Entity\EntityStorageException
    */
   protected function setUp(): void {
diff --git a/tests/src/Functional/ScannerTestBase.php b/tests/src/Functional/ScannerTestBase.php
index 4e1aba6..f736e3b 100644
--- a/tests/src/Functional/ScannerTestBase.php
+++ b/tests/src/Functional/ScannerTestBase.php
@@ -149,7 +149,7 @@ abstract class ScannerTestBase extends BrowserTestBase {
     ];
     $this->createContentType($args);
 
-    $field_name = 'link_field';
+    $field_name = $this->randomMachineName();
     // Create a field with settings to validate.
     $fieldStorage = FieldStorageConfig::create([
       'field_name' => $field_name,
@@ -184,9 +184,9 @@ abstract class ScannerTestBase extends BrowserTestBase {
           'format' => filter_default_format(),
         ],
       ],
-      'link_field' => [
+      $field_name => [
         [
-          'uri' => 'https://example.com'
+          'uri' => 'https://example.com',
         ],
       ],
       'title' => $title,
diff --git a/tests/src/Functional/SearchReplaceTest.php b/tests/src/Functional/SearchReplaceTest.php
index db52b91..0d793ff 100644
--- a/tests/src/Functional/SearchReplaceTest.php
+++ b/tests/src/Functional/SearchReplaceTest.php
@@ -11,6 +11,7 @@ class SearchReplaceTest extends ScannerTestBase {
 
   /**
    * {@inheritdoc}
+   *
    * @throws \Behat\Mink\Exception\ExpectationException
    * @throws \Drupal\Core\Entity\EntityStorageException
    */
@@ -141,4 +142,5 @@ class SearchReplaceTest extends ScannerTestBase {
     $this->assertSession()->pageTextNotContains($search);
     $this->assertSession()->pageTextContains($replace);
   }
+
 }
-- 
GitLab


From 2ba30c51cbce376b8dd22792ba1f5646205f9dfc Mon Sep 17 00:00:00 2001
From: Stephen Mustgrave <smustgrave@gmail.com>
Date: Fri, 21 Mar 2025 16:59:05 -0400
Subject: [PATCH 3/4] Test fixes

---
 tests/src/Functional/ScannerTestBase.php | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/tests/src/Functional/ScannerTestBase.php b/tests/src/Functional/ScannerTestBase.php
index f736e3b..13934e3 100644
--- a/tests/src/Functional/ScannerTestBase.php
+++ b/tests/src/Functional/ScannerTestBase.php
@@ -149,14 +149,17 @@ abstract class ScannerTestBase extends BrowserTestBase {
     ];
     $this->createContentType($args);
 
-    $field_name = $this->randomMachineName();
-    // Create a field with settings to validate.
-    $fieldStorage = FieldStorageConfig::create([
-      'field_name' => $field_name,
-      'entity_type' => 'node',
-      'type' => 'link',
-    ]);
-    $fieldStorage->save();
+    $fieldStorage = FieldStorageConfig::load('link_field');
+    $field_name = 'link_field';
+    if (is_null($fieldStorage)) {
+      // Create a field with settings to validate.
+      $fieldStorage = FieldStorageConfig::create([
+        'field_name' => $field_name,
+        'entity_type' => 'node',
+        'type' => 'link',
+      ]);
+      $fieldStorage->save();
+    }
     $linkField = FieldConfig::create([
       'field_storage' => $fieldStorage,
       'bundle' => $content_type,
-- 
GitLab


From 57a07e9508a3d811144f2b5063cdebee265f37b1 Mon Sep 17 00:00:00 2001
From: Stephen Mustgrave <smustgrave@gmail.com>
Date: Fri, 21 Mar 2025 16:59:50 -0400
Subject: [PATCH 4/4] Test fixes

---
 tests/src/Functional/ScannerTestBase.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/src/Functional/ScannerTestBase.php b/tests/src/Functional/ScannerTestBase.php
index 13934e3..57418a8 100644
--- a/tests/src/Functional/ScannerTestBase.php
+++ b/tests/src/Functional/ScannerTestBase.php
@@ -149,7 +149,7 @@ abstract class ScannerTestBase extends BrowserTestBase {
     ];
     $this->createContentType($args);
 
-    $fieldStorage = FieldStorageConfig::load('link_field');
+    $fieldStorage = FieldStorageConfig::load('node.link_field');
     $field_name = 'link_field';
     if (is_null($fieldStorage)) {
       // Create a field with settings to validate.
-- 
GitLab