backdrop-contrib / paragraphs

Paragraphs module to control your content flow
https://backdropcms.org/project/paragraphs
GNU General Public License v2.0
5 stars 11 forks source link

Allow separate modal edit/delete/sort of Paragraph items #60

Closed laryn closed 2 years ago

laryn commented 4 years ago

I have been meaning to see if I could figure out how to allow editing of individual Paragraph items via contextual link rather than requiring the entire node to be loaded. (For example, if one item way down the page needs a minor tweak, it would be way simpler to be able to edit that one item rather than load the entire page, scroll down to find that paragraph with everything else around it, potentially have to expand that Paragraph item before being able to edit it...)

My idea included opening the edit window in a modal and refreshing the page when it was submitted, but that may not be necessary. It turns out there's an issue (and a patch) in the Drupal queue that aims for very similar functionality (minus the modal). And follow up issues could be the ability to delete/insert Paragraphs in this way, and maybe even reorder (e.g. Move up, Move down).

I've tried to implement that first patch in the issue-60 branch.

The main issue I'm finding seems to be that host entity details aren't being tracked. This causes the access check to fail and the save to fail (Unable to save a paragraph without a valid reference to a host entity.).

I've temporarily adjusted the access check to include a new permission rather than checking whether the user has access to update the host entity, and could override the save not to check the host entity as well (but then we'd lose Paragraph revisions on nodes when edited in this way).

laryn commented 4 years ago

This is the $paragraphs_item entity as loaded in paragraphs_form_edit: Screen Shot 2020-04-20 at 4 23 23 PM

And here's what it looks like in Drupal 7: Screen Shot 2020-04-21 at 4 33 35 PM

laryn commented 4 years ago

I've made some progress, I think. I would appreciate anyone with more code experience looking over the changes I'm attempting:

https://github.com/backdrop-contrib/paragraphs/tree/contextual_edit

Right now it seems to work for Nodes, and partially for Taxonomy Terms (ie. it allows edit and save but it duplicates the same Paragraph item every time you save it -- something's off on the delta somewhere).

Comments or feedback welcome!

laryn commented 4 years ago

I think this is functional now. Anyone care to test and/or glance over the code for a quick review? Tested with Paragraph fields on a node, a taxonomy term, and a user.

When you add the Paragraph field to an entity, this box needs to be checked in order for contextual links to be added:

Screen Shot 2020-04-22 at 12 25 01 AM

laryn commented 3 years ago

Playing around with an alternate implementation that uses dropbutton instead of contextual link, so there are two separate branches related to this issue:

olafgrabienski commented 3 years ago

I've started to play around with the Dropbutton branch, looks really good at first sight. I like this approach more than the Contextual links approach.

olafgrabienski commented 3 years ago

Editing a Paragraph using Dropbuttons, I've encountered a strange behavior:

Upon Edit of a Paragraph, the background color and the Account menu in the header section of the page change their appearance. Looks like the styles are coming from the admin theme. Not sure if it's intended but that's not my issue. The issue is that this appearance remains after saving the Paragraph. (When I reload the page, it changes back to the expected appearance.) See the screenshots below.

(1) View the page

backdrop-paragraphs-1-view

(2) Edit paragraph

backdrop-paragraphs-2-edit

(3) Edited and saved

backdrop-paragraphs-3-edited

laryn commented 3 years ago

@olafgrabienski I'm going to move that into a separate issue related to core bugs: https://github.com/backdrop-contrib/paragraphs/issues/81

laryn commented 2 years ago

I've merged this in for the next alpha pre-release. Open new issues around this feature as you test!

laryn commented 2 years ago

After two alphas and a beta, I think we're at a point where we can do a first formal release that includes this functionality (using dropbutton instead of contextual links). Big thanks to @olafgrabienski for helping me test and to those that did the heavy lifting (using contextual links) in the Drupal 7 thread with patches, testing and feedback, including: @ModulesUnraveled, @darthsteven, jonathanshaw, @iaminawe, Grayle, Nchase, @stevetweeddale, RAFA3L, delacosta456, @PascalMortier, 8bitplateau, Ludo.R, @StryKaizer, jeroen.b, @mirodietiker, @anotherjames, @Nebel54, @martijnhoutman, @vollepeer, @amoebanath, @rgpublic, vaccinemedia, screon, loominade, Alexandre360, reekris, and georgiana-albu.