- Issue created by @amaisano
- πΊπΈUnited States danflanagan8 St. Louis, US
Great idea, @amaisano
For some reason, `matches` doesn't have the `property` configuration key that many condition plugins have (like `equals`, `greater_than`, etc.). I think the goal of this issue should be to add that same functionality to `matches`.
For BC reasons, I don't think we can change the "parens" behavior in the module. However, once `property` is supported within `matches`, a hook_plugin_info_alter should allow you to change the `parens` setting in the `matches` annotation to be `property`.
There's also some validation we'd have to change. And the `regex` key would no longer be required.
I can't recall exactly why I didn't make the `matches` plugin extend the SimpleComparisonBase class. Maybe that would have been better.
Anyway, we can definitely expand configuration options here but have to be careful to maintain BC.
- Issue was unassigned.
- πΊπΈUnited States amaisano Boston
Found a quick, custom plugin based solution thanks to author's help:
namespace Drupal\sw_migrate\Plugin\migrate_conditions\condition; use Drupal\migrate\MigrateException; use Drupal\migrate_conditions\Plugin\SimpleComparisonBase; /** * Alternate to migrate_conditions matches condition. * * Allows dynamic regex to be passed into regex() operator * via source and/or _pseudo_field properties. * * @MigrateConditionsConditionPlugin( * id = "regex", * parens = "property" * ) */ class Regex extends SimpleComparisonBase { /** * {@inheritdoc} */ protected function compare($source, $value) { if (is_string($source) && !is_null($value)) { $regex = '/' . $value . '/'; return (bool) preg_match($regex, $source); } else { throw new MigrateException('When using the regex condition, the source must be a string.'); } } }