Problem/Motivation

Paragraphs should be allowed to be converted in the widget.

If there are similar fields the plugin should work out of the box but it should be possible to go through the paragraphs fields and map them to the target paragraph type.

Similar to Add Above. Enable the convert feature in the field form display.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#22 paragraphs_conversion-3043559-22.patch42.3 KBweseze
#21 paragraphs_conversion-3043559-21.patch42.2 KBsasanikolic
#21 paragraphs_conversion-3043559-21-interdiff.txt601 bytessasanikolic
#20 paragraphs_conversion-3043559-20.patch42.11 KBBerdir
#19 paragraphs_conversion-3043559-19.patch42.12 KBBerdir
#18 paragraphs_conversion-3043559-18.patch42.07 KBPrimsi
#18 paragraphs_conversion-3043559-18-interdiff.txt844 bytesPrimsi
#17 paragraphs_conversion-3043559-17-15-interdiff.txt7.42 KBmbovan
#17 paragraphs_conversion-3043559-17.patch42.07 KBmbovan
#15 paragraphs_conversion-3043559-15-14-interdiff.txt3.11 KBmbovan
#15 paragraphs_conversion-3043559-15.patch43.32 KBmbovan
#14 paragraphs_conversion-3043559-14-13-interdiff.txt584 bytesmbovan
#14 paragraphs_conversion-3043559-14.patch42.09 KBmbovan
#13 paragraphs_conversion-3043559-13-12-interdiff.txt1.75 KBmbovan
#13 paragraphs_conversion-3043559-13.patch41.95 KBmbovan
#12 paragraphs_conversion-3043559-12-11-interdiff.txt638 bytesmbovan
#12 paragraphs_conversion-3043559-12.patch42 KBmbovan
#11 paragraphs_conversion-3043559-11-10-interdiff.txt2.04 KBmbovan
#11 paragraphs_conversion-3043559-11.patch41.98 KBmbovan
#10 paragraphs_conversion-3043559-10-9-interdiff.txt16.08 KBmbovan
#10 paragraphs_conversion-3043559-10.patch44.02 KBmbovan
#9 paragraphs_conversion-3043559-9-8-interdiff.txt1.02 KBmbovan
#9 paragraphs_conversion-3043559-9.patch39.63 KBmbovan
#8 interdiff-3043559-7-8.txt2.68 KBjohnchque
#8 paragraphs_conversion-3043559-8.patch39.47 KBjohnchque
#7 interdiff-3043559-6-7.txt2.14 KBjohnchque
#7 paragraphs_conversion-3043559-7.patch39.21 KBjohnchque
#6 interdiff-3043559-5-6.txt5.76 KBjohnchque
#6 paragraphs_conversion-3043559-6.patch39 KBjohnchque
#5 interdiff-3043559-4-5.txt1.54 KBjohnchque
#5 paragraphs_conversion-3043559-5.patch36.88 KBjohnchque
#4 interdiff-3043559-3-4.txt2.07 KBjohnchque
#4 paragraphs_conversion-3043559-4.patch36.62 KBjohnchque
#3 interdiff-3043559-2-3.txt37.71 KBjohnchque
#3 paragraphs_conversion-3043559-3.patch36.63 KBjohnchque
#2 paragraphs_conversion-3043559-2.patch36.17 KBjohnchque

Issue fork paragraphs-3043559

Command icon 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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yongt9412 created an issue. See original summary.

johnchque’s picture

Status: Active » Needs review
FileSize
36.17 KB

WIP patch. Working now. No tests yet.

johnchque’s picture

Now checking the allowed values. Updating the ellipsis by the ellipsis char. Updating the labels of elements introduced here.

johnchque’s picture

Sorry, some small adjustments. :)

johnchque’s picture

Got a problem when using the modal add form.

johnchque’s picture

Making the target types an array so we can have multiple types returned from the conversion operation.

johnchque’s picture

Sending the parent allowed types to the support method.

johnchque’s picture

Updating patch to allow returning Paragraphs objects so we can reuse them.

mbovan’s picture

This patch fixes a problem if a default language is not the first one in the list when doing conversions.

We noticed this in a client project and @Berdir fixed it so credits to him. :)

I have tried to create content + text paragraphs in one language and then switched it to the other language but I can't reproduce it...

mbovan’s picture

I thought that we are missing the alter hook so contrib/custom modules can alter converted paragraphs. It was just undocumented in paragraphs.api.php. Fixed that and while here also fixed the code style errors I noticed.

mbovan’s picture

ParagraphsDemoTest changes are not really related to this. Reverted that.

mbovan’s picture

Providing a fix for the case when a conversion plugin doesn't return paragraph values but a paragraph entity.

mbovan’s picture

This patch fixes an issue with the conversion hook that was not executed on each converted paragraphs.

mbovan’s picture

I updated hook_paragraphs_conversion() to document that the hook is not fired for each translation.

mbovan’s picture

I am providing a patch that improves Drupal\paragraphs\ParagraphsConversionBase::supports() to it checks a user has create access to at least one target paragraph type.

mbovan’s picture

+++ b/src/ParagraphsConversionManager.php
@@ -0,0 +1,185 @@
+          // Loop over the target types and check that the user has create
+          // access to all of them.
+          foreach ($definition['target_types'] as $target_type) {
+            if ($access_control_handler->createAccess($target_type)) {
+              // In case there are allowed types check the target type.
+              if (is_array($allowed_types) && !isset($allowed_types[$target_type])) {
+                $applicable = FALSE;
+              }
+            }
+          }

Just noticed we already have this logic in two places in Drupal\paragraphs\ParagraphsConversionManager. It has a bug as it doesn't set the flag to FALSE if a user has no create access.

In #15, I moved the check into the base class so plugin implementations could decide whether they want to rely on access checks (best practice) or if they're doing something special. If we are enforcing the access check based on the plugin definition we should then move the similar check for the source_type in Drupal\paragraphs\ParagraphsConversionManager IMHO.

mbovan’s picture

Here I fixed the original problem described in #16.1.

Primsi’s picture

Berdir’s picture

Berdir’s picture

sasanikolic’s picture

I propose we add the small button class like we did for other buttons (for Claro) in https://www.drupal.org/node/3111075.

weseze’s picture

Patch #21 wasn't working for us against 1.13 release.
Attached is one that applies to 1.13. No changes

Berdir’s picture

Thanks for the reroll. FWIW, I wasn't sure about committing this without getting some inputs about it from others. So if it's useful, let me know :)

  • Berdir committed 9c09c15a on 8.x-1.x
    Issue #3043559 by mbovan, johnchque, Berdir, Primsi, sasanikolic, weseze...
Berdir’s picture

Status: Needs review » Fixed

We've been using this for years. Committed and created a basic documentation page: https://www.drupal.org/docs/contributed-modules/paragraphs/converting-pa...

pp.panatom’s picture

@Berdir

on documentation page (also in related test),

function name `submitConversion()` should be `convert()`?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.