Commit e7ed69e7 authored by Aleksey.Alekseev's avatar Aleksey.Alekseev
Browse files

menu criation

parent 4edba9e5
......@@ -177,19 +177,26 @@ class DrushContentImport extends DrushCommands {
private function importMenu($data) {
// TODO: Create menu
// \Drupal::entityTypeManager()->getStorage('menu')->create([
// 'id' => $data['menu']['id'],
// 'label' => 'Test menu',
// 'description' => 'Description text',
// ])->save();
if ($menu = \Drupal::entityTypeManager()->getStorage('menu')->load($data['menu']['id'])) {
$menu->set('label', 'Test menu');
$menu->set('description', 'Description text');
$menu->save();
}
else {
\Drupal::entityTypeManager()->getStorage('menu')->create([
'id' => $data['menu']['id'],
'label' => 'Test menu',
'description' => 'Description text',
])->save();
}
$this->addMenuLink($data['links'], NULL);
$this->addMenuLink($data['links'], NULL, $data['menu']['id']);
}
/**
* Import Menu Links.
*/
private function addMenuLink($links, $parent_id) {
private function addMenuLink($links, $parent_id, $menu_id) {
if (empty($links)) {
return;
}
......@@ -198,7 +205,7 @@ class DrushContentImport extends DrushCommands {
$t = [
'title' => $menu_link['title'],
'link' => ['uri' => $menu_link['uri']],
'menu_name' => 'main',
'menu_name' => $menu_id,
'expanded' => $menu_link['expanded'],
'weight' => $menu_link['weight'],
'parent' => $parent_id,
......@@ -214,7 +221,7 @@ class DrushContentImport extends DrushCommands {
else {
$parent_id1 = NULL;
}
$this->addMenuLink($children, $parent_id1);
$this->addMenuLink($children, $parent_id1, $menu_id);
}
}
......
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