Skip to content
Snippets Groups Projects
Unverified Commit 510b5904 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3064016 by Matroskeen, alisonjo315, danflanagan8, quietone: Allow...

Issue #3064016 by Matroskeen, alisonjo315, danflanagan8, quietone: Allow menu_link source plugin to filter menu links by menu name(s)
parent 76f6b690
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,35 @@
/**
* Drupal menu link source from database.
*
* Available configuration keys:
* - menu_name: (optional) The menu name(s) to filter menu links from the source
* can be a string or an array. If not declared then menu links of all menus
* are retrieved.
*
* Examples:
*
* @code
* source:
* plugin: menu_link
* menu_name: main-menu
* @endcode
*
* In this example menu links of main-menu are retrieved from the source
* database.
*
* @code
* source:
* plugin: menu_link
* menu_name: [main-menu, navigation]
* @endcode
*
* In this example menu links of main-menu and navigation menus are retrieved
* from the source database.
*
* For additional configuration keys, refer to the parent classes:
* @see \Drupal\migrate\Plugin\migrate\source\SqlBase
* @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
*
* @MigrateSource(
* id = "menu_link",
* source_module = "menu"
......@@ -29,6 +58,9 @@ public function query() {
->condition('ml.customized', 1)
->condition($and);
$query->condition($condition);
if (isset($this->configuration['menu_name'])) {
$query->condition('ml.menu_name', (array) $this->configuration['menu_name'], 'IN');
}
$query->leftJoin('menu_links', 'pl', '[ml].[plid] = [pl].[mlid]');
$query->addField('pl', 'link_path', 'parent_link_path');
$query->orderBy('ml.depth');
......
......@@ -212,7 +212,7 @@ public function providerSource() {
],
[
// D7 non-customized menu link, provided by menu module.
'menu_name' => 'menu-test-menu',
'menu_name' => 'menu-test2-menu',
'mlid' => 300,
'plid' => 0,
'link_path' => 'node/142',
......@@ -270,6 +270,26 @@ public function providerSource() {
$tests[0]['expected_data'][] = $expected[3];
$tests[0]['expected_data'][] = $expected[4];
// Tests retrieval of links from multiple menus.
$tests[1] = $tests[0];
$tests[1]['expected_count'] = NULL;
$tests[1]['configuration'] = [
'menu_name' => ['menu-test-menu', 'menu-test2-menu'],
];
// Tests retrieval of links from a single menu.
$tests[2] = $tests[1];
$tests[2]['configuration'] = [
'menu_name' => 'menu-test2-menu',
];
$tests[2]['expected_data'] = [$expected[6]];
// Tests retrieval of links from a not existing menu.
$tests[3] = $tests[1];
$tests[3]['configuration'] = [
'menu_name' => 'menu-not-exists',
];
$tests[3]['expected_data'] = [];
return $tests;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment