You are here

function responsive_menu_test_install in Responsive and off-canvas menu 4.1.x

Same name and namespace in other branches
  1. 4.4.x tests/modules/responsive_menu_test/responsive_menu_test.install \responsive_menu_test_install()
  2. 4.3.x tests/modules/responsive_menu_test/responsive_menu_test.install \responsive_menu_test_install()

Implements hook_install().

@noinspection PhpFullyQualifiedNameUsageInspection

Throws

\Drupal\Core\Entity\EntityStorageException

File

tests/modules/responsive_menu_test/responsive_menu_test.install, line 20
Install file for responsive_menu_test module.

Code

function responsive_menu_test_install() {
  $items = [
    'level1item1' => [
      'title' => 'Test page title for top level nav',
      'link' => 'internal:/node/1',
      'body' => 'This is a page.',
    ],
    'level2item1' => [
      'title' => 'A second level item',
      'link' => 'internal:/node/2',
      'parent' => 'level1item1',
      'body' => 'A page linked to a second level item.',
    ],
    'level2item2' => [
      'title' => 'A sibling on the second level',
      'link' => 'internal:/node/3',
      'parent' => 'level1item1',
      'body' => 'Another second level item.',
    ],
    'level1item2' => [
      'title' => 'Menu item without children',
      'link' => 'internal:/node/4',
      'body' => 'A page that is in the menu tree without any children.',
    ],
    'level1item3' => [
      'title' => 'Third top level item',
      'link' => 'internal:/node/5',
      'body' => 'Just another test page.',
    ],
    'level2item3' => [
      'title' => 'Child of third item',
      'link' => 'internal:/node/6',
      'parent' => 'level1item3',
      'body' => 'A second level item test page.',
    ],
    'level3item1' => [
      'title' => 'Third level item',
      'link' => 'internal:/node/7',
      'parent' => 'level2item3',
      'body' => 'Used to test third level items.',
    ],
  ];
  $created = [];
  foreach ($items as $id => $item) {
    $menu_link_data = [
      'title' => $item['title'],
      'link' => [
        'uri' => $item['link'],
      ],
      'menu_name' => 'main',
      'expanded' => TRUE,
    ];
    if (isset($item['parent']) && isset($created[$item['parent']])) {
      $parent = $created[$item['parent']];
      $menu_link_data['parent'] = $parent
        ->getPluginId();
    }
    $menu_link = MenuLinkContent::create($menu_link_data);
    $menu_link
      ->save();
    $created[$id] = $menu_link;
    _create_node($item);
  }
  $blocks = [
    'responsive_menu_horizontal_menu',
    'responsive_menu_toggle',
  ];
  foreach ($blocks as $block_id) {
    $values = [
      'id' => $block_id,
      'plugin' => $block_id,
      'region' => 'primary_menu',
      'settings' => [
        'label' => '',
      ],
      'theme' => 'stark',
      'visibility' => [],
      'weight' => 0,
    ];
    $block = Block::create($values);
    $block
      ->save();
  }
  $node = Node::load(2);
  $node_ar = $node
    ->addTranslation('ar');
  $node_ar->title = 'هذا اختبار';
  $node_ar->body->value = 'ترجمة جوجل مفيدة';
  $node_ar->body->format = 'basic_html';
  $node_ar
    ->save();
}