function RowTest::preventFieldRemoval
The pre-row-save event handler for the second migration.
Checks row destinations and prevents the removal of the second field.
Parameters
\Drupal\migrate\Event\MigratePreRowSaveEvent $event: The migration event.
string $name: The event name.
File
-
core/
modules/ migrate/ tests/ src/ Kernel/ RowTest.php, line 128
Class
- RowTest
- Tests the Row class.
Namespace
Drupal\Tests\migrate\KernelCode
public function preventFieldRemoval(MigratePreRowSaveEvent $event, string $name) : void {
$row = $event->getRow();
// Both fields are empty and their existing values will be removed.
$this->assertFalse($row->hasDestinationProperty('field1'));
$this->assertFalse($row->hasDestinationProperty('field2'));
$this->assertTrue($row->hasEmptyDestinationProperty('field1'));
$this->assertTrue($row->hasEmptyDestinationProperty('field2'));
// Prevent removal of field 2.
$row->removeEmptyDestinationProperty('field2');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.