Problem/Motivation
It is possible to add all Paragraph Type bundles directly via /admin/content/paragraphs/add/default (ie, the Paragraph Library list) even if the 'Allow adding to library' box is unticked.
Eg, Paragraph Type bundle configuration here:

Yet still shows up:

Proposed resolution
Prevent using Paragraph Type bundles on the /admin/content/paragraphs/add/default page that are not allowed.
Remaining tasks
Provide patch (coming shortly).
User interface changes
The number of options on the "Add paragraphs library item" form will be reduced.
API changes
None.
Data model changes
None.
Release notes snippet
When adding a Paragraph Library item directly via the library, now only Paragraph Type bundles marked as 'Allow adding to library' will be allowed.
| Comment | File | Size | Author |
|---|---|---|---|
| #35 | respect-allow-adding-to-library-setting-3090101-35.patch | 5.03 KB | sergiur |
| #29 | interdiff_22-29.txt | 11.47 KB | abhijith s |
| #29 | 3090101-29.patch | 5.13 KB | abhijith s |
| #22 | interdiff_12_22.txt | 3.46 KB | bvoynick |
| #22 | paragraphs-prevent-adding-not-allowed-paragraph-type-bundles-to-library-3090101-22.patch | 7.81 KB | bvoynick |
Issue fork paragraphs-3090101
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
scott_euser commentedFirst shot at this. If this is in the right direction, happy to add tests to prove the issue and prove this resolves it.
Comment #3
scott_euser commentedUpdating issue description with screenshots.
Comment #4
berdirThe setting currently only limits the action on the paragraph edit form dropdown and not this.
I agree that the UI there is bad but I'm not sure we should be using the same setting for this.
Core kind of provides an API for this, we'd just need to expose the field settings form on the settings page and store it as a field config override.
Comment #5
scott_euser commentedThanks for the feedback. I'll see if I can find the UI and update the patch accordingly.
Should we also then rename "Allow adding to library" to something like "Allow adding to library from the paragraph edit form" as part of the scope of this or do you prefer as a separate issue? Ie, so that the label is not misleading as to its functionality.
Comment #6
berdirI'd be fine to change that here as well.
Note that there is no existing setting yet, you basically need to simulate what \Drupal\field_ui\Form\FieldConfigEditForm::form() does here:
And $this->entity is a field definition, so we need to get that from the base field definition, similar to content_translation_form_language_content_settings_submit(), $base_field_definition->getConfig(), then use that to build the form, apply the settings to it and then save it.
Not trivial...
Comment #7
scott_euser commentedThanks for the details. I am not fully sure if I understood, so just to double check the expected final outcome.
If you add an Entity Reference Revisions field type to a Node you get this configuration:

