Skip to content
This repository has been archived by the owner on Dec 27, 2018. It is now read-only.

Commit

Permalink
Minor changes on menus "generators".
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLigny committed Jul 13, 2016
1 parent 7ae8752 commit 60d54b0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
37 changes: 28 additions & 9 deletions src/PHPoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,15 @@ protected function generateMenus()
{
$this->menus = new Menu\Collection();

/* @var $page Page */
/**
* Collects pages with menu entry
* @var $page Page
*/
foreach ($this->pageCollection as $page) {
if (!empty($page['menu'])) {
// single
/*
* ex:
/**
* Single case
* ie:
* menu: main
*/
if (is_string($page['menu'])) {
Expand All @@ -523,9 +526,9 @@ protected function generateMenus()
$menu = $this->menus->get($page['menu']);
$menu->add($item);
}
// multiple
/*
* ex:
/**
* Multiple case
* ie:
* menu:
* main:
* weight: 1000
Expand All @@ -544,20 +547,36 @@ protected function generateMenus()
}
}
}
/*

/**
* Removing/adding/replacing menus entries from options array
* ie:
* ['site' => [
* 'menu' => [
* 'main' => [
* 'test' => [
* 'id' => 'test',
* 'name' => 'Test website',
* 'url' => 'http://test.org',
* 'weight' => 999,
* ],
* ],
* ],
* ]]
*/
if ($this->getOption('site.menu') !== '') {
if (!empty($this->getOption('site.menu'))) {
foreach ($this->getOption('site.menu') as $name => $entry) {
/* @var $menu Menu\Menu */
$menu = $this->menus->get($name);
foreach ($entry as $property) {
// remove disable entries
if (isset($property['disabled']) && $property['disabled']) {
if (isset($property['id']) && $menu->has($property['id'])) {
$menu->remove($property['id']);
}
continue;
}
// add new entries
$item = (new Menu\Entry($property['id']))
->setName($property['name'])
->setUrl($property['url'])
Expand Down
20 changes: 13 additions & 7 deletions tests/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,21 @@ public function testBuid()
'site' => [
'menu' => [
'main' => [
'index' => [
'id' => 'index',
'name' => 'Da home!',
'url' => '',
'weight' => 1,
],
'about' => [
'id' => 'about',
'disabled' => true,
'id' => 'about',
'disabled' => true,
],
'test' => [
'id' => 'test',
'name' => 'Test',
'url' => 'http://narno.org',
'weight' => 999,
'narno' => [
'id' => 'narno',
'name' => 'narno.org',
'url' => 'http://narno.org',
'weight' => 999,
],
],
],
Expand Down

0 comments on commit 60d54b0

Please sign in to comment.