3 namespace Drupal\migrate\Plugin\migrate\process;
5 use Drupal\migrate\ProcessPluginBase;
6 use Drupal\migrate\MigrateExecutableInterface;
7 use Drupal\migrate\Row;
8 use Drupal\migrate\MigrateSkipRowException;
11 * Skips processing the current row when a source value is not set.
13 * The skip_row_if_not_set process plugin checks whether a value is set. If the
14 * value is set, it is returned. Otherwise, a MigrateSkipRowException
17 * Available configuration keys:
18 * - index: The source property to check for.
19 * - message: (optional) A message to be logged in the {migrate_message_*} table
20 * for this row. If not set, nothing is logged in the message table.
27 * # Check if the "contact" key exists in the "data" array.
28 * plugin: skip_row_if_not_set
31 * message: "Missed the 'data' key"
34 * This will return $data['contact'] if it exists. Otherwise, the row will be
35 * skipped and the message "Missed the 'data' key" will be logged in the
38 * @see \Drupal\migrate\Plugin\MigrateProcessInterface
40 * @MigrateProcessPlugin(
41 * id = "skip_row_if_not_set",
42 * handle_multiples = TRUE
45 class SkipRowIfNotSet extends ProcessPluginBase {
50 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
51 if (!isset($value[$this->configuration['index']])) {
52 $message = !empty($this->configuration['message']) ? $this->configuration['message'] : '';
53 throw new MigrateSkipRowException($message);
55 return $value[$this->configuration['index']];