But at `/admin/config/content/paragraphs_library_item/fields` the reference field is not available to be configured.
So the goal here is to reproduce the above to allow the above URL to have an interface to be able to override
from paragraphs/modules/paragraphs_library/src/Entity/LibraryItem.php then:
Does that sound right or am I going down the wrong path?
Comment #8
berdirSounds right until point 1., 2., 3. :)
That functionality already exists, it's called base field overrides, it's a core config entity type, that is for example used by NodeTypeForm::save() to persist the default value for promote/sticky/status fields per bundle. And content_translation (as mentioned above) to store the translatability flag. you just get the field definition, call getConfig(), set the settings and you're good to go.
It's automatically loaded in and overrides the base field for a specific bundle (paragraphs_library currently doesn't have bundles, so it's just the default pseudo-bundle).
Comment #9
scott_euser commentedOkay great will follow those examples, thanks for all the pointers! This sounds like something I won't manage over a breakfast so I'll need to wait for my next free day on a weekend - might be a bit.
Comment #10
scott_euser commentedOkay I think I am getting there. The base field overrides don't seem to be affecting the library item add form though, but they are correctly exporting to
sites/default/files/sync/core.base_field_override.paragraphs_library_item.default.paragraphs.yml. I think I am clearing the correct cache but also tried a full cache rebuild in case with no joy.I have checked and the plugin ID I am overriding does appear to be an exact match to the selection handler on the library item add form, so I am not quite sure where I am going wrong.
(no interdiff as it is a completely different approach so 100% is different)
Comment #11
bvoynickThanks Scott, #10 was almost there.
The issue was using the bundle string 'default'. It looks like for bundle-less entities like paragraphs_library_item the entity type id must be reused again as the bundle id. Here's a modified version of the patch that addresses that and is working for me.
Additionally, vs patch #10 I fixed the call to the save() method so that it is called on the field configuration object rather than the field definition object. (I'm guessing you may have had that locally, but trying to save the form was hitting a fatal error for me with #10.)
I also added a task item for the main Manage Fields route, so that the task menu with the link to the Paragraphs field override will show up.
Comment #12
tostinni commented#11 works great, thank you.
I wanted to add a little more visibility to this feature so I added some documentation and took the liberty to change the links to the paragraph library setting screen (which is empty) to this new settings which is a little bit hidden right now.
Comment #13
inversed commentedLooks like the #12 patch no longer applies cleanly to the 1.12 version of the module. The #11 version still does, however.
Comment #14
stefan.kornI can also confirm that #11 works.
I would find it helpful if the views type filter for the paragraphs library would also leverage this new setting to limit the available paragraph types in the views filter. In order not to clutter this issue, I have created a new one for this at #3207764: Only show allowed paragraph types in the views filter.
Comment #15
mudassar774 commentedHi
The patch #11 applied successfully on D9.1.5 (theme Claro) but Allow Adding to Library setting inside Paragraph settings no more effective. The Only place to handle these setting will be
/admin/config/content/paragraphs_library_item/fields/paragraph-field-overridewith some visual issues too.Not sure if this is the intended behavior or this patch is not meant to be for D9 Yet
Thanks
Comment #16
stefan.kornIt is intended to have this now configured via /admin/config/content/paragraphs_library_item/fields/paragraph-field-override and not taken from the paragraph type library setting. See @berdir pointing that way in #4
Regarding visual issues, maybe explain or show a screenshot. Might be "Claro" related?
Comment #17
mudassar774 commentedhi @stefan.korn
about visuals After Ticking the checkboxes and save them, They remain unchecked visually, though settings applied and works, not sure if Claro issue or something else,
Comment #18
stefan.kornhi @mudassar774, not sure why you are seeing these special styled checkboxes. I tried with D9.1.6 and Claro and I got regular checkboxes that work like expected.
Do you have some customization or addons for the Claro theme?
Comment #19
esch commentedI tried applying patch #11 and it still does not limit selection of available paragraph types in list. I've only approved one paragraph type to be added to library but all the options are showing.
Enviro: Drupal 9.2.7, Claro 9.2.7, Paragraphs 1.12.0
Comment #20
pasqualleI can confirm #11 works, with the small "visual issue" on the /admin/config/content/paragraphs_library_item/fields/paragraph-field-override page, that the checkboxes remain unchecked after save.
There are some issues in the config
core.base_field_override.paragraphs_library_item.paragraphs_library_item.paragraphs.yml
negate and enabled should be boolean (true/false)
weight should be integer
seems like a missing config schema.
Tried to fix the config manually (and import), but the checkboxes are still unchecked on the admin page.
Comment #21
bvoynickComment #22
bvoynickHere's an updated patch that fixes the issues with saved config not being loaded back in properly for form building. It also fixes the issue pasqualle noted with config schema for this selection type not being used, by setting the handler for the overridden field config to be explicitly "default:paragraph" instead of just "default."
I also pulled in elements of #12, particularly the link to the field override route from the main item settings form. Other elements of #12 however did not seem appropriate to include. I don't know what plans there may be to add settings to the settings screen so I removed the replacement of links to that screen since it could still be important some day. I also removed the README text addition - documentation about promotion and this field override would be good, but as it is there is no documentation of promotion in general and I think that would be necessary context for a description of this field override to make sense.
Comment #23
NormySan commentedApplied the latest patch but the dropdown still shows all paragraph types even though only a few are allowed similar to #19. I would be happy to help out with this issue to get this done since it's kind of a dealbreaker for using the library.
Comment #24
bvoynickStrange, I'm not able to replicate the issue. I was using Gin for testing most recently, which is built on top of Claro - not impossible it's a very Claro-specific issue but seems unlikely.
Are you using any additional Paragraphs ecosystem modules, such as Layout Paragraphs?
The only ecosystem module I've confirmed this patch works with is Paragraphs Browser.
Comment #25
NormySan commentedI'm also using Gin and I'm on Drupal 9.3.7. I'm going to try to apply the patch again, could be that I did something wrong the first time around.
Comment #26
NormySan commentedThe latest patch works well. I misunderstood the functionality and thought that the checkbox "Allow adding to library" would also control the available options in the select list when adding a library item but I had to configure this through the field override settings.
Comment #27
c_archer commentedI can confirm the patch in #22 works well with the Gin theme. As per the comment on #26 I had to update the Add paragraph field at admin/config/content/paragraphs_library_item/fields/paragraph-field-override to only the show the ones users can add.
Comment #28
berdirThat's a setting :)
I don't see why this needs a new form, just put it in the existing empty settings form?
Comment #29
abhijith s commentedUpdated patch as per #28 suggestion.
Comment #30
abhijith s commentedComment #31
scottsawyerThis patch seems to be working well for me.
Restricted the library to a single bundle - only that bundle is able to be created.
Restricted to two bundles - only those two bundles are able to be created.
Comment #32
basvredelingThe "allow adding to library" function is really confusing as #26 mentioned already. I've opened another issue for that: #3319157: Rename "Allow adding to library" to "Allow promoting to library"
Patch in #29 works well.
Comment #33
mahdeAfter Drupal 9.5.5 upgrade I am not able to update the Paragraphs selections in paragraphs_library_item and nothing is saved. I am using Gin theme.
Comment #34
berdirI unfortunately got to another issue that added the save settings button/parent call first, so this needs a reroll.
Comment #35
sergiurRerolled to fix the conflict in LibraryItemsSettingsForm.php buildForm return
Comment #36
mahdeThanks for the patch but still when I need to update the excluded paragraph types (when I add or remove checkbox) and hit save then it's not saving.
Comment #37
banoodle commentedI tried path #35. It applies cleanly, but the problem originally reported in this task persists.
Comment #38
ninobrownh20 commentedPatch #35 is working for me to resolve this issue, as mentioned above, you need to make the selections for what paragraphs can be added to the library at admin/config/content/paragraphs_library_item I didn't experience any issue with updating the excluded paragraph types, everything saved as normal. Running Drupal 10.2.2 and paragraphs 1.17.0
Comment #39
banoodle commentedI saw comment #38 and noticed that I was on paragraphs 1.16.0.
I just upgraded to 1.17.0 and applied patch #35 and now it is working for me!
Thank you!
Comment #40
eduardo morales albertiComment #43
berdirFinally Merged, thanks everyone for sticking with this.