Loading src/Plugin/ConditionBase.php +25 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,13 @@ abstract class ConditionBase extends PluginBase implements ConditionInterface { */ protected $negated; /** * Properties to override the source value passed to evaluate(). * * @var string|string[] */ protected $source; /** * {@inheritdoc} */ Loading @@ -32,6 +39,7 @@ abstract class ConditionBase extends PluginBase implements ConditionInterface { } } $this->negated = $configuration['negate'] ?? FALSE; $this->source = $configuration['source'] ?? NULL; parent::__construct($configuration, $plugin_id, $plugin_definition); } Loading @@ -39,6 +47,9 @@ abstract class ConditionBase extends PluginBase implements ConditionInterface { * {@inheritdoc} */ public function evaluate($source, Row $row) { if ($this->source) { $source = $this->getSource($row); } return ($this->doEvaluate($source, $row) xor $this->negated); } Loading @@ -55,4 +66,18 @@ abstract class ConditionBase extends PluginBase implements ConditionInterface { */ abstract protected function doEvaluate($source, Row $row); /** * {@inheritdoc} */ protected function getSource(Row $row) { if (is_string($this->source)) { return $row->get($this->source); } $return = []; foreach ($this->source as $property) { $return[] = $row->get($property); } return $return; } } src/Plugin/LogicalConditionBase.php +3 −0 Original line number Diff line number Diff line Loading @@ -95,6 +95,9 @@ abstract class LogicalConditionBase extends ConditionBase implements ContainerFa * {@inheritdoc} */ public function evaluate($source, Row $row) { if ($this->source) { $source = $this->getSource($row); } if ($this->iterate && !is_array($source)) { throw new MigrateException("If the 'iterate' property is true, the source must be an array."); } Loading src/Plugin/migrate_conditions/condition/AllElements.php +4 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,10 @@ use Drupal\migrate_conditions\Plugin\ArrayConditionBase; * - negate: (optional) Whether to negate the all_elements condition. * Defaults to FALSE. You can also negate the 'all_elements' plugin by using * 'not:all_elements' as the plugin id. * - source: (optional) Property or array of properties on which to evaluate * the condition. If not set, the condition will be evaluated on the source * passed to the ::evaluate() method, typically the source of the process * plugin that is using this condition. * * Example: * Loading src/Plugin/migrate_conditions/condition/AndCondition.php +25 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,10 @@ use Drupal\migrate_conditions\Plugin\LogicalConditionBase; * - negate: (optional) Whether the 'and' condition should be negated. * Defaults to FALSE. You can also negate the 'and' plugin by using * 'not:and' as the plugin id. * - source: (optional) Property or array of properties on which to evaluate * the condition. If not set, the condition will be evaluated on the source * passed to the ::evaluate() method, typically the source of the process * plugin that is using this condition. * * Examples: * Loading Loading @@ -92,6 +96,27 @@ use Drupal\migrate_conditions\Plugin\LogicalConditionBase; * value: 'in charge' * @endcode * * The previous example is likely clearer if we configure the source * of each condition separately, rather than relying on the source * passed to the process plugin. * * @code * process: * large_and_in_charge: * plugin: evaluate_condition * condition: * plugin: and * conditions: * - * plugin: equals * value: 'large' * source: source_size * - * plugin: equals * value: 'in charge' * source: source_comportment * @endcode * * @MigrateConditionsConditionPlugin( * id = "and", * required = {"conditions"} Loading src/Plugin/migrate_conditions/condition/Callback.php +4 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,10 @@ use Drupal\migrate_conditions\Plugin\ConditionBase; * - negate: (optional) Whether the result of the callable function should be * negated. Defaults to FALSE. You can also negate the result of the * callable function by using 'not:callback' as the plugin id. * - source: (optional) Property or array of properties on which to evaluate * the condition. If not set, the condition will be evaluated on the source * passed to the ::evaluate() method, typically the source of the process * plugin that is using this condition. * * Examples: * Loading Loading
src/Plugin/ConditionBase.php +25 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,13 @@ abstract class ConditionBase extends PluginBase implements ConditionInterface { */ protected $negated; /** * Properties to override the source value passed to evaluate(). * * @var string|string[] */ protected $source; /** * {@inheritdoc} */ Loading @@ -32,6 +39,7 @@ abstract class ConditionBase extends PluginBase implements ConditionInterface { } } $this->negated = $configuration['negate'] ?? FALSE; $this->source = $configuration['source'] ?? NULL; parent::__construct($configuration, $plugin_id, $plugin_definition); } Loading @@ -39,6 +47,9 @@ abstract class ConditionBase extends PluginBase implements ConditionInterface { * {@inheritdoc} */ public function evaluate($source, Row $row) { if ($this->source) { $source = $this->getSource($row); } return ($this->doEvaluate($source, $row) xor $this->negated); } Loading @@ -55,4 +66,18 @@ abstract class ConditionBase extends PluginBase implements ConditionInterface { */ abstract protected function doEvaluate($source, Row $row); /** * {@inheritdoc} */ protected function getSource(Row $row) { if (is_string($this->source)) { return $row->get($this->source); } $return = []; foreach ($this->source as $property) { $return[] = $row->get($property); } return $return; } }
src/Plugin/LogicalConditionBase.php +3 −0 Original line number Diff line number Diff line Loading @@ -95,6 +95,9 @@ abstract class LogicalConditionBase extends ConditionBase implements ContainerFa * {@inheritdoc} */ public function evaluate($source, Row $row) { if ($this->source) { $source = $this->getSource($row); } if ($this->iterate && !is_array($source)) { throw new MigrateException("If the 'iterate' property is true, the source must be an array."); } Loading
src/Plugin/migrate_conditions/condition/AllElements.php +4 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,10 @@ use Drupal\migrate_conditions\Plugin\ArrayConditionBase; * - negate: (optional) Whether to negate the all_elements condition. * Defaults to FALSE. You can also negate the 'all_elements' plugin by using * 'not:all_elements' as the plugin id. * - source: (optional) Property or array of properties on which to evaluate * the condition. If not set, the condition will be evaluated on the source * passed to the ::evaluate() method, typically the source of the process * plugin that is using this condition. * * Example: * Loading
src/Plugin/migrate_conditions/condition/AndCondition.php +25 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,10 @@ use Drupal\migrate_conditions\Plugin\LogicalConditionBase; * - negate: (optional) Whether the 'and' condition should be negated. * Defaults to FALSE. You can also negate the 'and' plugin by using * 'not:and' as the plugin id. * - source: (optional) Property or array of properties on which to evaluate * the condition. If not set, the condition will be evaluated on the source * passed to the ::evaluate() method, typically the source of the process * plugin that is using this condition. * * Examples: * Loading Loading @@ -92,6 +96,27 @@ use Drupal\migrate_conditions\Plugin\LogicalConditionBase; * value: 'in charge' * @endcode * * The previous example is likely clearer if we configure the source * of each condition separately, rather than relying on the source * passed to the process plugin. * * @code * process: * large_and_in_charge: * plugin: evaluate_condition * condition: * plugin: and * conditions: * - * plugin: equals * value: 'large' * source: source_size * - * plugin: equals * value: 'in charge' * source: source_comportment * @endcode * * @MigrateConditionsConditionPlugin( * id = "and", * required = {"conditions"} Loading
src/Plugin/migrate_conditions/condition/Callback.php +4 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,10 @@ use Drupal\migrate_conditions\Plugin\ConditionBase; * - negate: (optional) Whether the result of the callable function should be * negated. Defaults to FALSE. You can also negate the result of the * callable function by using 'not:callback' as the plugin id. * - source: (optional) Property or array of properties on which to evaluate * the condition. If not set, the condition will be evaluated on the source * passed to the ::evaluate() method, typically the source of the process * plugin that is using this condition. * * Examples: * Loading