New process plugins
Starting with Migrate Plus 8x-5.2, there are several new process plugins.
dom_removedom_selectentity_valuegateservicetranspose
dom_remove
Remove nodes from a DOMDocument object by specifying an XPath selector.
For example, to remove the first three <img> elements from an HTML string:
process:
bar:
-
plugin: dom
method: import
source: text_field
-
plugin: dom_remove
selector: //img
limit: 3
-
plugin: dom
method: export
The limit key is optional. If you leave it off, then dom_remove removes all elements matching the XPath selector.
dom_select
Select text elements from a DOMDocument object by specifying an XPath selector.
For example, to select (i.e. return) the src attributes from the first three <img> elements:
process:
bar:
-
plugin: dom
method: import
source: text_field
-
plugin: dom_select
selector: //img/@src
limit: 3
The limit key is optional. If you leave it off, then dom_select selects all elements matching the XPath selector.
entity_value
Extract a specified field value from an entity.
The source value should be an entity ID. The type of the entity and the field name must be specified.
For content entities, if a langcode is given, that translation is loaded.
Example:
process:
field_foo:
plugin: entity_value
source: field_noderef/0/target_id
entity_type: node
langcode: en
field_name: field_foo
gate
Allow a source value to pass through the "gate" conditionally.
This is similar to skip_on_value, but the value (if not skipped) can be different from the "key" being tested.
Example:
Migrate an email address if an opt_in field is set.
process:
field_email:
plugin: gate
source: email
use_as_key: opt_in
valid_keys: TRUE
key_direction: unlock
The valid_keys can be a single value or an array of values. The key_direction can be lock or unlock.
service
This is similar to the callback plugin. Instead of supplying a callable, specify a service and a method:
process:
filemime:
plugin: service
service: file.mime_type.guesser
method: guessMimeType
source: filename
All options for the callback plugin can be used, except for callable, which will be ignored.
Since Drupal 9.2.0, it is possible to supply multiple arguments using the unpack_source property. See: https://www.drupal.org/node/3205079
transpose
Thinking of an array of arrays as a two-dimentional matrix, swap rows and columns.
In other words, the result is again an array of arrays. The first element contains the first element of all the input arrays, and so on.
Example:
Create full names from separate arrays of first and last names.
process:
full_names:
-
plugin: transpose
source:
- first_names
- last_names
This will create an array of 2-element, numerically indexed arrays where index 0 contains the first name and index 1 contains the last name.