Explorar o código

Merge pull request #1156 from EmmanuelVella/breadcrumbs

Check route and permissions when generating breadcrumbs
Thomas %!s(int64=12) %!d(string=hai) anos
pai
achega
dc77e3b3b6
Modificáronse 2 ficheiros con 11 adicións e 4 borrados
  1. 3 3
      Admin/Admin.php
  2. 8 1
      Resources/views/standard_layout.html.twig

+ 3 - 3
Admin/Admin.php

@@ -1959,7 +1959,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
 
         $child = $child->addChild(
             $this->trans($this->getLabelTranslatorStrategy()->getLabel(sprintf('%s_list', $this->getClassnameLabel()), 'breadcrumb', 'link')),
-            array('uri' => $this->generateUrl('list'))
+            array('uri' => $this->hasRoute('list') && $this->isGranted('LIST') ? $this->generateUrl('list') : null)
         );
 
         $childAdmin = $this->getCurrentChildAdmin();
@@ -1969,7 +1969,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
 
             $child = $child->addChild(
                 $this->toString($this->getSubject()),
-                array('uri' => $this->generateUrl('edit', array('id' => $id)))
+                array('uri' => $this->hasRoute('edit') && $this->isGranted('EDIT') ? $this->generateUrl('edit', array('id' => $id)) : null)
             );
 
             return $childAdmin->buildBreadcrumbs($action, $child);
@@ -1978,7 +1978,7 @@ abstract class Admin implements AdminInterface, DomainObjectInterface
             if ($action != 'list') {
                 $menu = $menu->addChild(
                     $this->trans($this->getLabelTranslatorStrategy()->getLabel(sprintf('%s_list', $this->getClassnameLabel()), 'breadcrumb', 'link')),
-                    array('uri' => $this->generateUrl('list'))
+                    array('uri' => $this->hasRoute('list') && $this->isGranted('LIST') ? $this->generateUrl('list') : null)
                 );
             }
 

+ 8 - 1
Resources/views/standard_layout.html.twig

@@ -122,7 +122,14 @@ file that was distributed with this source code.
                         {% if action is defined %}
                             {% for label, uri in admin.breadcrumbs(action) %}
                                 {% if not loop.last  %}
-                                    <li><a href="{{ uri }}">{{ label }}</a><span class="divider">/</span></li>
+                                    <li>
+                                        {% if uri is not empty %}
+                                            <a href="{{ uri }}">{{ label }}</a>
+                                        {% else %}
+                                            {{ label }}
+                                        {% endif %}
+                                        <span class="divider">/</span>
+                                    </li>
                                 {% else %}
                                     <li class="active">{{ label }}</li>
                                 {% endif %}