Problem/Motivation

Soon we have multilingual support.
#2414913: Support entity translation of paragraphs

This is an important aspect in the application of paragraphs.

Proposed resolution

Properly configure demo paragraphs / fields to be translatable.
(We also need multiple languages setup.)

Still if this is not needed for a simple demo, just ignore the "Translate" tab and the language selector when creating/editing content.
Alternatively we could have a separate multilingual content type setup to avoid multilingual confusion if it is completely irrelevant for audience.

Remaining tasks

User interface changes

API changes

CommentFileSizeAuthor
#55 demo_module-2461689-55-interdiff.txt608 bytessasanikolic
#55 demo_module-2461689-55.patch22.24 KBsasanikolic
#53 demo_module-2461689-53-interdiff.txt3.77 KBsasanikolic
#53 demo_module-2461689-53.patch22.26 KBsasanikolic
#49 demo_module-2461689-49-interdiff.txt2.08 KBsasanikolic
#49 demo_module-2461689-49.patch22.76 KBsasanikolic
#47 demo_module-2461689-47-interdiff.txt1.04 KBsasanikolic
#47 demo_module-2461689-47.patch23.15 KBsasanikolic
#44 demo_module-2461689-44-interdiff.txt2.75 KBsasanikolic
#44 demo_module-2461689-44.patch22.73 KBsasanikolic
#41 interdiff_38-41.txt2.22 KBLKS90
#41 demo_module-2461689-41.patch20.54 KBLKS90
#38 demo_module-2461689-38.patch18.32 KBLKS90
#38 interdiff_36-38.txt2.17 KBLKS90
#36 demo_module-2461689-36.patch17.77 KBLKS90
#34 interdiff_31-33.txt685 bytesLKS90
#33 demo_module-2461689-33.patch17.8 KBLKS90
#31 demo_module-2461689-31.patch17.49 KBLKS90
#24 demo_module-2461689-24-interdiff.txt1.48 KBsasanikolic
#24 demo_module-2461689-24.patch17.5 KBsasanikolic
#23 demo_module-2461689-23-interdiff.txt4.81 KBsasanikolic
#23 demo_module-2461689-23.patch16.94 KBsasanikolic
#20 interdiff_18-20.txt1.35 KBLKS90
#20 demo_module-2461689-20.patch14.46 KBLKS90
#18 interdiff_16-18.txt2.1 KBLKS90
#18 demo_module-2461689-18.patch14.23 KBLKS90
#16 demo_module-2461689-16-interdiff.txt556 bytessasanikolic
#16 demo_module-2461689-16.patch12.13 KBsasanikolic
#14 demo_module-2461689-14-interdiff.txt2.38 KBsasanikolic
#14 demo_module-2461689-14.patch12.17 KBsasanikolic
#10 demo_module-2461689-10-interdiff.txt7.65 KBsasanikolic
#10 demo_module-2461689-10.patch9.79 KBsasanikolic
#9 demo_module-2461689-9-interdiff.txt1.71 KBsasanikolic
#9 demo_module-2461689-9.patch3.58 KBsasanikolic
#8 demo_module-2461689-8-interdiff.txt934 bytessasanikolic
#8 demo_module-2461689-8.patch2.08 KBsasanikolic
#6 demo_module-2461689-6.patch1.17 KBsasanikolic

Comments

miro_dietiker’s picture

miro_dietiker’s picture

Title: paragraph demo: Multilingual setup » demo module: Multilingual setup
miro_dietiker’s picture

(Jeroen: I think we should have a demo component in the issue queue.)

jeroen.b’s picture

I added the Demo component.

miro_dietiker’s picture

Component: Documentation » Demo
Priority: Normal » Major

Nice, moving to demo component.

I'm promoting this to major since i want to use Paragraphs as a reference example for smooth multilingual workflows combined with TMGMT.
In the best case, this means, the demo contains the multilingual setup.

