Problem/Motivation

As a followup from adding multilingual support:
#2414913: Support entity translation of paragraphs

The node form is now simultaneously editing multiple entities due to the composite relationship of the paragraphs.
Multilingual paragraphs (in how we support them) means that all paragraphs present in language A are also present in language B.

While translating, buttons to add / remove paragraphs are still present. The core behaviour about what field is "all languages" and what is language specific does not work anymore. The paragraph field on its own is "all languages" while the referenced entities (can) contain translatable fields. Then below, the buttons to add new paragraphs are again all languages.

Proposed resolution

Reduce user confusion and hide "remove" and "add" actions when translating.

(Indeed, also changing sequence is a thing that also affects all languages..)

Remaining tasks

User interface changes

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

miro_dietiker’s picture

miro_dietiker’s picture

From the original issue / Berdir suggestion:
Check $paragraph_item->language()->getId() != $paragraph_item->getUntranslated()->language()->getId()

miro_dietiker’s picture

TBD: Force this behaviour or add a setting to disable it?

jeroen.b’s picture

I think it would be best to force this behaviour.
Suggestion looks OK to me.

miro_dietiker’s picture

Component: Documentation » User interface
Priority: Normal » Major

Promoting this as a major usability issue in multilingual paragraphs.

sasanikolic’s picture

Status: Active » Needs review
FileSize
2.87 KB

Status: Needs review » Needs work

The last submitted patch, 6: hide_add_remove_buttons-2463491-6.patch, failed testing.

miro_dietiker’s picture

+++ b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
@@ -710,7 +712,7 @@ class InlineParagraphsWidget extends WidgetBase {
+    if (($real_item_count < $cardinality || $cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) && !$form_state->isProgrammed() && $items->getEntity()->language()->getId() != $items->getEntity()->getUntranslated()->language()->getId()) {

For me this is just too much on one single line.

Shouldn't we introduce a helper method isTranslation($entity) or isSource($entity) somewhere?

And we need tests pass and extended and checking the newly defined UI pattern including checks that assure the elements are removed.

sasanikolic’s picture

Status: Needs work » Needs review
FileSize
11.05 KB

The if check should be the other way around, i guess.

Tests are coming tomorrow morning, probably in a separate issue?

miro_dietiker’s picture

Tests are coming tomorrow morning, probably in a separate issue?

No, tests always part of the issue. At least basic test coverage. :-)

miro_dietiker’s picture

Status: Needs review » Needs work

When editing a translation, add / remove is dropped.
However, when adding a translation, they are still present.

And i just identified lots of issues with the translation workflow and need to update #2414913: Support entity translation of paragraphs
Comment link: https://www.drupal.org/node/2414913#comment-9834765

miro_dietiker’s picture

Ohh, forgot to mention...
Possibly you should just set #access to FALSE to hide the button, instead of changing the whole nesting.

sasanikolic’s picture

Status: Needs work » Needs review
FileSize
3.28 KB
9.34 KB

Changed the check for the add button as suggested.

Still need to fix the hide buttons while adding a translation issue.

miro_dietiker’s picture

First providing a patch that only adds #access without all the other complexity. Only 5 changing lines.

miro_dietiker’s picture

About the missing part: The language should already be set when creating a translation. But it is not. So that's a bug on #2414913: Support entity translation of paragraphs

miro_dietiker’s picture

Nice. So the other patch passes and hiding buttons is now easier.

The patch to test also includes the paragraphs issue dependency.

miro_dietiker’s picture

Status: Needs review » Needs work

Still missing tests that check if the button are properly removed.

miro_dietiker’s picture

Wrote the tests to make sure the buttons are there / gone as defined.

Berdir’s picture

  1. +++ b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
    @@ -281,6 +279,7 @@ class InlineParagraphsWidget extends WidgetBase {
     
    +          $button_access = $paragraphs_entity->access('delete') && $paragraphs_entity->language()->getId() == $paragraphs_entity->getUntranslated()->language()->getId();
               $links['remove_button'] = array(
    

    A comment here would be useful I think, to explain why we want to enforce it like this.

  2. +++ b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
    @@ -717,9 +716,11 @@ class InlineParagraphsWidget extends WidgetBase {
         if (($real_item_count < $cardinality || $cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) && !$form_state->isProgrammed()) {
    +      $add_more_access = $this->getCurrentLangcode($form_state, $items) == $items->getEntity()->getUntranslated()->language()->getId();
    

    Same comment here..

miro_dietiker’s picture

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Very niiice comment ;)

Reminder: The do-not-test patch is the one that will need to be committed, after #2414913: Support entity translation of paragraphs is committed.

jeroen.b’s picture

Resubmitted for retest

jeroen.b’s picture

Status: Reviewed & tested by the community » Needs review
jeroen.b’s picture

Status: Needs review » Fixed

Passes the tests so pushed to dev, thanks!

Status: Fixed » Closed (fixed)

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