Problem
When adding an existing ERR (paragraphs) field to a node or on a paragraph, the default widget is Autocomplete not Paragraphs.
This is different from when the ERR (paragraphs) field is newly created for that paragraph/node, in which case the widget is correctly the Paragraphs widget.
Cause
(according to #5)
ERR uses the property "default_reference_revision_settings" on the Entity Paragraph Annotations to pass these default settings when creating the field, it uses the function "getPreconfiguredOptions" on the FieldType to add those to the list. However, it does not store the selected preconfiguration when creating the field, so when you add that same field to another bundle, it does not know which preconfiguration you picked, and it also doesn't ask which one you want to pick. So then you end up with the same storage settings (as it does copy those), but with another widget (the default for that field type).
Solution
(according to #5)
1. Open a core issue about this.
2. Implement a quick workaround in some hook (if exists) while the core issue is being addressed.
Original report
Shouldn't the paragraphs widget be the default widget for a new Paragraphs field? Currently it's Autocomplete by default.
Perhaps this cannot be achieved given that #2430209: Create own fieldtype for Paragraphs was not adopted.
| Comment | File | Size | Author |
|---|---|---|---|
| #34 | interdiff-2668678-31-34.txt | 761 bytes | johnchque |
| #34 | make_paragraphs_widget-2668678-34.patch | 2.92 KB | johnchque |
| #31 | interdiff-2668678-25-31.txt | 1.66 KB | johnchque |
| #31 | make_paragraphs_widget-2668678-31.patch | 2.89 KB | johnchque |
| #25 | make_paragraphs_widget-2668678-25.patch | 2.93 KB | johnchque |
Comments
Comment #2
jeroen.b commentedIt should be the default widget. What versions are you using?
Results in the following form display:

Comment #3
jeroen.b commentedPicture upload, can't reference external images.
Comment #4
jonathanshawI was referring to the form display widget. I had some trouble reproducing, but I've got it now:
the issue only occurs when adding an existing ERR (paragraphs) field (to a node or on a paragraph). It doesn't happen when the ERR (paragraphs) field is newly created for that paragraph/node.
Structure->Manage content type->Basic Page->Manage fields
Add field -> Existing field -> Entity Reference Revisions field_paragraphs_demo
Manage form display
Tested today on simplytestme with D8-1.x with paragraphs demo module.
Comment #5
jeroen.b commentedAh yes. I think I remember that.
This is a very hard one.
ERR uses the property "default_reference_revision_settings" on the Entity Paragraph Annotations to pass these default settings when creating the field, it uses the function "getPreconfiguredOptions" on the FieldType to add those to the list. However, it does not store the selected preconfiguration when creating the field, so when you add that same field to another bundle, it does not know which preconfiguration you picked, and it also doesn't ask which one you want to pick. So then you end up with the same storage settings (as it does copy those), but with another widget (the default for that field type).
I think it's best to open a core issue about this, as it's generally odd behavior to experience.
However, we could implement a quick workaround in some hook (if exists) while the core issue is being addressed:
(warning: this code is kind of pseudo-code)
Comment #6
jonathanshawUnfortunately I don't understand Entity API and its terminology enough to be able to check if that core issue already exists, and create it if it doesn't. Sorry not to be more help with that!
Comment #7
jeroen.b commentedI'll check it out tomorrow.
Comment #8
jeroen.b commented-doublepost-
Comment #9
jonathanshawComment #10
berdirAfter the composite changes, we should try to not only default to our widget, we should hide the other widgets completely, since they must not be used anymore.
While doing so, we should also disallow creating entity reference fields to paragraphs since that will not work anymore either.
I guess we have to do form alters on the relevant core forms.
Comment #11
johnchqueComment #12
johnchqueAdded first try, hiding the other widgets.
But not sure about
It means that we should not be able to add entity_reference fields in a paragraph type? or that we should not be able to reference a paragraph type with a entity_reference field?
Comment #13
berdirYes, it means that if you click on Other.. for a normal reference field, in the select that you get, Paragraph should not be listed as an option.
Comment #14
johnchqueAdded second hook for hiding Paragraph as an option to be referenced by a entity_reference field. Not really sure how to implement a presave hook for set the default widget. Is it really needed?
Comment #15
miro_dietikerFrom Berdir: Missing t() since the key is translatable...
Note that for me without applying this patch, if i select adding a new ERR field to Paragraphs, i get the Paragraphs widget automatically selected.
Comment #16
johnchque@miro_dietiker yes, when you create a new ERR field the widget by default is Paragraphs but when you use it somewhere else it is set to Autocomplete. #4 explains the situation better.
Comment #17
miro_dietikerFinally, what #4 describes is a core bug.
Core in FieldStorageAddForm only merges in submitForm the preconfiguredOptions, specifically of entity_form_display (Paragraphs provide, Paragraph.php, default_reference_revision_settings).
Please open the issue and refer to it in the workaround code comment.
Also workarounds like this need tests.. :-)
Comment #18
berdirThis needs some comments to explain what we're doing and why we're doing it.
'Content' is a translatable string, you need (string) t('Content') in the key.
Also, the loop is unnecessary, you can just unset() the key directly.
This comment isn't very clear yet. What's not supported is entity reference fields *to* paragraphs.
Comment #19
johnchqueChanges made based on comments above. :)
Comment #20
johnchqueTests added. :)
Comment #24
berdirSimilar to below, I think we can simplify this, just loop over the keys you want to unset and unset them.
Also, $key is a bad variable name, use $field_name or so instaed. Same for $value, which you don't use, you could use array_keys($field_definitions) to avoid an unnecessary variable.
Also missing the core issue that we identified above.
Comment #25
johnchqueChanged as it should. :)
Comment #29
johnchqueCreated core issue. #2717319: Provide better default configuration when re-using an existing field
Comment #30
tduong commentedLooks good. Maybe just a couple of nitpick:
// Loop over ERR field's display options with paragraph target type.
Probably better above the first foreach loop.
// Entity Reference fields are no longer supported to reference Paragraphs.
Comment #31
johnchqueComments changed. :)
Comment #32
tduong commentedYep, looks great! :)
Comment #33
miro_dietikerContinuing to nitpick.. :-)
For instance you comment being looping, but not why.
We are not really testing that it is "not supported". We are more testing that the unsupported situation can not be selected.
Comment #34
johnchqueThanks for the feedback. :)
Comment #35
berdirLooks good to me.
Comment #37
miro_dietikerThx, committed. :-)
Comment #38
jonathanshawI created a new issue #2724213: Widget is wrong when adding existing ERR field to Paragraph for this, but @yongt closed it as a duplicate of this, so I'll reopen this instead.
The result of this patch, the current state of the module, is that placing an existing ERR field on a paragraph type produces a result that is badly broken, but not obviously so.
More specifically,
- the widget is actually set to ER autocomplete by default
BUT
- the widget claims (on Manage Form Display) to be set to Paragraphs.
I understand it's easy enough to fix this by setting the widget to hidden and back to Paragraphs, and that there is a core issue pending that may address this one day, but my question is:
are you sure you want to ship the stable release of the module in this condition?
I just wanted to be sure the maintainers understood that the "workarounds" discussed above were only partial.
Comment #39
berdirNo, he didn't close it as a duplicate of this issue.
He closed it as a duplicate of the still open core issue: #2717319: Provide better default configuration when re-using an existing field.
Yes, we are aware of the problem, but the problem is in core, and we don't think this is important enough to add workarounds in paragraphs. We will fix the core issue instead.
Comment #40
johnchqueAnd also you don't even need to set it as hidden and back again to Paragraphs, you can just re save it.
Comment #41
jonathanshawGreat, thanks for the reply, I just wanted to be sure.
Comment #43
benjifisherComment #44
benjifisherThere is now a patch to try out on #2717319: Provide better default configuration when re-using an existing field. Once that issue is resolved, re-using a paragraph field should be a lot easier.
Comment #45
gthibert commentedComment #46
mahtabalam