sasanikolic’s picture

Status: Active » Needs review
StatusFileSize
new1.17 KB

Extended the demo module for multilingual support.

Status: Needs review » Needs work

The last submitted patch, 6: demo_module-2461689-6.patch, failed testing.

sasanikolic’s picture

Status: Needs work » Needs review
StatusFileSize
new2.08 KB
new934 bytes

Fixed the failing test.

sasanikolic’s picture

FIxed a schema config.

sasanikolic’s picture

Changed the test and added the config files.

Status: Needs review » Needs work

The last submitted patch, 10: demo_module-2461689-10.patch, failed testing.

The last submitted patch, 10: demo_module-2461689-10.patch, failed testing.

sasanikolic’s picture

Status: Needs work » Needs review
StatusFileSize
new12.17 KB
new2.38 KB

Fixed the test fails - some configuration for translating text+image were missing.

mbovan’s picture

  1. +++ b/modules/paragraphs_demo/config/install/language.content_settings.node.paragraphed_content_demo.yml
    @@ -0,0 +1,16 @@
    +uuid: 872a47fc-77da-4589-a537-55325e31170a
    

    I think the UUID should be removed.

  2. +++ b/src/Tests/ParagraphsTranslationTest.php
    @@ -38,10 +33,7 @@ class ParagraphsTranslationTest extends WebTestBase {
    +    \Drupal::service('entity.definition_update_manager')->applyUpdates();
    
    @@ -112,7 +79,7 @@ class ParagraphsTranslationTest extends WebTestBase {
    -    $this->clickLink(t('Add'));
    

    Is there any other way to add French translation (e.g. clicking a button somewhere?) in tests, except visting /fr/node/1/translations/add/en/fr directly?

sasanikolic’s picture

StatusFileSize
new12.13 KB
new556 bytes

Thanks.

1.) Done.
2.) I think hardcoding the link is fine. clickLink('Add') doesn't work now because it clicks on the first Add button that it finds. But now, after loading the languages from the configs we have them in different order...

LKS90’s picture

I'm adding a test for the demo module now.
Considering 2.) in #16: clickLink also has an optional second parameter which is the index of the button to click. Messy but it works. I'll upload a working patch tomorrow hopefully. My test for the demo module still has a schema error

LKS90’s picture

StatusFileSize
new14.23 KB
new2.1 KB

Here is the test I was talking about up there, just so Saša might continue working on it.

Status: Needs review » Needs work

The last submitted patch, 18: demo_module-2461689-18.patch, failed testing.

LKS90’s picture

StatusFileSize
new14.46 KB
new1.35 KB

An updated version. It's supposed to pass the tests but I'm having some problems locally (last drupalPostForm returns a 500 error message).

sasanikolic’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 20: demo_module-2461689-20.patch, failed testing.

sasanikolic’s picture

Status: Needs work » Needs review
StatusFileSize
new16.94 KB
new4.81 KB

Re-made the test from scratch and added the checks for the default configurations.

sasanikolic’s picture

Extended the test with paragraphs creation.

The last submitted patch, 23: demo_module-2461689-23.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 24: demo_module-2461689-24.patch, failed testing.

The last submitted patch, 20: demo_module-2461689-20.patch, failed testing.

The last submitted patch, 23: demo_module-2461689-23.patch, failed testing.

The last submitted patch, 24: demo_module-2461689-24.patch, failed testing.

miro_dietiker’s picture

PHP Fatal error: Class 'Drupal\search_api\Tests\WebTestBase' not found in /var/lib/drupaltestbot/sites/default/files/checkout/sites/default/modules/paragraphs/modules/paragraphs_demo/src/Tests/ParagraphsDemoTest.php on line 15

With only resolved dependencies to entity_reference_revisions (and paragraphs).

+++ b/modules/paragraphs_demo/src/Tests/ParagraphsDemoTest.php
@@ -0,0 +1,143 @@
+use Drupal\search_api\Tests\WebTestBase;

