You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to be able to do a (depth-first) search through a tree of MenuItems:
$randomPost = newPage(123);
foreach ($menuas$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:
I want to be able to do a (depth-first) search through a tree of
MenuItem
s: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 inMenu
, 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:WP_Mock
(see SiteTest.php for an example) to mock menu/item dataThe text was updated successfully, but these errors were encountered: