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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
migrate_plus
Commits
9de72b01
Commit
9de72b01
authored
3 years ago
by
Ivan Doroshenko
Committed by
Ivan Doroshenko
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3225569
: Improve str_replace documentation.
parent
ac90c7fd
No related branches found
No related tags found
1 merge request
!47
Issue #3225569: Improve str_replace documentation.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/migrate/process/StrReplace.php
+36
-34
36 additions, 34 deletions
src/Plugin/migrate/process/StrReplace.php
with
36 additions
and
34 deletions
src/Plugin/migrate/process/StrReplace.php
+
36
−
34
View file @
9de72b01
...
...
@@ -8,58 +8,60 @@ use Drupal\migrate\ProcessPluginBase;
use
Drupal\migrate\Row
;
/**
* Uses the str_replace()
method
on a source string.
* Uses
ei
the
r
str_replace()
or preg_replace() function
on a source string.
*
* @MigrateProcessPlugin(
* id = "str_replace"
* )
* Available configuration keys:
* - search: The value or pattern being searched for. It can be either a string
* or an array with strings.
* - replace: The replacement value that replaces found search values. It can be
* either a string or an array with strings.
* - regex: (optional) If not empty, then preg_replace() function will be used
* instead of str_replace(). Defaults to FALSE.
* - case_insensitive: (optional) If not empty, then str_ireplace() function
* will be used instead of str_replace(). Defaults to FALSE. Ignored if
* 'regex' is enabled.
*
* @codingStandardsIgnoreStart
* Depending on the value of 'regex', the rules for
* @link http://php.net/manual/function.str-replace.php str_replace @endlink
* or
* @link http://php.net/manual/function.preg-replace.php preg_replace @endlink
* apply. This means that you can provide arrays as values, your replace string
* can include backreferences, etc.
*
* To do a simple hardcoded string replace, use the following:
* @code
* field_text:
* plugin: str_replace
* source: text
* search:
foo
* replace:
bar
* search:
et
* replace:
that
* @endcode
* If the value of text is "vero eos et accusam et justo vero" in source, foo is
* "et" in search and bar is "that" in replace, field_text will be "vero eos
* that accusam that justo vero".
* If the value of text is "vero eos et accusam et justo vero" in source,
* field_text will be "vero eos that accusam that justo vero".
*
* Case
insensitive searches can be achieved using the following:
* Case
-
insensitive searches can be achieved using the following:
* @code
* field_text:
* plugin: str_replace
* case_insensitive: true
* source: text
* search:
fo
o
* replace:
bar
* search:
ver
o
* replace:
that
* @endcode
* If the value of text is "VERO eos et accusam et justo vero" in source, foo is
* "vero" in search and bar is "that" in replace, field_text will be "that eos
* et accusam et justo that".
* If the value of text is "VERO eos et accusam et justo vero" in source,
* field_text will be "that eos et accusam et justo that".
*
* Also regular expressions can be matched using:
* Also
,
regular expressions can be matched using:
* @code
* field_text:
* plugin: str_replace
* regex: true
* source: text
* search:
foo
* replace:
bar
* search:
/[0-9]{3}/
* replace:
the
* @endcode
* If the value of text is "vero eos et 123 accusam et justo 123 duo" in source,
* foo is "/[0-9]{3}/" in search and bar is "the" in replace, field_text will be
* "vero eos et the accusam et justo the duo".
*
* Depending on the value of 'regex', the rules for
* @link http://php.net/manual/function.str-replace.php str_replace @endlink
* or
* @link http://php.net/manual/function.preg-replace.php preg_replace @endlink
* apply. This means that you can provide arrays as values, your replace string
* can include backreferences, etc.
* field_text will be "vero eos et the accusam et justo the duo".
*
* Multiple values can be matched like this:
* @code
...
...
@@ -76,14 +78,14 @@ use Drupal\migrate\Row;
* plugin: str_replace
* regex: true
* source: text
* search:
foo
* replace:
bar
* search:
/@(\S+)/
* replace:
$1
* @endcode
* If the value of text is "@username" in source,
* foo is "/@(\S+)/" in search and bar is "$1" in replace, field_text will be
* "username".
* If the value of text is "@username" in source, field_text will be "username".
*
* @codingStandardsIgnoreEnd
* @MigrateProcessPlugin(
* id = "str_replace"
* )
*/
class
StrReplace
extends
ProcessPluginBase
{
...
...
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