Problem/Motivation
Paragraphs are now only editable in the host entity edit page.
Proposed resolution
It would be nice if users can decide in the field widget settings if contextual links for each paragraph item are available, making the items editable per paragraph item entity.
The default way would stay the same, but people who'd like to offer their users direct editing links, will be able to do so.
(Note: I mailed about this with the jeroen-b (module-author) who suggested the field widget settings option)
Remaining tasks
The current latest patch includes functionality that has since been split off into #2715833: Delete/insert paragraphs with contextual links, which added complexity beyond this ticket's original scope. So a new patch needs to be produced without that, that should also cover the following concerns which I don't think it addressed anyway:
- Other revisionable entity types (e.g. beans) should probably be handled, rather than being specific to nodes. We could have some more entity-type-generic code that handles that. (james.williams, comment 34)
- As per #2452675: Entity translation support for Drupal 7, depending on how language is handled, we'll have to correctly set the paragraph field values, rather than being hardcoded to 'Language neutral'. (mihai_brb, comment 33)
Comments
Comment #1
strykaizerAttached you can find a patch which implements the described feature
Comment #2
strykaizerComment #4
strykaizerNew patch which checks if separate_edit setting is set before accessing
Comment #5
jeroen.b commentedNice!
Can you change
paragraphs_item_access("update",$paragraphs_item, $user, 'paragraphs_item');toparagraphs_item_access("update", $paragraphs_item, $user, 'paragraphs_item');?Can you also use single quotes everywhere?
Also, I think you should also update the host entity to point to the new revision?
Comment #6
strykaizerAttached is a refactor with single quotes and space as requested.
I'm a bit confused about the revision update.
Do we need to update the revision id on the host entities paragraph_item reference field?
Since only the paragraph_item entity is changed, there is no new revision_id on the host entity, so the reference stays the same?
Or do you prefer manually creating a new revision for the hostentity on each individual paragraph item edit? If yes, since revisions are optional, we should check if auto-revisions are enabled for the host-entity.
Comment #7
jeroen.b commentedI think it's good to use the same behaviour as in the normal widget.
See: http://cgit.drupalcode.org/paragraphs/tree/paragraphs.module#n607
Comment #8
miro_dietikerThis reminds me to the issue that happened when we tried inline editing yesterday...
As a user you would expect that inline editing allows you to edit a single paragraph. Instead you edit the entity reference, showing all paragraphs at the same time as editable widget. OK, a separate issue, but feels kindof related to this contextual editing.
Hope there are no clashes of these two functionalities here?
I'm struggling here...
If the contextual links are an appreciated concept that fit well, we should have them enabled by default.
But it completely changes edit experience as of now. So default is no option.
This is bringing us much more near to having routes per paragraph. For now this was avoided including the fact that a paragraph can not be displayed on its own.
We might want to allow access this edit URI only in case the setting in the field is enabled.
Codestyle... Please check all code with coder.
Comment #9
strykaizerJust a note, using the patch in #6 is not stable yet and should not be used in production. You WILL experience issues ;)
Haven't found the time to see if I can fix the current issues I'm experiencing atm.
Comment #10
james.williamsThe attached patch improves on the patch in comment 6 above in the following ways, as raised above:
1. Code style issues fixed
2. Removed unnecessary/unwanted menu router item 'paragraphs' and related code
3. Access to the separate form is only granted if the setting is enabled.
4. PHP notices on submission of the separate form fixed ($form_state was not being modified by reference so field state data was not set)
To address some of the remaining issues...
@jeroen.b (comment 7) ... the normal widget behaviour is determined by whether the editor has decided to create a new revision or not for the host entity. But if they are editing a paragraph on its own in this separate page,
$entity->revisiondoes not itself exist. Nodes have a default setting for whether that would be set to true/false initially (and permissions to determine whether editors can override it for a certain edit). But that can then be different for every entity type, so it's not so simple.@miro_dietiker (comment 8) ... Since contextual links could start appearing all over the place, I don't think it's a bad thing to default this new setting to be initially disabled. In core, there would usually only be a few contextual links on any page. But paragraphs increases the potential quite significantly, possibly crowding the UI too much for editors. Plus enabling it by default might require updating existing field instances in an update hook so that they would be consistent with new field instances, which feels unnecessary.
Routes per paragraph can continue to be avoided for now - which is why I've removed the 'paragraphs' item in
paragraphs_menu()in the patch, and implemented the contextual links in a more bespoke way, since they would normally rely on a root path. If a root path is explicitly to be avoided (at least for now), then 'normal' contextual links wouldn't make sense. Hopefully that explains why I've gone down that route (no pun intended!) in this patch.@StryKaizer (comment 9) ... are there specific issues you could list? I've done what I can to fix what I could see, as I wanted to use this functionality. I'd be very keen to know if there are other issues you're aware of?
Comment #11
james.williamsSorry, I got an access check wrong after re-factoring, this patch is better :-)
Comment #12
nebel54Hej, thanks for the Patch! I Just did some first tests, I needed to add
print render($title_prefix);print render($title_suffix);to the paragraophs_item.tpl.php to get the contextual menu working, as the html for it is injected via $title_suffix. Did you use a custom template or is there a better way to get the html injected?
Attached you can find a patch which works with vanilla drupal7. I'm going to test more in the next days.
Comment #13
martijn houtman commentedPatch works fine for me!
Comment #14
strykaizer@james.williams: The issue I experienced with my patch was when using paragraphs in combinatiion with a custom entity (eck) and entity reference, it threw an error.
I just tested the patch in #12 and I can not reproduce my previous error. God, I love open source software! ;-)
Comment #15
jeroen.b commentedSince we are now checking the host entity inside paragraphs_item_access we can change the following line:
to:
Comment #16
vollepeer commentedWhen editing a paragraph using a contextual link and you have workbench moderation enabled, there are couple of issues:
Editing a paragraph of the currently published node
Editing a paragraph in general
When saving changes, the host entity gets unpublished.
Comment #17
vollepeer commentedFound the solution to the problem with the host entity being unpublished. In the function paragraphs_form_submit(), the call of the save() method has to have parameter one set to TRUE ($skip_host_save). Will attach new patch ASAP.
Comment #18
james.williamsHere's a re-rolled version of the patch from comment 11 above, since the access callback on the separate form page no longer worked after the latest commit to paragraphs, which stopped loading host entity details.
I did not make any changes to the template, since I was trying to be conservative in what I changed, and it's quite possible for themes to do that themselves. I could believe I'm being too conservative there, I'm not sure.
Comment #19
vollepeer commentedI created a new patch starting from comment 18, including the fix discussed in comment 17.
Comment #20
vollepeer commented@james.williams, I think you re-rolled from the wrong comment: comment 12 has the addition of title_prefix and title_suffix in the paragraphs-item.tpl.php file. This is necessary for the contextual links to work. I created a new patch containing the changes made in comment 12.
Comment #21
vollepeer commentedI'm am currently working on extending the patch to also support the deletion of separate paragraph items + insertion of new paragraphs in between existing paragraphs using contextual links. Will post these extensions to the patch ASAP.
Comment #22
steven jones commented@vollepeer I think @james.williams was going for minimal UI changes, as we're adding the contextual links in a theme, but yeah, you're right, this really should be in the module itself, especially as there's a way to hide the links anyway on each field's config.
Additional contextual links for delete and insert sounds amazing!
Comment #23
amoebanath commentedIt makes sense that if, when our host entity has revisioning enabled by default, we save a new revision of our host entity. To make that happen, we need to replicate the 'Create new revision' option as used on the Node form, set its default value according to our host entity's default value, and then make sure that we revision accordingly.
Here's a patch that achieves that :)
On the way, I've also corrected some whitespace and changed one of the access callbacks to use the new paragraphs_paragraphs_item_access check.
Comment #24
vollepeer commentedI have finished a first (highly experimental) addition to the patch allowing both deletion + adding paragraphs (like described in comment 21). The new patch does not contain yet the changes from comment 23 -> TODO.
The code still needs a lot of refactoring and testing at this point, but it would be nice to get some early feedback already about the concepts in there.
Comment #25
rgpublicCaveat emptor: I'm no Drupal expert... but I was a bit impatient so I just gave patch #24 a roll. I found the following problems:
1) Some content on my website vanished as soon as I enabled the patch. I found this is due to "if (!isset($item[0]['value']))" in "paragraphs_field_prepare_view". Some of my items only have $item["und"][0]["value"] for some reason. Couldn't figure out if this is due some i18n stuff or due to some paragraphs contain image fields or even sth. else. Perhaps you might want to reconsider this check, though.
2) I somehow cannot create new paragraphs. The whole process (contextual menu => Following page appears => Save => Back to original page) works but no new paragraph appears :-(
3) The following warnings appear on every page:
Notice: Undefined property: ParagraphsItemEntity::$type in paragraphs_contextual_links_add() (Zeile 1801 von /var/www/developer/epos-services.com/htdocs/sites/all/modules/paragraphs/paragraphs.module).
Warning: Invalid argument supplied for foreach() in paragraphs_contextual_links_add() (Zeile 1802 von /var/www/developer/epos-services.com/htdocs/sites/all/modules/paragraphs/paragraphs.module).
Comment #26
vaccinemedia commentedTried the patch #23 - so far so good! Getting an error on the field manage display though:
Notice: Trying to get property of non-object in paragraphs_paragraphs_item_access() (line 264 of /var/www/act/www/sites/all/modules/contrib/paragraphs/paragraphs.module).
Notice: Trying to get property of non-object in paragraphs_paragraphs_item_access() (line 282 of /var/www/act/www/sites/all/modules/contrib/paragraphs/paragraphs.module).
Notice: Trying to get property of non-object in paragraphs_paragraphs_item_access() (line 287 of /var/www/act/www/sites/all/modules/contrib/paragraphs/paragraphs.module).
Notice: Trying to get property of non-object in paragraphs_paragraphs_item_access() (line 288 of /var/www/act/www/sites/all/modules/contrib/paragraphs/paragraphs.module).
Notice: Trying to get property of non-object in paragraphs_paragraphs_item_access() (line 299 of /var/www/act/www/sites/all/modules/contrib/paragraphs/paragraphs.module).
Notice: Trying to get property of non-object in paragraphs_paragraphs_item_access() (line 264 of /var/www/act/www/sites/all/modules/contrib/paragraphs/paragraphs.module).
Notice: Trying to get property of non-object in paragraphs_paragraphs_item_access() (line 282 of /var/www/act/www/sites/all/modules/contrib/paragraphs/paragraphs.module).
Notice: Trying to get property of non-object in paragraphs_paragraphs_item_access() (line 283 of /var/www/act/www/sites/all/modules/contrib/paragraphs/paragraphs.module).
Comment #27
screon commentedI think this would be great for the Drupal 8 version as well. Content editors who usually work from the front-end of a website (using contextual links or quick edit), are somewhat stuck with Paragraphs as they have to edit the page and dive into a (deeply) nested paragraph to alter a single line of text.
It would be much easier if they could just edit a certain paragraph directly from the front-end. Either through contextual links and seperate edit pages for paragraphs, or through an improved quick edit (there's already an issue for that I saw).
Comment #28
rgpublic(+1) I'm currently working on our first D8 website for a customer and the experience so far has simply been nothing but great. Almost no bugs, decent object orientation, many things that IMHO were not so great in D7 (like menu system etc) are solved and/or cause much less unwanted surprises than in the previous version. Big kudos to everyone involved!
The only thing I'm really missing very, very much is the separate item editing patch. I think this should even be a default feature one day without any patching. It is so important if you want to offer your customers (i.e. content editors) a usable UI. Keeping my fingers crossed this will be implemented soon...
Comment #29
loominade commented#24 works flawless. But I think Edit should go first, and Delete after. Like in contextual links for nodes.
Comment #30
reekris commented+1 For getting this into the Drupal 8 version as well, it's a great feature!
Comment #31
Alexandre360 commented#24 doesn't work for me.
I have a quite complex paragraph system with paragraphs inside paragraphs, don't know it it can enter into consideration but I don't see any contextual links.
Comment #32
georgiana.albu commentedI can confirm that patch #24 works.
However "Add paragraph" contextual links do not show up if no paragraph bundles are selected. The quick fix is to select any/all the paragraph types in the paragraph field settings. The following code covers this case. I can update the patch if needed.
Comment #33
mihai_brb commentedWe should also fix this :
with something like this :
But we also have this https://www.drupal.org/node/2452675
So depending on how language is handled, we'll have to correctly set the paragraph field values.
Comment #34
james.williamsA merged patch of the patches in comments 23 and 24 is coming very soon, I'm told, so work can pick up again, to incorporate changes since then. Go Nathan! ;-)
I also just wanted to point out that the patch in comment 23 has some code specific to nodes, whereas other revisionable entity types (e.g. beans) should probably be handled too. We could have some more entity-type-generic code that handles that...
Comment #35
amoebanath commentedHere's the aforementioned patch, smushing #23 and #24 together. (Interdiff based from 20 + 24, adds 23)
Hopefully I'll have time to make some of the other suggested changes soon, too.
Comment #36
amoebanath commentedHere's #35 with the additions suggested in #32 and #33.
Still need to handle #33 super-properly though.
Comment #37
miro_dietikerThat's a huge amount of code ad the paragraphs widget are already so much spaghetti due to all the variants and settings. I would prefer to maintain this complexity in a separate module if it is easily possible?
Comment #38
james.williams@miro_dietiker - I see your point, yes, it would be ideal to keep it simpler & more maintainable. If I'm following what you said, I think you feel there would be too much complexity introduced to the field formatter? (There are no changes to the field widget form, so I'm guessing that's what you meant by 'widget'? The following may be going off in the wrong direction if I've misunderstood you, sorry!)
However, the original intention of the ticket appeared to be just allowing editing paragraphs in their own form, via contextual links. Doing just that would also achieve feature parity with field collection. That's not worth doing just for the sake of it, but it is well worth doing given how paragraphs are being used in the real world; as individual building blocks, for example (among many others):
http://www.webwash.net/drupal/tutorials/how-create-powerful-container-pa...
https://www.computerminds.co.uk/drupal-code/building-site-content-paragr...
https://www.commercialprogression.com/post/paragraphs-are-drupals-answer... (which even refers to a separate paragraphs_formatters module
So that in itself would be a very strong piece of functionality to have in core paragraphs. That corresponds to what was done in the patch in comment 23.
The patch in comment 24 added functionality for inserting paragraphs in-place, which is where the complexity to the formatter was introduced. I would suggest that that part, as useful as it is, is the part that may be better to keep out of core paragraphs, keeping that more maintainable. That is very useful functionality, but goes above & beyond the original intention of this ticket and beyond feature parity with field collection. The patch in comment 24 also allowed deleting paragraphs in-place, which is much simpler, doesn't involve changes to the formatter, and is also supported by field collections, so I'd suggest having that in the core of paragraphs.
So, in summary, what about having contextual links & forms for editing & deleting paragraphs in the core paragraphs module? Then the inserting paragraphs in-place functionality could go in a separate module (perhaps the paragraphs_formatters module linked to above, if that got moved onto d.org)? That ensures the key functionality is added without introducing further complexity to the already-complex part of the module that you were concerned about.
What do others think? I don't want to just be suggesting purely due to my own interest & use case, I hope it's a sensible suggestion for everyone! (And to allow this issue to advance rather than getting stuck on trying to do everything, as it already covers more than one piece of functionality.... maybe a different way forward would be to split out each part of functionality into child tickets and decide which parts should go into core paragraphs separately?)
Comment #39
amoebanath commentedOops, broke a couple of things in that merge. This should rectify things.
BUT it would be good to clarify #38 before moving on too much further.
Comment #40
strykaizerMy 2 cents, I agree with #38
The extra frontend functionality (adding new paragraphs) should not be in this issue, as this is other functionality than this issue describes.
Better create a separate issue for that patch which could depend on this issue, or create a separate module if maintainer thinks its out of scope.
Comment #41
mihai_brb commentedRegardless of how issue queue is organised, I just want to point out the huge impact this features will have on content editors.
As soon as we'll have a direction, code could be better organised. For example all this new forms should be included in separate file.
Comment #42
james.williamsThanks both for your responses. It's been two weeks, so I've made a start to get this unblocked. #2715833: Delete/insert paragraphs with contextual links has been opened to represent the good work started by vollepeer from comment 24, in order to restrict the spaghetti complexity of the change. As suggested in comment 38 above, this will then allow the original intention of this ticket to be advanced here instead, without the 'above & beyond' of handling inserting/deleting paragraphs. So the basics of contextual links and editing paragraphs on a separate form can be handled here, which does not add to the complexity of the existing formatter widget. Hopefully that addresses miro_dietiker's concern in comment 37!
I've updated the issue summary too to reflect the current state of things, including a list of things to address that have been raised. So, patch to follow here, based on the one from comment 39, with all other concerns raised so far included, but now keeping to the original issue.
Comment #43
amoebanath commentedOK, here's a revised patch, which:
Things remaining:
Comment #44
amoebanath commentedComment #45
amoebanath commentedComment #46
bjlewis2 commentedSetting to "needs review" so it'll go through patch review.
Comment #47
miro_dietikerDidn't we have this discussion recently in a different issue around 8.x-1.x?
Comment #48
james.williamsTotally fair enough. The work that's been done for 7.x-1.x has been great so far, it's nearly there so just needs a little push to get over the line, it's not far off.
So as we (Nathan & I) are working on it here anyway, we'll look to finish the 7.x patch, even with the expectation that it won't be committed to the module, but that it ensures we're all happy with the workflow/UX/approach, as much of the work that's been done so far is already in use on production websites anyway. That also ensures a fully working patch will be available sooner, as it will take longer to make progress for 8.x.
Then once the 7.x patch has been finished off, all our effort can go into making an 8.x version.
Unless anyone else has resource to get going straight away on 8.x of course, as they would be very welcome! We just haven't had too much 8.x experience yet, so are trying to limit our unknowns where we can. We're looking forward to jumping in!
Comment #49
amoebanath commentedNested paragraphs working OK with patch #43
Crossed off some to-dos from the summary.
Comment #50
jonathanshawI think what @miro_dietiker might be remembering in #47 is that there is already a 8.x paragraphs_edit contrib module which aims to offer contextual links for editing. The module's page does not explain its purpose, but we discussed it with the maintainer here: #2698449: Missing save button in quick edit
Comment #51
amoebanath commentedOoh! So, could paragraphs_edit (once standardised and tested etc.) be included in paragraphs module as the D8 solution for this issue? Where/how might we best discuss that?
Comment #52
jonathanshawA good start would be for someone to document how to use paragraphs_edit. The creator gives a hint about how the module works in the issue i linked to, but there's no full explanation of features or setup and no screenshots.
Comment #53
miro_dietiker@amoebanath and we will not simply include the module paragraphs_edit. If you read the individual related issues, you see that we need clean minimalistic solutions per problem we want to solve. We need to agree about each approach and implementation. And we need nice test coverage for everything we add.
This is a lot of work, but UX and UI improvements will be the major focus once a first stable release is out. I'm pretty sure we will progress quickly with all the help from the community. :-)
Comment #54
james.williamsHi @miro_dietiker - thanks for the clarification, that's understandable. So even if we did get to having a completed patch for D8, with full test coverage, would you actually want any of this functionality in the 'clean minimalistic' core paragraphs module? If not, then we're clearly heading in the wrong direction and we need to move our focus over to paragraphs_edit anyway.
Sorry that we've skipped that more conceptual discussion around what the vision for paragraphs is and jumped straight into just trying to implement the ideas! Is this the place to have that discussion, in order to agree about approach and implementation?
Comment #55
miro_dietikerBy reading the title, you ask for support of contextual links. Also i see the patch is limited to the relevant pieces and not a full clone of the paragraph_edit complexity.
Note that i won't commit this to Drupal 7 as i'm not maintaining that branch. You would need feedback from jeroen.
For Drupal 8, i would like to add an equivalent as part of paragraphs main module once we have it and test coverage is provided.
Comment #56
Alexandre360 commentedremove
Comment #57
Alexandre360 commentedwrong manipulation :/
Comment #58
iaminawe commented#43 did not apply cleanly to latest Paragraphs dev. I had to manually add in the code that did not apply correctly.
I have edited each paragraph field and made sure the checkbox to allow it to be edited via the contextual menu is enabled.
I checked that there were no required permissions, cleared my cache and ran update.php but I still dont see contextual edit links for each paragraph when I view a node on the frontend.
Can anyone tell if I am missing a step or has anyone had a similar experience trying to use this?
Thanks
Gregg
Comment #59
iaminawe commentedAfter replicating this on a clean drupal 7 site - it seems there are still issues with the contextual links showing on nested paragraphs and in particular when there is more than one paragraph field on a content type it seems to break. I had a column one paragraph field and a column two paragraph field and the items in column one showed contextual edit links while the items in column 2 did not.
Comment #60
vollepeer commentedDrupal 8 module (experimental) which allows managing paragraphs from the front-end: https://www.drupal.org/project/geysir.
Comment #61
grayle commented@iaminawe I had the same problem where the patch failed, and I manually patched it, and then I used replace on the '+'es which deleted a bunch of pluses it shouldn't have in paragraphs_contextual_links_view_alter changing several "+=" into "=".
For example:
$links[$class] += $item['localized_options'];
was turned into
$links[$class] = $item['localized_options'];
which of course meant the link didn't have a title or href attribute anymore so it never showed up.
Comment #62
nchase commentedPatch in #43 works.
Sidenode: When the paragraph is overwritten with entity-views-attach the dropdown let's only edit the view but not edit the paragraph. But other than set: great stuff! thx!
Comment #63
stevetweeddale commentedJust a re-roll of patch in #43 so it applies to the latest 7.x-1.x
On that, I notice this issue is still marked as for 8.x, but the patches are all for 7.x… am I missing something?
Comment #64
james.williams@stevetweeddale - see comments 47 & 48. Patches are supposed to be for 8.x, but the work had originally been done for 7.x and no-one has provided any attempt at a 8.x patch yet.
Comment #65
RAFA3L commentedThanks, this is really useful! I found this issue right now and this module came to my mind
https://www.drupal.org/project/ajax_form_entity
I like the approach of ajax_form_entity, is not a contextual link, work like a field so you can place the link anywhere in the display and edit inline without leave the page, I don't know if is possible and ease add Paragraphs to make it to work like Field Collections.
The patch #63 work fine at a glance
Comment #66
delacosta456 commentedhi @RAFA3L
Deos what you explain can work for D7 ? , with Panel ?
I have been finding since long time howe to , from a node display , add more item of paragraph without leaving the page ?
Something similar to what we do with comment ..
thanks
Comment #67
RAFA3L commentedHello @delacosta456, yes I use ajax_form_entity but with Field Collection, not with Panels.
Check this to add Paragraphs https://www.drupal.org/node/2715833
Comment #68
delacosta456 commentedhello @RAFA3L
thanks for that .. but still looks that the patch is not yet ok.. right?
thanks
Comment #69
delacosta456 commented@RAFA3L ,
Also i just found this too Field Collection Ajax but haven't tried it
Am i going to get the same Features as if i was using Field collection + Ajax form Entity
Comment #70
pascalmortier commentedSolution in progress :
https://www.drupal.org/node/2807125
Comment #71
RAFA3L commentedIf your paragraphs are multi language add this to show the fields in the current language when edit
Comment #72
nchase commentedlatest patch doesn't work for a paragraph that has its own tpl. The setting is available in the paragraph field settings but the gear icon simply doesn't appear when viewing the node.
Comment #73
8bitplateau commented@Nchase add to your template :
I use Display Suite pretty heavily, and like with the node template this has to be present to make them appear, might work for you too.
Comment #74
ludo.rI confirm #43 works for me using 7.x-1.0-rc5
Comment #75
coaston commentedIs there any version for drupal 9? I need the same functionality there...
Comment #76
bluegeek9 commentedUnfortunately, Drupal 7 is End of Life and no longer supported. We strongly encourage you to upgrade to a supported version of Drupal.