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

Fixed MenuItem parent #383

Open
wants to merge 3 commits into
base: 2.5
Choose a base branch
from

Conversation

tbruckmaier
Copy link

Fixed the MenuItem parent relation using laravel belongsTo relation. Also fixed the tests, a menu item's parent id (in _menu_item_menu_item_parent) contains the id of the parent menu item, not the parent's linked post/page/etc.
I left the original parent() method there (which still points to the parent's post/page), so it should not break any implementations, just marked it as deprecated.
This should also fix #365
I can send a pull request for 2.6 after the other menu item pr is merged, otherwise it gets too confusing ;)

…f menu items points to the parent menu item, not the parent item's post/page
Copy link
Member

@jgrossi jgrossi left a comment

Choose a reason for hiding this comment

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

thanks for the PR. just a few changes and it's ready to go! thanks! 🎉

README.md Outdated
@@ -609,14 +609,15 @@ foreach ($menu->items as $item) {

To handle multi-levels menus, loop through all the menu items to put them on the right levels, for example.

You can use the `MenuItem::parent()` method to retrieve the parent instance of that menu item:
You can use the `MenuItem::parent_item()` relation to retrieve the parent instance of that menu item:
Copy link
Member

Choose a reason for hiding this comment

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

can you change it to parentItem() to follow PSR-2, please?

README.md Outdated

```php
$items = Menu::slug('foo')->first()->items;
$parent = $items->first()->parent(); // Post, Page, CustomLink or Term (category)
$parentItem = $items->first()->parent_item; // MenuItem or null for top-level items
Copy link
Member

Choose a reason for hiding this comment

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

same here 😉

*/
public function parent()
public function parent_item()
Copy link
Member

Choose a reason for hiding this comment

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

fix method name please 😉💪

@tbruckmaier
Copy link
Author

done! cheers

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.

None yet

2 participants