Commit c76853c9 authored by Matroskeen's avatar Matroskeen Committed by heddn
Browse files

Allow currently processed/parsed URL to be read from data parser plugin.

parent 28396c4b
......@@ -181,6 +181,15 @@ abstract class DataParserPluginBase extends PluginBase implements DataParserPlug
return $this->currentItem;
}
/**
* {@inheritdoc}
*/
public function currentUrl(): ?string {
$index = $this->activeUrl ?: \array_key_first($this->urls);
return $this->urls[$index] ?? NULL;
}
/**
* {@inheritdoc}
*/
......
......@@ -12,4 +12,12 @@ namespace Drupal\migrate_plus;
*/
interface DataParserPluginInterface extends \Iterator, \Countable {
/**
* Returns current source URL.
*
* @return string|null
* The URL currently parsed on success, otherwise NULL.
*/
public function currentUrl(): ?string;
}
<?xml version="1.0" encoding="utf-8"?>
<items>
<item id="1">
<values title="Values">
<value>Value 1</value>
<value>Value 2</value>
</values>
</item>
<item id="2">
<values title="Values">
<value>Value 1 (single)</value>
</values>
</item>
</items>
<?xml version="1.0" encoding="utf-8"?>
<items>
<item id="3">
<values title="Values">
<value>Value 1</value>
<value>Value 2</value>
</values>
</item>
</items>
......@@ -86,6 +86,29 @@ class SimpleXmlTest extends KernelTestBase {
];
}
/**
* Tests current URL of parsed XML item.
*/
public function testCurrentUrl() {
$urls = [
$this->path . '/tests/data/simple_xml_current_url1.xml',
$this->path . '/tests/data/simple_xml_current_url2.xml',
];
$this->configuration['urls'] = $urls;
/** @var \Drupal\migrate_plus\DataParserPluginInterface $parser */
$parser = $this->pluginManager->createInstance('simple_xml', $this->configuration);
// First 2 items available in the first URL.
$parser->rewind();
$this->assertEquals($urls[0], $parser->currentUrl());
$parser->next();
$this->assertEquals($urls[0], $parser->currentUrl());
// Third item available in the second URL.
$parser->next();
$this->assertEquals($urls[1], $parser->currentUrl());
}
/**
* Tests reducing single values.
*/
......
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