Skip to content
Snippets Groups Projects

Add text mode to dom_str_replace migrate process plugin

Files
2
<?php
declare(strict_types = 1);
declare(strict_types=1);
namespace Drupal\migrate_plus\Plugin\migrate\process;
@@ -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;
}
}
Loading