-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Bugfix/13266 Update the processing of items for the top menu #13323
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
Bugfix/13266 Update the processing of items for the top menu #13323
Conversation
foreach ($children as $child) { | ||
if ($childLevel === 0 && $child->getData('is_parent_active') === false) { | ||
continue; | ||
} | ||
$child->setLevel($childLevel); | ||
$child->setIsFirst($counter == 1); | ||
$child->setIsLast($counter == $childrenCount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach looks generally good to me but I don't the idea of separate filtering loop.
I believe instead of removing if
and introducing filtering we need just to track last item properly.
For example, remove $childrenCount
variable, declare $lastChild = null
before loop, do
$child->setIsLast(false);
$lastChild = $child;
in loop and
if ($lastChild) {
$lastChild->setIsLast(true);
}
after it.
As always, please squash changes into single commit and force push after changes are performed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orlangur thank you for your feedback.
Your approach was also the first thing that I wanted to do, but that does not work because the $html
with all the html for the $schildren
is generated in the foreach
loop.
If you do the setIsLast()
after the loop the class last
is not added to the last visible menu item (which was the whole point for this commit ;) )
I squashed the commits 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please remove
$itemPosition
as it seems to be unused - Track
$lastChild
as requested earlier - Split one loop into two: in first we process children, in second generate actual HTML with concatenation
- Feel free to introduce new private methods to get rid of
@SuppressWarnings(PHPMD.CyclomaticComplexity)
and@SuppressWarnings(PHPMD.NPathComplexity)
9351152
to
c5d30e2
Compare
@orlangur can you please take a look at my response? |
@arnoudhgz yeah-yeah, I saw your response and even started to reply, will search for a tab in my browser :) Sorry for delay and thanks for quicks feedback 👍 |
Removed the label, the code does not need the update as suggested. There should be taken a closer look in the issue and the proposed solution in this commit. The suggested change by @orlangur will not help to solve the issue, because the HTML is generated inside the foreach loop. |
The suggested change does not solve the issue because the HTML is generated inside the foreach loop
Label should be removed no earlier than it is confirmed by reviewer. Current approach is not acceptable from computational complexity perspective, I was checking the best way to split loop into two, will share exact suggestion soon. |
Great! A solution with perfect code that will also solve the bug has my preference too 😉 |
@orlangur do you have any idea when you can take a look into this? |
foreach ($children as $child) { | ||
if ($childLevel === 0 && $child->getData('is_parent_active') === false) { | ||
continue; | ||
} | ||
$child->setLevel($childLevel); | ||
$child->setIsFirst($counter == 1); | ||
$child->setIsLast($counter == $childrenCount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please remove
$itemPosition
as it seems to be unused - Track
$lastChild
as requested earlier - Split one loop into two: in first we process children, in second generate actual HTML with concatenation
- Feel free to introduce new private methods to get rid of
@SuppressWarnings(PHPMD.CyclomaticComplexity)
and@SuppressWarnings(PHPMD.NPathComplexity)
Hi @arnoudhgz, please check my previous comment :) |
The counter in the foreach loop was not being calculated correctly. This resolved in the 'last' css class not being set on the output when one or more parent items are not active. With this commit the items will be filtered first before they are being processed for the html output. Move the filtering to seperate method Moved the filter of children without active parent to a seperate method. This will make the whole method more readable and understandable. Also this is a little optimization; the foreach loop will only be run if the child level = 0. Apply consistent class import for Node
c5d30e2
to
eff8a50
Compare
@orlangur the splitting into separate private function would be a good thing to do. But I can't agree with the tracking of the In my approach of making the array first smaller you have to loop over less items in the second I don't get the thing about the Before I start working again on making this function cleaner in more separate private functions can you elaborate more about your suggested approach? Maybe you can make an example in (pseudo) code... |
Hi @arnoudhgz, could you please recreate this branch? During review I noticed that The only thing I would ask you to do is rename I lost your PR somewhere among hundreds of open browser tabs, sorry about that. |
@orlangur yes, no problem. I will add it again. Should I add the |
@arnoudhgz you can but it's mandatory for newly added files only. |
Description
The counter in the foreach loop was not being calculated correctly. This resolved in the 'last' css class not being set on the output when one or more parent items are not active.
With this PR the items will be filtered first before they are being processed for the html output.
Fixed Issues (if relevant)
Manual testing scenarios
Contribution checklist