Repository: django-cms/django-cms

Issue:
Plugin breadcrumbs are in wrong order



Discussion:

Resolving patch:
diff --git a/cms/models/pluginmodel.py b/cms/models/pluginmodel.py
--- a/cms/models/pluginmodel.py
+++ b/cms/models/pluginmodel.py
@@ -372,18 +372,7 @@ def get_breadcrumb(self):
 
         model = self.placeholder._get_attached_model() or Page
         breadcrumb = []
-        if not self.parent_id:
-            try:
-                url = force_text(
-                    admin_reverse("%s_%s_edit_plugin" % (model._meta.app_label, model._meta.model_name),
-                                  args=[self.pk]))
-            except NoReverseMatch:
-                url = force_text(
-                    admin_reverse("%s_%s_edit_plugin" % (Page._meta.app_label, Page._meta.model_name),
-                                  args=[self.pk]))
-            breadcrumb.append({'title': force_text(self.get_plugin_name()), 'url': url})
-            return breadcrumb
-        for parent in self.get_ancestors().reverse():
+        for parent in self.get_ancestors():
             try:
                 url = force_text(
                     admin_reverse("%s_%s_edit_plugin" % (model._meta.app_label, model._meta.model_name),
@@ -393,6 +382,15 @@ def get_breadcrumb(self):
                     admin_reverse("%s_%s_edit_plugin" % (Page._meta.app_label, Page._meta.model_name),
                                   args=[parent.pk]))
             breadcrumb.append({'title': force_text(parent.get_plugin_name()), 'url': url})
+        try:
+            url = force_text(
+                admin_reverse("%s_%s_edit_plugin" % (model._meta.app_label, model._meta.model_name),
+                              args=[self.pk]))
+        except NoReverseMatch:
+            url = force_text(
+                admin_reverse("%s_%s_edit_plugin" % (Page._meta.app_label, Page._meta.model_name),
+                              args=[self.pk]))
+        breadcrumb.append({'title': force_text(self.get_plugin_name()), 'url': url})
         return breadcrumb
 
     def get_breadcrumb_json(self):


Test patch:
diff --git a/cms/tests/plugins.py b/cms/tests/plugins.py
--- a/cms/tests/plugins.py
+++ b/cms/tests/plugins.py
@@ -244,6 +244,28 @@ def test_plugin_order_alt(self):
             rendered_live_placeholder = live_placeholder.render(self.get_context(live_page.get_absolute_url(), page=live_page), None)
             self.assertEqual(rendered_live_placeholder, "I'm the firstI'm the secondI'm the third")
 
+    def test_plugin_breadcrumbs(self):
+        """
+        Test the plugin breadcrumbs order
+        """
+        draft_page = api.create_page("home", "col_two.html", "en",
+                                     slug="page1", published=False, in_navigation=True)
+        placeholder = draft_page.placeholders.get(slot="col_left")
+
+        columns = api.add_plugin(placeholder, "MultiColumnPlugin", "en")
+        column = api.add_plugin(placeholder, "ColumnPlugin", "en", target=columns, width='10%')
+        text_plugin = api.add_plugin(placeholder, "TextPlugin", "en", target=column, body="I'm the second")
+        text_breadcrumbs = text_plugin.get_breadcrumb()
+        self.assertEqual(len(columns.get_breadcrumb()), 1)
+        self.assertEqual(len(column.get_breadcrumb()), 2)
+        self.assertEqual(len(text_breadcrumbs), 3)
+        self.assertTrue(text_breadcrumbs[0]['title'], columns.get_plugin_class().name)
+        self.assertTrue(text_breadcrumbs[1]['title'], column.get_plugin_class().name)
+        self.assertTrue(text_breadcrumbs[2]['title'], text_plugin.get_plugin_class().name)
+        self.assertTrue('/edit-plugin/%s/'% columns.pk in text_breadcrumbs[0]['url'])
+        self.assertTrue('/edit-plugin/%s/'% column.pk, text_breadcrumbs[1]['url'])
+        self.assertTrue('/edit-plugin/%s/'% text_plugin.pk, text_breadcrumbs[2]['url'])
+
     def test_add_cancel_plugin(self):
         """
         Test that you can cancel a new plugin before editing and