Components
- Code
- Documentation
- Miscellaneous
- User interface
Documentation
Licence
http://www.gnu.org/licenses/old-licenses/gpl-2.0.htmlpermet d'obtenir des plugins de conditions et de comparaisons pour configurer les migrations via les fichiers de configurations YML.
Release
Covered by Drupal's security advisory policy
Release type : New features
Covered by Drupal's security advisory policy
Release type : New features
Covered by Drupal's security advisory policy
Release type : New features
Beta releases are not covered by Drupal security advisories.
Description
Overview
Add logic to your process pipeline with Migrate Conditions.
This project provides a framework of condition plugins exclusively for use with the Migrate API. The module then provides a number of process plugins that can leverage the conditions. Please note that any of these process plugins and be used with any of the condition plugins.
Process plugins
- skip_on_condition
- evaluate_condition
- if_condition
- first_meeting_condition
- filter_on_condition
- switch_on_condition
- stop_on_condition
This project began as an ambitious solution to #3259591: Add generic Skip migrate process plugin with various operations.
Please see the Documentation for examples and details.
Similar Modules
You may not need Migrate Conditions. Drupal core provides several plugins that might solve your problem:
And Migrate Plus offers the skip_on_value process plugin.
If those plugins solve your problem, you might as well use them instead of adding Migrate Conditions to your codebase.
Requirements
Core migrate module.
Recommended modules
Migrate Condition plugins
There are three rough categories of condition plugins included. Please note that any of these condition plugins and be used with any of the process plugins listed above.
"Primary" Condition Plugins
These are the ones you will use the most. They do not require any other condition plugins to work.
- callback
- contains
- default
- empty
- entity_exists
- equals
- greater_than
- http_status
- in_array
- in_migrate_map
- is_null
- is_stub
- isset
- less_than
- matches
- older_than
"Logical" Condition Plugins
These conditions allow the primary conditions to be composed (that is, AND-ed and OR-ed)
"Array-Handling" Condition Plugins
These conditions allow another condition to be evaluated on each element of an array.
Examples
Seriously, see the Documentation for many more examples and details.
1. Skip a row is a certain source value is NOT empty.
@see skip_on_condition, empty
process:
skip_on_not_empty:
plugin: skip_on_condition
condition:
plugin: empty
negate: true
method: (row/process)
source: my_source
Or negation can be done more concisely by prefixing the condition plugin id with not:
:
process:
skip_on_not_empty:
plugin: skip_on_condition
condition: not:empty
method: (row/process)
source: my_source
Since the not:empty
condition does not require any further configuration, we were able to simply pass the plugin id as the condition.
Whether you negate a condition using not:
or by setting negate: true
is a matter of personal preference. For conditions plugins that require no additional configuration (like empty
or is_null
) it's much more concise to use the not:
prefix.
Beginning with v2.1.0, we can alternatively specify the source
directly on the condition. Thus the previous example could be written as:
process:
skip_on_not_empty:
plugin: skip_on_condition
condition:
plugin: not:empty
source: my_source
method: (row/process)
Specifying the source
on the condition is not especially useful in this case, but in other cases it may come in handy.
2. Filter old dates out of a source array of timestamps. That is, keep dates that are not older than now.
@see filter_on_condition, older_than
process:
future_timestamps:
plugin: filter_on_condition
source: source_array_of_timestamps
condition:
plugin: older_than
negate: true
format: 'U'
value: now
3. Set a boolean to true if a source_age is between 13 (inclusive) and 20 (not inclusive).
@see evaluate_condition, and, less_than
process:
is_a_teenager:
plugin: evaluate_condition
source: my_source_age
condition:
plugin: and
conditions:
-
plugin: not:less_than
value: 13
-
plugin: less_than
value 20
Some conditions support parens to pass a value. The example above is written more succinctly below.
process:
is_a_teenager:
plugin: evaluate_condition
source: my_source_age
condition:
plugin: and
conditions:
- plugin: not:less_than(13)
- plugin: less_than(20)
4. Use source_value_backup if source_value is empty, This is a powerful alternative to default_value
.
@see if_condition, empty
process:
destination_value:
plugin: if_condition
source: source_value
condition: empty
do_get: source_value_backup
else_get: source_value
or equivalently
process:
destination_value:
plugin: if_condition
source: source_value
condition: not:empty
else_get: source_value_backup
5. Return the first source value that is not empty, like an "empty coalesce" plugin would.
@see first_meeting_condition, empty
process:
some_not_empty_value:
plugin: first_meeting_condition
condition: not:empty
source:
- something
- another
- you_get_the_idea
6. Determine whether a number is negative, positive, or zero.
@see switch_on_condition, less_than, equals, default
process:
sign_string:
plugin: switch_on_condition
source: my_source_number
cases:
-
condition: less_than(0)
default_value: negative
-
condition: equals(0)
default_value: zero
-
condition: default
default_value: positive
The use of parens notation, shown above, can make the yaml very simple.
7. Provide a random value as a fallback if my_source_number is empty.
@see stop_on_condition
field_number:
-
plugin: stop_on_condition
condition: not:empty
source: my_source_number
-
plugin: callback
callable: rand
unpack_source: true
source: []
Toutes les informations proviennent du site drupal.org