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

Make Menu implement Iterator #92

Open
acobster opened this issue Mar 7, 2019 · 0 comments
Open

Make Menu implement Iterator #92

acobster opened this issue Mar 7, 2019 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@acobster
Copy link
Contributor

acobster commented Mar 7, 2019

I want to be able to do a (depth-first) search through a tree of MenuItems:

$randomPost = new Page(123);
foreach ($menu as $item) {
  if ($item->object_id === $randomPost->id) {
    // do some stuff with $item
  }
}

This is useful for finding items matching arbitrary criteria (that is, other than the "current" menu item, or ancestors of it).

The simplest way to accomplish this is by implementing the Iterator interface in Menu, using an internal stack of items to keep track of position in the depth-first search.

NOTE: an implementation of this lives in the Metro Parks codebase. We just need to backport it and get some tests around it. Tests will likely be a bit of a PITA because Timber's Menu is coupled to the database. There are a few approaches I could see us taking to solve that:

@acobster acobster added the enhancement New feature or request label May 12, 2019
@acobster acobster added this to the 2019-Q3 milestone Jul 29, 2019
@acobster acobster self-assigned this Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant