Skip to content

Commit

Permalink
Add new param $parentItem to renderItems() private method
Browse files Browse the repository at this point in the history
  • Loading branch information
itstructure committed Aug 11, 2020
1 parent 74f1f54 commit 839ff74
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Data from the **database** is taken from an active model, which instance of **yi

Via composer:

`composer require itstructure/yii2-multi-level-menu ~3.2.6`
`composer require itstructure/yii2-multi-level-menu ~3.2.7`

## Usage

Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
### CHANGE LOG:

**3.2.7 August 11, 2020:**
- Add new param `$parentItem` to `renderItems()` private method.

**3.2.6 July 17, 2020:**
- Readme instruction fixes.

Expand Down
9 changes: 5 additions & 4 deletions src/MenuWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,11 @@ private function groupLevels(array $models): array
*
* @param array $items
* @param int $level
* @param array $parentItem
*
* @return string
*/
private function renderItems(array $items, int $level = 0): string
private function renderItems(array $items, int $level = 0, $parentItem = []): string
{
if (count($items) == 0) {
return '';
Expand All @@ -250,7 +251,7 @@ private function renderItems(array $items, int $level = 0): string
], $this->levelAttributeValue($this->itemTemplateParams, $level, $item)));

if (isset($item['items'])) {
$contentLi .= $this->renderItems($item['items'], $level + 1);
$contentLi .= $this->renderItems($item['items'], $level + 1, $item);
}

$itemContainerTag = $this->levelAttributeValue($this->itemContainerTag, $level, $item);
Expand All @@ -261,8 +262,8 @@ private function renderItems(array $items, int $level = 0): string
);
}

$mainContainerTag = $this->levelAttributeValue($this->mainContainerTag, $level);
$mainContainerOptions = $this->levelAttributeValue($this->mainContainerOptions, $level);
$mainContainerTag = $this->levelAttributeValue($this->mainContainerTag, $level, $parentItem);
$mainContainerOptions = $this->levelAttributeValue($this->mainContainerOptions, $level, $parentItem);

if ($level == 0 && null !== $this->menuId) {
$mainContainerOptions = ArrayHelper::merge($mainContainerOptions, [
Expand Down

0 comments on commit 839ff74

Please sign in to comment.