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

Feature Request: overrideable way to instantiate MenuItems #1709

Closed
acobster opened this issue Apr 28, 2018 · 1 comment
Closed

Feature Request: overrideable way to instantiate MenuItems #1709

acobster opened this issue Apr 28, 2018 · 1 comment

Comments

@acobster
Copy link
Collaborator

I'd like to be able to override how MenuItem instances are created. Right now, new $this->MenuItemClass($item) is bound up inside Menu::order_children. If it were in its own method, I could override that in order to, for instance, polymorphically create different kinds of MenuItems:

class CustomMenu extends Timber\Menu {
  protected function create_menu_item($item) {
    if ($this->is_login_nav_item($item)) {
     return new LoginMenuItem($item);
    }

    return new $this->MenuItemClass($item);
  }
}

In this example, LoginMenuItem might return a different title/URL depending on the user's login state. But we don't necessarily want all items to be instances of that class.

acobster pushed a commit to sitecrafting/timber that referenced this issue Apr 28, 2018
jarednova added a commit that referenced this issue May 1, 2018
#1709 break $MenuItemClass instantiation into own method
@gchtr
Copy link
Member

gchtr commented May 1, 2018

Thanks for providing a pull request for this 💪. I guess we can close this now.

@gchtr gchtr closed this as completed May 1, 2018
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

No branches or pull requests

2 participants