That's the problem.

LKS90’s picture

Status: Needs work » Needs review
StatusFileSize
new17.49 KB

Corrected the usage. The other Paragraphs tests use the simpletest WebTestBase, the demo test now does as well.

miro_dietiker’s picture

Status: Needs review » Needs work

Looks pretty nice.

description: Demo module for paragraphs.
The paragraph demo module description needs to be extended. Also notify that it is a multilingual demo and adds german and french languages. And it should also state that it adds paragraph types, CSS (responsive wrapping) and... Not too much detail, but clear enough about contents.

LKS90’s picture

Status: Needs work » Needs review
StatusFileSize
new17.8 KB

I tried it with multiline description, but it doesn't really work. Feedback welcome (keep it like it is? Put it on one line?). I also changed the package (capitalisation) so all paragraphs modules are grouped together (there were 2 groups before).

LKS90’s picture

StatusFileSize
new685 bytes

And an interdiff of which shows the changes.

LKS90’s picture

https://www.drupal.org/node/2506497 already changed the paragraphs group, rebase necessary.

LKS90’s picture

StatusFileSize
new17.77 KB

Rebased and reviewed, ready for commit if reviewed by someone else.

arla’s picture

Status: Needs review » Needs work

When I save a node (new or existing), I get:

Drupal\Core\Entity\EntityStorageException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'content_translation_source' in 'field list': INSERT INTO {paragraphs_item_field_data} (id, revision_id, type, langcode, uid, created, changed, default_langcode, content_translation_source, content_translation_outdated, content_translation_status) VALUES ...

Sometimes when I visit the content overview, I get this PHP notice:

