Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
migrate_plus
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
migrate_plus
Commits
5a2ee566
Commit
5a2ee566
authored
1 month ago
by
Marco Villegas
Committed by
Lucas Hedding
1 month ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3427939
by marvil07, heddn: Replace text content mode for dom_str_replace
parent
a70a881d
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!90
Add text mode to dom_str_replace migrate process plugin
Pipeline
#541356
canceled
1 month ago
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Plugin/migrate/process/DomStrReplace.php
+18
-1
18 additions, 1 deletion
src/Plugin/migrate/process/DomStrReplace.php
tests/src/Unit/process/DomStrReplaceTest.php
+13
-3
13 additions, 3 deletions
tests/src/Unit/process/DomStrReplaceTest.php
with
31 additions
and
4 deletions
src/Plugin/migrate/process/DomStrReplace.php
+
18
−
1
View file @
5a2ee566
...
...
@@ -19,6 +19,7 @@ use Drupal\migrate\Row;
* - mode: What to modify. Possible values:
* - attribute: One element attribute.
* - element: An element name.
* - text: The element text content.
* - xpath: XPath query expression that will produce the \DOMNodeList to walk.
* - attribute_options: A map of options related to the attribute mode. Required
* when mode is attribute. The keys can be:
...
...
@@ -70,6 +71,12 @@ use Drupal\migrate\Row;
* search: '/foo-(\d+)/'
* replace: 'bar-$1'
* -
* plugin: dom_str_replace
* mode: text
* xpath: '//a'
* search: 'Find more information here'
* replace: 'More information'
* -
* plugin: dom
* method: export
* @endcode
...
...
@@ -96,6 +103,7 @@ class DomStrReplace extends DomProcessBase {
'attribute_options'
=>
NULL
,
],
'element'
=>
[],
'text'
=>
[],
],
'search'
=>
NULL
,
'replace'
=>
NULL
,
...
...
@@ -218,6 +226,9 @@ class DomStrReplace extends DomProcessBase {
case
'element'
:
return
$node
->
nodeName
;
case
'text'
:
return
$node
->
textContent
;
}
}
...
...
@@ -231,6 +242,7 @@ class DomStrReplace extends DomProcessBase {
switch
(
$this
->
configuration
[
'mode'
])
{
case
'attribute'
:
case
'element'
:
case
'text'
:
return
$this
->
configuration
[
'search'
];
}
}
...
...
@@ -245,6 +257,7 @@ class DomStrReplace extends DomProcessBase {
switch
(
$this
->
configuration
[
'mode'
])
{
case
'attribute'
:
case
'element'
:
case
'text'
:
return
$this
->
configuration
[
'replace'
];
}
}
...
...
@@ -299,6 +312,10 @@ class DomStrReplace extends DomProcessBase {
}
$html_node
->
parentNode
->
replaceChild
(
$new_node
,
$html_node
);
break
;
case
'text'
:
$html_node
->
textContent
=
$new_subject
;
break
;
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/src/Unit/process/DomStrReplaceTest.php
+
13
−
3
View file @
5a2ee566
...
...
@@ -6,9 +6,9 @@ namespace Drupal\Tests\migrate_plus\Unit\process;
use
Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
;
use
Drupal\Component\Utility\Html
;
use
Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
;
use
Drupal\migrate\MigrateSkipRowException
;
use
Drupal\migrate_plus
\Plugin\migrate\process\DomStrReplace
;
use
Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
;
/**
* Tests the dom_str_replace process plugin.
...
...
@@ -62,7 +62,7 @@ final class DomStrReplaceTest extends MigrateProcessTestCase {
],
'mode-invalid'
=>
[
[
'mode'
=>
'invalid'
],
'Configuration option "mode" only accepts the following values: attribute, element.'
,
'Configuration option "mode" only accepts the following values: attribute, element
, text
.'
,
],
'attribute_options-null'
=>
[
[
'attribute_options'
=>
NULL
],
...
...
@@ -139,6 +139,16 @@ final class DomStrReplaceTest extends MigrateProcessTestCase {
]
+
self
::
$exampleConfiguration
,
'<a href="/fbar/Fbar/fbar">text</a>'
,
],
'mode-text'
=>
[
'<a href="/foo/Foo/foo">foo</a>'
,
[
'mode'
=>
'text'
,
'xpath'
=>
'//a'
,
'search'
=>
'foo'
,
'replace'
=>
'bar'
,
],
'<a href="/foo/Foo/foo">bar</a>'
,
],
];
return
$cases
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment