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
base: 2.5
Are you sure you want to change the base?
Conversation
…f menu items points to the parent menu item, not the parent item's post/page
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.
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: |
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.
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 |
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.
same here 😉
src/Model/MenuItem.php
Outdated
*/ | ||
public function parent() | ||
public function parent_item() |
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.
fix method name please 😉💪
done! cheers |
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 ;)