Notice: Undefined index: content_translation_source in Drupal\Core\Entity\Sql\SqlContentEntityStorage->loadFromSharedTables() (line 715 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Drupal\Core\Entity\Sql\SqlContentEntityStorage->loadFromSharedTables(Array, Array)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->mapFromStorageRecords(Array)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->getFromStorage(Array)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->doLoadMultiple(Array)
Drupal\Core\Entity\EntityStorageBase->loadMultiple(Array)
entity_load_multiple('node', Array)

This (paragraphs + paragraphs_demo) doesn't depend on any other contrib module than entity_reference_revisions, right?

  1. +++ b/modules/paragraphs_demo/paragraphs_demo.info.yml
    @@ -1,4 +1,6 @@
    +description: >
    +  Multilingual demo for paragraphs. It adds CSS for responsive wrapping as well as the following paragraph types:
    +  User, Images, Text, Image + Text, Text + Image
    

    To make line breaks matter in YAML strings, you should use |, not >. But it doesn't really matter, because the module description is just printed in the HTML and line breaks are ignored anyway. IMHO that's okay, the line break is not really necessary here.

  2. +++ b/modules/paragraphs_demo/src/Tests/ParagraphsDemoTest.php
    @@ -0,0 +1,144 @@
    +  function setUp() {
    

    Should be protected.

  3. +++ b/modules/paragraphs_demo/src/Tests/ParagraphsDemoTest.php
    @@ -0,0 +1,144 @@
    +  }
    +
    +  protected function testParagraphsCreation() {
    

    Test method needs doc.

  4. +++ b/modules/paragraphs_demo/src/Tests/ParagraphsDemoTest.php
    @@ -0,0 +1,144 @@
    +}
    +
    

    I get

    <stdin>:435: new blank line at EOF.
    +
    warning: 1 line adds whitespace errors.

    when applying.

LKS90’s picture

StatusFileSize
new2.17 KB
new18.32 KB

The feedback has been implemented! Now we might want to add a demo node with paragraphs and translate that, the paragraphs_demo.install has plenty of space to do things.

LKS90’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 38: demo_module-2461689-38.patch, failed testing.

LKS90’s picture

StatusFileSize
new20.54 KB
new2.22 KB

Updated the test, assertOptionSelected didn't have a result for it's xpath call, doing it manually with an assertRaw for the HTML now.

LKS90’s picture

Status: Needs work » Needs review
arla’s picture

The assertOptionSelected calls must be failing because of #1305882: drupal_html_id() considered harmful; remove ajax_html_ids to use GET (not POST) AJAX requests (Core).

But assertRaw seems like an okay fix.

sasanikolic’s picture

Added the introduction on the frontpage.

Status: Needs review » Needs work

The last submitted patch, 44: demo_module-2461689-44.patch, failed testing.

LKS90’s picture

Concerning #41: #2530092: AssertOptionSelected() does not work for dynamic HTML IDs

The easiest solution right now:

#2530044: Edit widget test is failing

Revert the assertRaw(), add the fixed assertOptionSelected() function temporarily.

sasanikolic’s picture

Status: Needs work » Needs review
StatusFileSize
new23.15 KB
new1.04 KB

Fixed the test fails. Because of the new welcome node in the demo, the index of the node in the test has to be changed to 2.

LKS90’s picture

+++ b/src/Tests/ParagraphsAdministrationTest.php
@@ -224,7 +224,8 @@ class ParagraphsAdministrationTest extends WebTestBase {
-    $this->assertOptionSelected('edit-fields-field-paragraphs-settings-edit-form-settings-add-mode', 'button', 'Updated value is correct!.');
+    // Assert the 'Buttons' option is selected.
+    $this->assertRaw('<option value="button" selected>Buttons</option>');
 
     // Add two Text + Image paragraphs in article.
     $this->drupalGet('node/add/article');
@@ -272,7 +273,8 @@ class ParagraphsAdministrationTest extends WebTestBase {

@@ -272,7 +273,8 @@ class ParagraphsAdministrationTest extends WebTestBase {
     // Check if the setting is stored.
     $this->assertText('Edit mode: Closed', 'Checking the settings value.');
     $this->drupalPostAjaxForm(NULL, array(), "field_paragraphs_settings_edit");
-    $this->assertOptionSelected('edit-fields-field-paragraphs-settings-edit-form-settings-edit-mode', 'closed', 'Updated value correctly.');
+    // Assert the 'Closed' option is selected.
+    $this->assertRaw('<option value="closed" selected>Closed</option>');
     $this->drupalGet('node/1/edit');
     // The textareas for paragraphs should not be visible.
     $this->assertNoRaw('field_paragraphs[0][subform][field_text][0][value]');
@@ -296,7 +298,8 @@ class ParagraphsAdministrationTest extends WebTestBase {

@@ -296,7 +298,8 @@ class ParagraphsAdministrationTest extends WebTestBase {
     // Test for open option.
     $this->drupalGet('admin/structure/types/manage/article/form-display');
     $this->drupalPostAjaxForm(NULL, array(), "field_paragraphs_settings_edit");
-    $this->assertOptionSelected('edit-fields-field-paragraphs-settings-edit-form-settings-edit-mode', 'preview', 'Updated value correctly.');
+    // Assert the 'Preview' option is selected.
+    $this->assertRaw('<option value="preview" selected>Preview</option>');

Those should be reverted. Add the fixed assertOptionSelected() method instead.

sasanikolic’s picture

Ok, reverted back to use assertOptionSelected.

berdir’s picture

Status: Needs review » Needs work

Cool stuff!

  1. +++ b/modules/paragraphs_demo/src/Tests/ParagraphsDemoTest.php
    @@ -0,0 +1,146 @@
    + *
    + * @group Paragraphs
    

    Usually the group is the module machine name.

    do the other tests also use Paragraphs? Then fine...

  2. +++ b/modules/paragraphs_demo/src/Tests/ParagraphsDemoTest.php
    @@ -0,0 +1,146 @@
    +  public static $modules = array(
    +    'node',
    +    'paragraphs_demo',
    +  );
    

    paragraphs_demo should depend on node.module, not the test.

  3. +++ b/modules/paragraphs_demo/src/Tests/ParagraphsDemoTest.php
    @@ -0,0 +1,146 @@
    +    $this->drupalGet('admin/config/regional/content-language');
    +    $this->assertFieldChecked('edit-entity-types-node');
    +    $this->assertFieldChecked('edit-entity-types-paragraph');
    +    $this->assertFieldChecked('edit-settings-node-paragraphed-content-demo-translatable');
    +    $this->assertFieldChecked('edit-settings-paragraph-images-translatable');
    +    $this->assertFieldChecked('edit-settings-paragraph-image-text-translatable');
    +    $this->assertFieldChecked('edit-settings-paragraph-text-translatable');
    +    $this->assertFieldChecked('edit-settings-paragraph-text-image-translatable');
    +    $this->assertFieldChecked('edit-settings-paragraph-user-translatable');
    

    Can we also add an assertion that the paragraphs reference field is *not* checked?

  4. +++ b/modules/paragraphs_demo/src/Tests/ParagraphsDemoTest.php
    @@ -0,0 +1,146 @@
    +
    +  }
    +
    +  /**
    +   * Test creating content of demo paragraph type.
    +   */
    +  protected function testParagraphsCreation() {
    

    This probably makes the test almost twice as slow. I'd combine those two methods together.

  5. +++ b/src/Tests/ParagraphsTranslationTest.php
    @@ -38,10 +33,7 @@ class ParagraphsTranslationTest extends WebTestBase {
        */
       protected function setUp() {
         parent::setUp();
    -    $language = ConfigurableLanguage::createFromLangcode('de');
    -    $language->save();
    -    $language = ConfigurableLanguage::createFromLangcode('fr');
    -    $language->save();
    +    \Drupal::service('entity.definition_update_manager')->applyUpdates();
       }
    

    applyUpdates() is now called in paragraphs_demo_install(), this shouldn't be needed anymore.

  6. +++ b/src/Tests/ParagraphsTranslationTest.php
    @@ -112,7 +79,7 @@ class ParagraphsTranslationTest extends WebTestBase {
         $this->clickLink(t('Translate'));
    -    $this->clickLink(t('Add'));
    +    $this->drupalGet('/fr/node/2/translations/add/en/fr');
    

    No leading /.

The last submitted patch, 41: demo_module-2461689-41.patch, failed testing.

sasanikolic’s picture

Status: Needs work » Needs review
StatusFileSize
new22.26 KB
new3.77 KB

Fixes for the comments above.

LKS90’s picture

Status: Needs review » Needs work
+++ b/src/Tests/ParagraphsTranslationTest.php
@@ -112,7 +78,7 @@ class ParagraphsTranslationTest extends WebTestBase {
-    $this->clickLink(t('Add'));
+    $this->drupalGet('fr/node/2/translations/add/en/fr');

Changing from clickLink to drupalGet is a bit much I'd say, just change it to $this->clickLink(t('Add'), 1); to click the second Add link on the page. Now we do the same thing as before and actually use the UI buttons instead of clicking links and then suddenly drupalGetting to the place we want to go to.

sasanikolic’s picture

Status: Needs work » Needs review
StatusFileSize
new22.24 KB
new608 bytes

Thanks, totally forgot about this easy way. :)

LKS90’s picture

Status: Needs review » Reviewed & tested by the community

Now it's perfect! ;)

berdir’s picture

Yes, looks good to me as well.

  • jeroen.b committed fe99c2b on 8.x-1.x authored by sasanikolic
    Issue #2461689 by sasanikolic, LKS90, miro_dietiker, Berdir, Arla,...
jeroen.b’s picture

Status: Reviewed & tested by the community » Fixed

Thanks guys, commited to dev, really appreciate all your hard work!

Status: Fixed » Closed (fixed)

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