Allow subpage deletion on panel when "deletable: true" on child page(s)

I think you could ā€œhackā€ in a custom delete action. Depending on where you need to be able to delete a page.
Doing this for the sidebar only would be relatively easy. Expanding it to the context menu should be doable as well. I think.

You could add a custom delete link in the sidebar with javascript pointing to a custom route where you can delete the page with $force = true.

Perhaps I can fiddle something together.

1 Like

I agree with @lukaskleinschmidt, that option is preferable to hacking the panel, you can then still update Kirby without any problems and you donā€™t run into issues, because the Panel code is rather complex.

As far as I remember someone has created a field for deleting files; deleting pages could be achieved in the same way: https://github.com/arnaudjuracek/kirby-field-trashfiles

I totally agree with @texnixe and @lukaskleinschmidt and would love to have a custom delete action. Itā€™s a bit hacky too, though as we canā€™t extend the sidebar without duplicating fields with Javascript, yet. Or is there something Iā€™m missing?

I had another look at the Kirby core, and as is all too often the case I found the lines preventing pages with subpages to be deleted.

Here are the necessary changes.

https://github.com/medienbaecker/plainkit/commit/f1221981dcd2497ee416f2348022c8663402faf7

Maybe this helps with the development of a custom delete action. Or as a last resort you can temporarily change this in the core as Iā€™m positive this will be possible in the next Kirby version.

1 Like

Oh, only two little changes, that looks fine to me.

Yes, itā€™s crazy. I changed so many instances of delete in the Kirby and Panel folders and each and every time a new layer of protection came around. But now after some time I just changed two files and it works.

Iā€™m still in disbelief itā€™s that easy, did you test it already?

EDIT:

As Iā€™m changing the delete() function to never break when there are subpages, and since thereā€™s no second warning in the panel, itā€™s definitely not an ideal solution. Keep that in mind when using this.

No, not yet, I have some other stuff to do right now. Sometimes itā€™s just difficult to find the right lines to change. Does not look as if that would interfere with permissions.

Thanks @thguenther! I made a comment to your commit with a proposed change that allows you to use the deletable: false blueprint setting to prevent certain pages to be deleted.

Thanks @ola! I commented the lines out and pushed another commit.

I was able to put something together.
It only works for the sidebar currently.

1 Like

Wow, thatā€™s super clean. Especially the action path delete/force really makes sense.

Adding a page to a page which does not yet have child pages results in two instances of ā€œDelete pageā€ for me. Can you reproduce that? It doesnā€™t happen when adding additional subpages.

The one on the bottom seems to think itā€™s still on the parent page as the path is not the subpage but the parent page. Maybe the redirect to the child after creating it has something to do with it?

Hm actually I test if the default delete action is avialable. In a way :confused:.

Could you please change the js code delete/assets/js/delete.js to

(function($) {

  $.fn._sidebar  = $.fn.sidebar;

  $.fn.sidebar = function() {
    add();
    return this._sidebar();
  };

  var add = function() {
    var url = window.location.href.replace('/edit', '/options/delete');

    if((window.location.pathname.match(/\//g) || []).length < 3 || $('#delete').length) return;

    $.get(url, function(data) {
      console.log(data);
      if(!data) return;

      var link = $('<a id="delete"><i class="icon icon-left fa fa-trash-o"></i>' + data.label + '</a>');

      if(data.href) {
        link.attr('href', data.href);
      }

      if(data.title) {
        link.attr('title', data.title);
      }

      if(data['data-shortcut']) {
        link.attr('data-shortcut', data['data-shortcut']);
      }

      if(data['data-modal']) {
        link.attr('data-modal', '');
      }

      $('.sidebar-list:nth-of-type(1)').append($('<li>').append(link))
    });
  }

})(jQuery);

And tell me what the console spits out?

Thatā€™s what the console looks like:

EDIT:

Adding a setTimeout to the function like this:

$.fn.sidebar = function() {
    setTimeout(function() {
      add();
    }, 10);
    return this._sidebar();
};

ā€¦solves the problem but adds a delay of course.

Thanks. I was able to recreate this behaviour. I fixed it with checking for a node with $([data-shortcut="#").

Edit: A delay would also work but yeah delay :wink:

Thanks a lot! Yup, way better than a delay. :thumbsup: