Problem/Motivation
With the implementation of #2843917: Implement Library entity type. Re use paragraphs is now possible. The first implementation only adds that to new created paragraphs but we should also allow the conversion from a normal paragraph type to be re-usable.
Proposed resolution
Add a button in the widget that allows to the paragraph to be added to the library. Discuss how to deal with paragraphs that are used more than once and are removed from the library. We can deal with converting a lib item back to paragraph in a follow up.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #52 | interdiff-2847053-51-52.txt | 946 bytes | toncic |
| #52 | convert_a_normal-2847053-52.patch | 8.44 KB | toncic |
| #51 | interdiff-2847053-43-52.txt | 685 bytes | toncic |
| #51 | convert_a_normal-2847053-51.patch | 8.61 KB | toncic |
| #43 | interdiff-2847053-40-43.txt | 4.8 KB | toncic |
Comments
Comment #2
miro_dietikerParagraphs Collection it is!
And it's the instance that is converted, not the type. And not sure if this really needs determination by type.
Comment #3
berdirAnd also not sure about supporting converting back in the first issue, that can easily be split up.
Comment #4
primsi commentedComment #5
primsi commentedWIP patch. Missing tests and probably something else.
One question I had is what to use as the title for the library item? Created from paragraph + date. Or should we move away from the approach I took (add the link to the drop button) and have a separate button + text field for creating the library item?
Comment #6
johnchqueHmm both approaches sounds nice, but if we add a text field for naming the library item, might be kind of cluttering the UI.
I would vote for using create from paragraph + date.
But we recently added the label method to the paragraph entity, what if we use that one?
Comment #7
primsi commentedWorked a bit more on that. Still needs tests.
Comment #8
toncic commentedI will continue with this one.
Comment #9
toncic commentedIMHO I don't like how we are making title. Is not very readable and doesn't provide information about paragraph.
Providing screenshot.
Any idea how we can improve this?
Comment #10
berdirYeah, we already discussed this before...
My idea was to include a confirmation step that contains a label text field that the user can or is required to fill out? We could possibly even use the closed summary as a better default value, limited to the first N characters.
Might not be really possible to actually do that without changes in paragraphs, so we could make a folow-up for that. People tried to refactor the different paragraph states into a pluggable system before, we might actually have a use case for it now :)
Comment #11
miro_dietikerYeah, so you would prefer a "multistep" form inside the paragraph?
So when choosing the action to convert it to a library item, we show a form with title (and the other metadata fields?)
And then on confirmation, we save, connect the new paragraph with the library wrapper?
So yeah, we can simply make it work with a default title, preferrably from the collapsed summary and then get into all the complexity in follow-ups. Thus, i think we should create the follow-ups for this plan and update the parent meta issue.
Comment #12
berdirYep, that's my suggestions, similar to the delete -> confirm delete form.
Comment #13
toncic commentedCleanup patch, fixing small bug and added tests.
One more stuff here, do we want to avoid converting empty paragraphs, e.g. text paragraph without text, or images without image?
Created follow-up: #2856568: Allow editing label (title) while converting paragraph item to library
Comment #14
miro_dietikerNo special treatment for empty paragraphs. It would need hardcoded special treatment and create even UX problems..
Comment #15
toncic commentedThan, this is ready for review.
Comment #16
primsi commentedI think we could improve the test a bit by adding text to the text paragraph we create and then when the node is saved assert that we see the same text we added there.
Comment #17
toncic commentedSorry, I totally forgot on that part.
Comment #18
miro_dietikerThis is not a proper condition. You need to check if we are in a paragraphs widget. The code would also apply on an entity reference field widget pointing to a paragraph target (although people should not do it)...
Also i'm missing a summary update and the issue creation of the "and backwards" step.
Since this conversion is that important, we can get this in with an alter. But we need a high priority follow-up:
Paragraphs should make it easy to register operations on that button, for instance by triggering a specific operation alter hook.
This code complexity to just register an operation is leading us to total eclipse.
We should wait with the issue implementation until we have a decision in markcarvers refactoring proposal
#2854444: Refactor field widget code to reduce duplication and make theme abstract
So before further coding, please help with issue management.
Comment #19
berdiryes, $context contains the widget object, so we should be able to check that is our widget. And I guess only the new experimental, we don't want to mess with class as its structure will eventually be different.
not namespaced.
the items_count line is strange. also not sure about the original deltas logic.
didn't we want to use the closed summary, not seeing that anywhere? (yes that is currently on the widget class where it can't be reused I guess, that's needs to be move somewhere else)
My suggestion for the default label would be "$type: substr($summary, 0, 50)"
Comment #20
toncic commented#3. Is working fine. We are exporting current paragraph and on the same place we add item from library and we are not adding one more new paragraph after exporting.
#4. This part is a little bit tricky. We can not use summary for label, summary function is in ParagraphsWidget class and we can not access from LibraryItem. One solution is to make function in ParagraphsWidget static and another one is to add summary function in ParagraphInterface and overwrite in Paragraphs. I think the second one is better approach because summary should be part of paragraph not ParagraphWidget.
This part with adding summary in Paragraph we can do in follow-up and after that we can change that label use part of summary in this #2856568: Allow editing label (title) while converting paragraph item to library
Comment #21
berdirYes, agreed with moving it to a method on the entity. That makes sense to me.
Lets open an issue for that and work on that now, I think we should probably include that in a first patch for this feature, Miro also said that above, although he probably didn't except that this also needs a paragraphs change.
Comment #22
toncic commentedCreated new issue to move summary into paragraphs #2857112: Add summary method into paragraph entity. This is is kind of postponed until we finish summary issue.
Comment #23
primsi commentedThis also needs a follow up for the conversion in the other direction if we are not doing it here.
Comment #24
miro_dietiker@toncic and the title still proposes both direction. Needs title + summary update. Please always do that first.
Comment #25
primsi commentedPostponing for now until #2857112: Add summary method into paragraph entity is in.
Comment #26
primsi commentedComment #27
miro_dietikerI can't see the paragraph reverse issue linked or created?
Comment #28
toncic commentedAfter committing this #2857112: Add summary method into paragraph entity we can continue with converting paragraphs item into library.
Comment #29
toncic commentedChanged to use part of summary for label. Rebased and fixed test failing.
Comment #31
toncic commentedRerolled and fixed test failing.
Comment #32
primsi commentedWe could use a ternary operator here.
isset($widget_state['paragraphs'][$context['delta']]) ?: FALSE;
Just noticed in the mocks that the wording is "Add to library". I think we should use that.
This was copied from the duplicate feature. Should we really update the count? Because we are replacing here, not adding.
Extra new line
Comment #33
miro_dietikerI think this heavily conflicts with the widget refactoring in #2854444: Refactor field widget code to reduce duplication and make theme abstract
That should make an extensibility point much easier.
We should not add a form alter here. Instead the widget should offer an extension point or a hook an event or a behavior plugin interface callback so everyone can register actions to these buttons.
This extensibility point us super important in the evolution for Paragraphs. Let's create a high priority issue there
Comment #34
toncic commentedImplemented comm #32 and created issue in paragraphs which @miro_dietiker mentioned in #33. #2862428: Add hook function for widget
Comment #35
primsi commentedPostponing this then.
Comment #36
miro_dietikerNow we have a hook. Plz reroll and use that extensibility point instead of the alter.
Comment #37
toncic commentedRerolled patch and changed to use hook function from paragraphs.
Comment #39
toncic commentedFixing test failing.
Comment #40
toncic commentedThe first interdiff is wrong. Here is a patch.
Comment #41
miro_dietikerFirst dashes, then conversion to underscore? :-)
Comment #42
berdirWe do that a lot in paragraphs widget,
taht's a strange weight, usually those numbers are a lot smaller.
this needs paragraphs_collection prefix.
this is not the add_more button.
use ParagraphsWidget::class
uhm, what? we're not inserting something new, we replace?
does this ensure that the paragraph is saved, including changes?
unrelated leftover?
you don't need to check strlen() yourself, Unicode::truncate() does that.
isn't getType() the machine name? we need getParagraphType()->label() or so.
so we are testing for a new entity, that's good.
I think we should also cover converting an existing paragraph on an edit form and changing an existing paragraph and then converting it to a library item at the same time.
lets make sure we also assert the label of the library item,.
Comment #43
toncic commentedAddressed comm #41 and #42.
@Berdir:
1. I think we should check '#weight' in $links in PargraphsWidget class, and give the similar number, so this seems OK.
5. Yes, we are replacing.
6. I think so. Also Added some test for this.
Comment #45
toncic commentedComment #50
primsi commentedI've tested this manually and it seems to work fine. I opened two follow ups:
#2867297: Paragraphs library table expands with content
#2867299: Improve library item widget item experience
Let's wait for #42.5 if we meant to add, not replace.
Comment #51
toncic commentedBecause we are replacing element I changed comment.
Comment #52
toncic commentedChecked with @Berdir about #42.5, we had some unrelated lines, so removed it.
Comment #54
primsi commentedCommitted, thanks!
Comment #56
vood002 commentedHi, I'm curious about this one...it looks like most of the patch is on the core paragraphs_library module, but it belongs to the paragraphs_collection module. Is there a chance this functionality could be applied to paragraphs? I imagine there would be interest, I'm interested for one, and don't run paragraphs collection due to the strict "no production" warning and the fact that it wont install for me b/c I already have a paragraph type called "container".
Thanks!
Comment #57
berdirI don't know what you mean, this was committed to paragraphs_collection and then moved into the paragraphs project. It's opt-in per paragraph type, so make sure you allow it for the paragraph types where you want to use it.
Comment #58
vood002 commentedThank you for the response @Berdir. I was confused by this being an issue on paragraphs_collection, I can confirm that I was able to add preexisting paragraphs to the library without the paragraphs_collection module, thanks for the nice addition!