Problem/Motivation

The motivation for this is to fix three open issues:

In the location hierarchy drag and drop editor (provided by the farm_ui_location module), we currently handle all updates to asset parent relationships by tracking drag and drop changes in client-side JavaScript (using the Inspire Tree library), and then sending JSON:API requests to the backend to add/remove parents from each asset that was changed. This works, but has some drawbacks, and we've been running into some complexities with the issues linked above.

Proposed resolution

An alternative approach might help to resolve those issues. Instead of sending JSON:API requests to update parents, we can process that changes via PHP when the form is submitted. We can still use client-side JS to track the changes as they happen. These changes can be saved to a hidden form input field, which is then processed on submit. The page is currently built as a controller, not a form, so that would also need to change.

Remaining tasks

  • Step 1: Convert location hierarchy controller to a form (maintaining the same logic).
  • Step 2: Perform location hierarchy changes in form submit instead of AJAX.

User interface changes

"Save" and "Reset" buttons will perform a form submission, instead of using AJAX.

API changes

None.

Data model changes

None.

Issue fork farm-3252070

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

m.stenta created an issue. See original summary.

m.stenta’s picture

Status: Active » Needs review

Took a pass at this. It wasn't too hard! We are able to keep the same JS logic for tracking changes as items are dragged and dropped, and save that information to a hidden input field.

The logic for updating parents is simple: iterate through the changes, remove old parent, and add new parent. This handles assets with multiple parents gracefully. Only the parent that is being changed is removed, and then the new parent is added.

There is one behavior that is a bit odd, when dealing with an asset with multiple parents: if you drag the asset to the root ("All locations"), it will remove the parent that you dragged it from, but it will still be in its other parent. When the hierarchy is re-rendered, the asset ONLY appears under the other parent - NOT under "All locations". This does make some sense... because our logic is "if there are no parents then show it under "All parents". But in this case it still has one parent, so it shows under that one. Even though its a bit odd when you're doing it, it does make sense, so I'm OK with this.

The other nice thing I was able to do is add more informative revision log messages to assets that are updated...

When parents are changed, the revision log is:

Parents changed to [list of parent names] via the Locations drag and drop editor.

When an asset is moved to "All locations" (and it no longer has any parents), the revision log is:

Parents removed via the Locations drag and drop editor.

m.stenta’s picture

(Force pushed to fix codesniffer issues.)

  • m.stenta committed aee4520 on 2.x
    Issue #3252070 by m.stenta: Process location hierarchy changes via PHP...
m.stenta’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.