Commit 5a03edbb authored by alexpott's avatar alexpott

Issue #2511632 by neclimdul: Add ability to provide default for Extract process plugin

parent 2fbb1a03
......@@ -18,6 +18,7 @@ process:
- 0
- attributes
- title
default: ''
menu_name:
plugin: migration
migration: d6_menu
......
......@@ -76,6 +76,17 @@ public function testMenuLinks() {
$this->assertIdentical(['attributes' => ['title' => '']], $menu_link->link->options);
$this->assertIdentical('https://www.drupal.org', $menu_link->link->uri);
$this->assertIdentical(0, $menu_link->getWeight());
// assert that missing title attributes don't stop or break migration.
$menu_link = entity_load('menu_link_content', 393);
$this->assertIdentical('Test 3', $menu_link->getTitle());
$this->assertIdentical('secondary-links', $menu_link->getMenuName());
$this->assertIdentical('', $menu_link->getDescription());
$this->assertIdentical(TRUE, $menu_link->isEnabled());
$this->assertIdentical(FALSE, $menu_link->isExpanded());
$this->assertIdentical([], $menu_link->link->options);
$this->assertIdentical('internal:/user/login', $menu_link->link->uri);
$this->assertIdentical(15, $menu_link->getWeight());
}
}
......@@ -33,7 +33,12 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
}
$new_value = NestedArray::getValue($value, $this->configuration['index'], $key_exists);
if (!$key_exists) {
throw new MigrateException('Array index missing, extraction failed.');
if (isset($this->configuration['default'])) {
$new_value = $this->configuration['default'];
}
else {
throw new MigrateException('Array index missing, extraction failed.');
}
}
return $new_value;
}
......
......@@ -51,4 +51,13 @@ public function testExtractFail() {
$this->plugin->transform(array('bar' => 'foo'), $this->migrateExecutable, $this->row, 'destinationproperty');
}
/**
* Tests unsuccessful extraction.
*/
public function testExtractFailDefault() {
$plugin = new Extract(['index' => ['foo'], 'default' => 'test'], 'map', []);
$value = $plugin->transform(['bar' => 'foo'], $this->migrateExecutable, $this->row, 'destinationproperty');
$this->assertSame($value, 'test', '');
}
}
......@@ -5154,8 +5154,34 @@ public function load() {
'p8' => '0',
'p9' => '0',
'updated' => '0',
))->values(array(
'menu_name' => 'secondary-links',
'mlid' => '393',
'plid' => '0',
'link_path' => 'user/login',
'router_path' => 'user/login',
'link_title' => 'Test 3',
'options' => 'a:0:{}',
'module' => 'menu',
'hidden' => '0',
'external' => '0',
'has_children' => '1',
'expanded' => '0',
'weight' => '15',
'depth' => '1',
'customized' => '1',
'p1' => '138',
'p2' => '0',
'p3' => '0',
'p4' => '0',
'p5' => '0',
'p6' => '0',
'p7' => '0',
'p8' => '0',
'p9' => '0',
'updated' => '0',
))->execute();
}
}
#a594b05a60a1a549e86f4c190c2f2f4e
#8e902b6a6367838c553b463060befdd3
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment