Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically hide parent 'yii\bootstrap\Nav' section if all subitems are hidden #119

Closed
wants to merge 3 commits into from

Conversation

arogachev
Copy link

Closes #117

@SilverFire SilverFire changed the title Closed #117: Automatically hide parent 'yii\bootstrap\Nav' section if all subitems are hidden Automatically hide parent 'yii\bootstrap\Nav' section if all subitems are hidden Feb 2, 2016
}

$items = ArrayHelper::getValue($parentItem, 'items');
if (empty($items)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be:

$items = ArrayHelper::getValue($parentItem, 'items', []);
if ($items === []) {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case testEmptyItems is failing because we got null and foreach try to run on null.

We can add additional check for null but this is shorter.

@samdark
Copy link
Member

samdark commented Feb 2, 2016

@yiisoft/core-developers need additional review.

@@ -202,6 +202,32 @@ public function renderItem($item)
}

/**
* Check if parent item is visible
* @param array $parentItem
* @return boolean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@since 2.0.7

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe 2.0.6? This extension has no version 2.0.6. released yet and has own version history as I see. Or we need to write framework version here? Why in changelog last changes are written under 2.0.6?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, 2.0.6, of course. Sorry, I've missed that we are in a separated repo

* @param array $parentItem
* @return boolean
*/
protected function isParentVisible($parentItem)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name isParentVisible() is not appropriate.
Should be isItemVisible(), to be consistent with isItemActive().

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's more appropriate because only parent items (of the first level) checked like that, and item can be considered as parent even if it don't have any children.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name sounds like you are checking if item, which is parent to the given one, is chceked to be visible.

@klimov-paul
Copy link
Member

It is better to introduce normalizeItems() method instead. Just as we do for regular yii\widgets\Menu, so those widgets will be consistent.
Besides we have #16 issue as well.

@klimov-paul
Copy link
Member

Since now we have BootstrapWidgetTrait, we can actually resolve #16 and this one, extending Nav from Menu.

@arogachev
Copy link
Author

Maybe add this for now, if related issue is more difficult to implement. The amount of changes is small, so related issue can be implemented separately in the future,

@klimov-paul
Copy link
Member

Adding protected method introduces new class API, which future change will cause BC break.

@arogachev
Copy link
Author

@klimov-paul Could you summarize what's need to be fixed / changed in this case?

@klimov-paul
Copy link
Member

Could you summarize what's need to be fixed / changed in this case?

Even if do not extend Nav from Menu at this time. Thier methods interfaces should be as same as possible.
Back in Menu we pass $items through normalizeItems() method, which handles visibility, active check and so on. And only after that, we are rendering $items. Thus Nav should share this approach and methods API.

Actually, all we need to do is 'copy-paste' code from Menu to Nav.

@arogachev arogachev closed this Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatically hide parent 'yii\bootstrap\Nav' section if all subitems are hidden
4 participants