function hook_migrate_prepare_row

Same name and namespace in other branches
  1. 9 core/modules/migrate/migrate.api.php \hook_migrate_prepare_row()
  2. 8.9.x core/modules/migrate/migrate.api.php \hook_migrate_prepare_row()
  3. 10 core/modules/migrate/migrate.api.php \hook_migrate_prepare_row()

Allows adding data to a row before processing it.

For example, filter module used to store filter format settings in the variables table which now needs to be inside the filter format config file. So, it needs to be added here.

hook_migrate_MIGRATION_ID_prepare_row() is also available.

Parameters

\Drupal\migrate\Row $row: The row being imported.

\Drupal\migrate\Plugin\MigrateSourceInterface $source: The source migration.

\Drupal\migrate\Plugin\MigrationInterface $migration: The current migration.

Related topics

3 functions implement hook_migrate_prepare_row()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

forum_migrate_prepare_row in core/modules/forum/forum.module
Implements hook_migrate_prepare_row().
migrate_prepare_row_test_migrate_prepare_row in core/modules/migrate/tests/modules/migrate_prepare_row_test/migrate_prepare_row_test.module
Implements hook_migrate_prepare_row().
migrate_skip_all_rows_test_migrate_prepare_row in core/modules/migrate/tests/modules/migrate_skip_all_rows_test/migrate_skip_all_rows_test.module
Implements hook_migrate_prepare_row().
1 invocation of hook_migrate_prepare_row()
SourcePluginBase::prepareRow in core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php
Adds additional data to the row.

File

core/modules/migrate/migrate.api.php, line 155

Code

function hook_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) {
    if ($migration->id() == 'd6_filter_formats') {
        $value = $source->getDatabase()
            ->query('SELECT [value] FROM {variable} WHERE [name] = :name', [
            ':name' => 'my_module_filter_foo_' . $row->getSourceProperty('format'),
        ])
            ->fetchField();
        if ($value) {
            $row->setSourceProperty('settings:my_module:foo', unserialize($value));
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.