Problem/Motivation
Due Paragraphs are not re usable, we cannot set a default value for a Paragraphs field thus default values are being removed in #2769857: Disable default value of ERR field but user should be able to set a default value to a Paragraphs field.
Proposed resolution
Allow to select a default paragraph type that will be shown for an empty field.
Upload a patch.
Provide test coverage.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#41 | interdiff-2770507-37-39.txt | 3.3 KB | toncic |
#41 | allow_to_select_a-2770507-39.patch | 15.13 KB | toncic |
#37 | interdiff-2770507-36-37.txt | 1.73 KB | toncic |
#37 | allow_to_select_a-2770507-37.patch | 13.91 KB | toncic |
#36 | interdiff-2770507-32-36.txt | 7.51 KB | toncic |
Comments
Comment #2
miro_dietikerYeah, that would be a nice UX improvement!
Comment #3
John Pitcairn CreditAttribution: John Pitcairn commentedNot sure if it is possible, but it would be a great UX improvement to be able to set a multiple-item default value, so that (for example) a standard "create page" form can be pre-populated with ready-to-edit paragraph:image and paragraph:text forms.
Comment #4
toncic CreditAttribution: toncic at MD Systems GmbH commentedAdded select options and raw in summary.
Stopped to work on this because the HEAD are failing.
Comment #5
miro_dietikerThe widget label and description are repeating and lacking and don't help users understand about its purpose.
Also can't see any test coverage.
BTW for more complex cases such as prepopulating multiple paragraphs, we will have a library and a template, see references.
Comment #6
toncic CreditAttribution: toncic at MD Systems GmbH commentedTried to add paragraph but not success. @yongt9412 should apply patch to debug.
Comment #9
toncic CreditAttribution: toncic at MD Systems GmbH commentedShowing default paragraph type and wrote test coverage.
But still we need first to fix HEAD fails before this issue.
Comment #12
miro_dietikerWe need to careful: Changing the allowed paragraph type could cause this setting to be out of sync. How are we dealing with this situation?
Comment #13
Ginovski CreditAttribution: Ginovski at MD Systems GmbH commentedUnrelated change
Use $this->t()
Had a discussion with @toncic, there are more options to fix this:
When trying to change allowed type (which is set as default)
1. Update the default settings and set default paragraph type to 'None'.
2. Warn the user that the paragraph type is set as default and to change it there first.
Comment #14
toncic CreditAttribution: toncic at MD Systems GmbH commentedFixed test fails and added check if type is allow before showing paragraph.
Comment #15
toncic CreditAttribution: toncic at MD Systems GmbH commentedComment #18
toncic CreditAttribution: toncic at MD Systems GmbH commentedFixing test failing and extract code for testing in new method in ParagrapsAddModesTest class.
Comment #19
toncic CreditAttribution: toncic at MD Systems GmbH commentedCleaning patch.
Comment #20
drobnjak CreditAttribution: drobnjak at MD Systems GmbH commentedLooks good to me.
Comment #21
toncic CreditAttribution: toncic at MD Systems GmbH commentedComment #22
johnchqueEverything fine but here would be nicer to show the label of the Paragraph type and not its machine name.
Change this variable to be $entity_type_manager
After that looks fine to RTBC it. ;)
Comment #23
toncic CreditAttribution: toncic at MD Systems GmbH commentedOk. now we want to remove button if is single type allowed and remove description from summary if we don't have default_paragraph_type.
And of course test coverage.
Comment #26
miro_dietikerThis logic should only be triggered for new host entities, not for updates.
Make sure to test cover this, so also do an edit and verify no extra paragraph is added.
This should not be needed. The getDefaultParagraphTypeMachineName should already check for allowed ones and never return invalid values.
No public, protected if we need it for our widget only.
We should avoid '' and instead refer to NULL for emptyness.
So even if the selection is "- None -" we propose a default machine name...
Comment #27
miro_dietikerThere are some UX problems.
I first thought: Yeah, let's always add a default paragraph it only one type is selected and even remove the setting.
But for some optional rarely used paragraphs, this is bad UX. Also we have some other problem (see below).
So we could make auto-add a default setting. But if explicitly set to none, we need to respect that too.
Now the harder part:
If a paragraph is prepared and added by default and the user doesn't fill out any of the fields, we now still save it with empty values.
This is an unexpectedly complex problem. We would need to flag auto-added instances and check the visible fields for emptyness. If all are empty (and it has no children), we could skip creating it. But this check needs to be limited to the auto-added since other paragraphs could have no field at all. For some intentionally added paragraphs, this might not be true and all fields could be empty.
We can put this whole problem into a follow-up. :-)
Comment #28
toncic CreditAttribution: toncic at MD Systems GmbH commentedAdded items_count instead to check if is new host entity, but still not sure what we want to do with setting. I discussed shortly wit @Berdit and we should continue tomorrow. Test is still failing.
Comment #31
BerdirYes, the special case for single type is tricky. Might be a good reason to keep that to the separate issue for this that was created for it. I can see that there might be a use case to not have a default even for single type use cases. But it prevents us from hiding the setting completely for that case and also means we either need to force users to explicitly select the default always (then we can drop the code for this completely but it is more work and gets us further away from the field_collection default behavior) or we need to be able to differentiate between "user didn't decide anything explicitly, so apply single-type default" and "user explicitly opts out of default type". So we need a _default and _none special options.
Best option might really be to drop that part of the logic here and discuss in #2829572: Allow default opt-out for single paragraph type.
5. The way it was implemented (didn't check last patch) was that we would default-select the type for single case and show that in the summary. and wouldn't show anything if none is selected for multi-type.
I don't think that this is a problem we need to solve. What we need to solve is to be able to expllicitly *remove* the default, so there is nothing shown, which I tested with @toncic and it doesn't work yet. This is very easy to solve on site building level. Make the field in your paragraph type required, then you force the user to decide between having a field and not, instead of saving something that is empty?
Comment #32
toncic CreditAttribution: toncic at MD Systems GmbH commentedAdded new function for testing that we can set default paragraph type to none. Test are failing because of limited number.
Comment #35
johnchquePlease use that new created method to fix the failing tests setting default_paragraphs as none.
Comment #36
toncic CreditAttribution: toncic at MD Systems GmbH commentedFixed a lot of test failing, there is one more in
ParagraphsFieldGroupTest
function. Uploading patch that @yong9412 can test it localy.I'm continue to write test coverage for other functionality.
Comment #37
toncic CreditAttribution: toncic at MD Systems GmbH commentedAdded test for testing remove default paragraph type.
Logic for single type is not good here, but we deal to discuss that in related issue Add default paragraph for single paragraph type.
Comment #38
miro_dietikerNo, we can discuss the single logic in the other issue.
remove commented lines.
missing t() and skip it as it's repetitive.
Still only add a new paragraph when creating a new host entity. We never want to have them added when editing existing ones.
Comment #39
DamienMcKennaAny chance of this being backported to D7?
Comment #40
BerdirI don't think we will work on a D7, but I would assume that it shouldn't be too complicated to do.
Tagging, so we can keep the issue open after commit.
Comment #41
toncic CreditAttribution: toncic at MD Systems GmbH commentedImplemented comm #38 and add test case for new host entity.
Comment #44
toncic CreditAttribution: toncic at MD Systems GmbH commentedComment #45
drobnjak CreditAttribution: drobnjak at MD Systems GmbH commentedComment #46
johnchqueJust tested again. Looks solid, I tested with two paragraphs fields in the same node, each one with its own default type. Works good. About the single case, we will need to define the behavior in #2829572: Allow default opt-out for single paragraph type. So...
Comment #48
miro_dietikerCommitted with a bunch of clean-ups.
Comment #49
Taran2LThis patch is creating other issue - I have an optional paragraph with a single possible type.
Now, on the edit form - I see a new empty paragraph added, even so I've selected not to add a default one.
Comment #50
Taran2LIssue lives here. This behavior is undesirable.
Comment #51
johnchqueI just tested and @Taran2L is right, even if none is selected the default paragraph types is still added. Let's fix that in the followup.