Allow to not impose the Paragraphs type restrictions in Paragraphs library items

Created on 2 September 2021, over 3 years ago
Updated 16 September 2024, 3 months ago

Problem/Motivation

When a paragraphs library item contains a paragraph type that may not be used in a field of a content, when saving the content, a validation error will prevent the content from being saved. The constraint's id that causes this error is "ParagraphsLibraryItemHasAllowedParagraphsType".

This may be an unexpected behavior and may also sometimes be undesirable.

An use case is when the paragraphs library item is set by a trusted editor and once is defined it should be allowed to be used in any paragraph field that has the "from library" option, whatever are the paragraph types that the paragraphs library item has in it.

Steps to reproduce

  1. Create paragraph types A (check option Allow adding to library) and B
  2. Create a content type with a paragraph field that may use paragraphs B and From library
  3. Add a library item with paragraph A
  4. Create a content of the new content type and in the paragraph field add from library the reusable paragraph A

An error will be displayed:
The Reusable paragraph field cannot contain a A paragraph, because the parent Paragraphs field disallows it.

Proposed resolution

My proposal is to allow to not impose the mentioned constraint, through a configuration setting.

I consider that just the fact that this configuration setting exists is beneficial by itself, because by reading the settings page of the module, a developer will be aware of the mentioned constraint, that otherwise could be unexpected (it was unexpected for me).

Feature request
Status

Needs work

Version

1.0

Component

Module: Library

Created by

🇵🇹Portugal dxvargas

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇱Netherlands IJsbrandy

    Unfortunately the patch in #11 gives an exception when changing the settings (for example the cardinality) of a paragraph field. This occurs when you have translations activated and due to the unnecessary save method that is called.
    + $storage->save();
    The ThirdPartySetting should be saved by just setting the value.

    See attachment for small adjustment to patch

    Todo: add tests to confirm implementation

  • Status changed to Needs work 6 months ago
  • 🇮🇳India anil.sharma

    The patch was not working for entity type entity_reference and target type paragraphs_library_item. So I added one more condition to it.

Production build 0.71.5 2024