Would be nice to have a way to filter import rows based on a string in a field. I'm doing this for one of my projects already. Would this be useful to the community?

/**
* Filters rows based on a string. If the string is not present, returns FALSE and
* skips the row
*
* @MigrateProcessPlugin(
* id = "string_filter",
*
*)
*/
class StringFilter extends ProcessPluginBase {
/**
* {@inheritdoc}
*/

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$string = isset($this->configuration['string']) ? $this->configuration['string'] : '';
if (!empty($value)) {
if(strpos($value, $string) !== FALSE) {
return $value;
}
else {
throw new MigrateSkipRowException();
}
}
}
}

Comments

brooke_heaton created an issue. See original summary.

mikeryan’s picture

Status: Needs work » Active

Yes, that would be useful. It'd be good to have a configuration option to choose whether to include or to exclude items matching the provided string.

heddn’s picture

Assigned: brooke_heaton » Unassigned
Status: Active » Closed (duplicate)

This sure seems like a duplicate of #2711949: Migrate Skip on Value (or non Value).

brooke_heaton’s picture

Yes, this may likely be a duplicate. My specific need was to be exclusive and only migrate rows that match a specific value, rather than exclude. Assuming Skip on Value (or non Value) skips on non-value, then we're talking about the same thing. Great to see that addition!