To reproduce:

* Install demo
* Limit the paragraph field for both the node field and the nested field to the nested field type. => Boom.

We need to add a static that counts the amount of nested elements and somehow limit it. Not sure based on what exactly we want to limit, like number of same paragraph types and then stop adding a default? Or total amount and a bit higher limit?

Comments

Berdir created an issue. See original summary.

johnchque’s picture

Does this really happen? I cannot reproduce, where does it "boom" exactly? when saving or when editing/viewing a node?

berdir’s picture

When you edit.

Because we will add a default paragraph in your field, that paragraph has a paragraph field, which will add the same default paragraph, which also has a paragraph field (as it is the same type) and it will add another one and so on..

miro_dietiker’s picture

We could also simply disallow adding the own type as child again?

toncic’s picture

StatusFileSize
new2.55 KB

I tried @miro_dietiker proposal and seems like works, but test failing.

toncic’s picture

Assigned: Unassigned » toncic
Status: Active » Needs work
toncic’s picture

Status: Needs work » Needs review

Just to check what tests will say.

Status: Needs review » Needs work

The last submitted patch, 5: recursion_loop_if-2853759-5.patch, failed testing.

primsi’s picture

Maybe I got this wrong, but isn't this only a problem with nested ones? So shouldn't we check if current and parent are nested?

toncic’s picture

Status: Needs work » Needs review
StatusFileSize
new4.94 KB
new2.39 KB

I forgot to fix this for classic paragraphs.This is working pretty fine for me, hope it is a good approach.

miro_dietiker’s picture

Status: Needs review » Needs work

I think this looks pretty fine, didn't test though. Some small doc things.

  1. +++ b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
    @@ -766,7 +766,7 @@ class InlineParagraphsWidget extends WidgetBase {
    +      if ($default_type && $default_type != $items->getEntity()->bundle()) {
    ...
           // Checking if default_type is not none and if is allowed.
    ...
    +      if ($default_type && $default_type != $items->getEntity()->bundle()) {
    

    This seems fine, but this extra check is so much important, you should add a comment here why...

  2. +++ b/src/Tests/Classic/ParagraphsWidgetButtonsTest.php
    @@ -109,4 +109,32 @@ class ParagraphsWidgetButtonsTest extends ParagraphsTestBase {
    +    $this->drupalGet('node/add/paragraphed_test');
    

    You are not describing what the effective problem is - what specifically caused recusion. We should add comments that explain the problem.

toncic’s picture

Status: Needs work » Needs review
StatusFileSize
new6.33 KB
new3.66 KB

Changed documentation for test functions and added more code comments to make code more understandable.

miro_dietiker’s picture

So, it sounds constructed, but the recursion could still indirectly happen if
A only allows B as child
And B only allows A child
;-)

We could only try to avoid that type of recursion by only allowing auto-population of each field once per host entity. Not sure what's the best definition.

toncic’s picture

Status: Needs review » Needs work

A only allows B as child
And B only allows A child

Yes, my solution is not working for these cases. We still get recursion.

toncic’s picture

Status: Needs work » Needs review
StatusFileSize
new11.07 KB

After discussion with @Berdir, if these situation happen that is because wrong configuration. We don't want to try to fix wrong configuration, we just won't to prevent crushing. After adding 5 level of nesting we stopped adding default paragraph type and display warning.
Without interdiff because approach are totally different.

miro_dietiker’s picture

I agree in general about "not fixing wrong config", but this behavior is the default behavior we propose if a paragraph type only supports itself as child type (until there is an opt-out). So it's likely not wrong custom config, but wrong default config. I'm not yet convinced to ignore that problem. ;-)

berdir’s picture

We could not make the default default type if it's the same as the parent, that might be possible.

But if it's not *wrong* configuration then it is at least weird configuration, because then you start mixing containers and content paragraphs, you can not have a container-only paragraphs using itself as its only child as then you would actually ever have anything to display. So it would be something like a text + child paragraph paragraph type.

miro_dietiker’s picture

Yeah, i also thought once that a container paragraph type can be clearly differentiated from a content paragraph type.
But sometimes, Containers could have content too and work without a child. At least (custom) compositions that have extra content fields (plus support children). I still think we need more examples to understand these things right.

primsi’s picture

What if we - instead of trying to figure out if we are in a recursion from the paragraph types - we just try to figure out if we are in a recursion, by setting some flag when we assign a default value for the first time. Not sure how should we do exactly, but it might be worth investigating a bit.

anand.toshniwal93’s picture

Version: 8.x-1.x-dev » 8.x-1.3
StatusFileSize
new11.22 KB

I have re-rolled this patch against the 8.x-1.3 version

Status: Needs review » Needs work

The last submitted patch, 20: recursion_loop_if-2853759-20.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

osab’s picture

Hi! Maybe we should relate the issue https://www.drupal.org/project/paragraphs/issues/3022843 to the current one?

knieriem’s picture

Since this is related to https://www.drupal.org/project/paragraphs/issues/3022843, which has been marked closed, works as designed, can this be closed as well?