Skip to content
This repository has been archived by the owner on Feb 11, 2018. It is now read-only.

Breadcrumb : display basic breadcrumb when the current route not found in the Menu tree #22

Closed
QuentinLemCode opened this issue Feb 20, 2015 · 3 comments

Comments

@QuentinLemCode
Copy link

Hello,

When you try to generate a breadcrumb on a page that doesn't exist in the menubuilder, the function

$breadcrumbs = $manipulator->getBreadcrumbsArray($itemFilterIterator->current());

return an exception

Why not just return an empty breadcrumb ?
On Twig/MenuExtension.php l.100

        // Extract the items for the breadcrumb
    $manipulator = new MenuManipulator();
    $current = $itemFilterIterator->current();
    if($current instanceof ItemInterface)
        $breadcrumbs = $manipulator->getBreadcrumbsArray($itemFilterIterator->current());
    else
        $breadcrumbs = $manipulator->getBreadcrumbsArray($menu);

Thanks

@flobb
Copy link
Owner

flobb commented Feb 20, 2015

Hi,

I'm going to investingate. Can you add your route and your menu ?

If the page is not in the menu, what is the expected result for the display ?
An empty breadcrumb is strange :/

@QuentinLemCode
Copy link
Author

No display ! The itemFilterIterator->current() return null, so the manipulator throw an exception.

For example, when you generate CRUD with symfony, it create 6 route :

entity
entity_new
entity_create
entity_edit
entity_update
entity_delete

If (like me) you put the breadcrumb in the base layout. The breadcrumb will throw an exception when you open a page who aren't on the menu. The page "entity_update" is used when the data in form are invalid, why put this on the menu ? Currently, for not crash the breadcrumb !

I understand that without the menu, the breadcrumb will not display the correct name, but i think it shouldn't have to crash, no ? :p

That's true, an empty breadcrumb is strange. But I think the itemFilterIterator should return the parent item when it don't find the current matched item.
At least, it can be good to handle the exception.

flobb added a commit that referenced this issue Feb 27, 2015
flobb added a commit that referenced this issue Feb 27, 2015
@flobb
Copy link
Owner

flobb commented Feb 27, 2015

That's true, an empty breadcrumb is strange. But I think the itemFilterIterator should
return the parent item when it don't find the current matched item.

If you have a way to use the matcher with url and return the most relevent item (the nearest parent), please, make a PR.

Actually, i suggest to have a breadcrumb with the first item.

flobb pushed a commit that referenced this issue Mar 1, 2015
@flobb flobb closed this as completed Mar 1, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants