Skip to content

Modal state is lost when opening the pagelist in a modal (+idea for a general solution) #2020

Open
@BernhardBaumrock

Description

@BernhardBaumrock

Tracking the modal state can be a pain. There are many situations where we need to modify urls, append &modal=1 to not lose the modal state.

I just found another situation of that today. And while working on a fix I had an idea how we could improve the situation in a more generic way (see idea at the end).

Short description of the issue

I want to show a pagelist in a modal to manage my tags that are then used in a page reference field.

To open the pagelist in a modal I added this button to my page select field:

<a href='{$url}page/list/?id=$id' class='pw-modal'>
  Manage Tags
</a>
image

This opens the pagelist as expected:

image

But when I click on "edit" on one of those pages the modal state gets lost:

image

Expected behavior

The page edit button should open the page editor in a modal like this:

image

Optional: Suggestion for a possible fix

I have just added a solution to the RockAdminTweaks module: https://github.com/baumrock/RockAdminTweaks/blob/main/tweaks/PageList/AddModalParam/AddModalParam.js

Idea

Rather than fighting all urls on the backend, hooking here and there and whatnot, what if we used the approach that I took here not only for the pagelist but all across the admin?

What if we didn't care about url rewriting on the backend at all and modified the urls only via javascript? This could happen on page load, and on ajaxComplete, and when calling ProcessWire.addModalParams() (for example).

I think that should improve the situation, because if anybody built a module for whatever feature, he/she didn't even have to think about also supporting modals with custom PHP code like this:

if($input->get->modal) $url = '...';
else $url = '...';

He/she would just output a link like /foo/bar/whatever and the modal link watcher would kick in on page load and transform it into /foo/bar/whatever?modal=1 if in a modal and if not, leave it as is.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions