Non-translatable fields can only be changed when updating the current revision.

Created on 9 June 2020, over 4 years ago
Updated 26 January 2023, almost 2 years ago

Problem/Motivation

  1. My articles have a workflow. Forward revisions are enabled.
  2. When editing an existing article, the system automatically treats it as a non default revision initially because Drupal\content_moderation\EntityTypeInfo::entityPrepareForm calls $new_revision = $storage->createRevision($entity, FALSE);. That FALSE is the root of all of our problems.
  3. entity_reference_revisions_entity_revision_create propagates this and so the paragraphs think they are in a non default revision.
  4. ModerationStateFieldItemList::setValue calls updateModeratedEntity which resets the node to default revision if the moderate state is such
  5. That one, however, is called from the validate form -- build entity chain and, again resets only the node.
  6. InlineParagraphsWidget::elementValidate, is called much earlier because it is in #element_validate
  7. This calls $display->validateFormValues which in turns fires $entity->validate() where the entity is the paragraph.
  8. Now comes the tragedy: EntityUntranslatableFieldsConstraintValidator thinks we are adding a new paragraph to a non default revision and forbids it. Despite we are adding it to the default revision but due to #3 the paragraph does not realize this.

Proposed resolution

If we reference a specific revision anyways then what is the point of defaultness? Just kill #3.

Remaining tasks

Decide whether this is correct. Maybe not for the generic case and then it needs to be somehow restricted to paragraphs. I do not know how to do that.

๐Ÿ› Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

๐Ÿ‡จ๐Ÿ‡ฆCanada Charlie ChX Negyesi ๐ŸCanada

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States cpierce42

    Patch does not apply on version 1.1x of this module.
    Drupal 9.5.2

  • ๐Ÿ‡ช๐Ÿ‡ธSpain rcodina Barcelona

    Patch on #2 works like a charm!

    Drupal: 9.5.2
    Entity Reference Revision: 8.x-1.10

  • ๐Ÿ‡ฆ๐Ÿ‡ทArgentina juanramonperez

    Patch #2 works for me also

    Drupal core 9.5.2
    Entity Reference Revisions 8.x-1.10

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States wheelercreek

    Drupal 9.5.5 - Patch #2 did not work for me. We have a content type with multiple paragraph fields, and these fields have entity reference revisions. Some of these paragraphs contain other paragraph fields.

    I found the problem is fixed by going through every field in the revisions and making sure to check the box "Users my translate this field". I did this even though there is the warning about how paragraphs do not support translations. This fixed the error and at least now I can update the content. Otherwise the nodes are stuck & cannot be updated (in any field).

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom maseyuk

    Thanks patch #2 works well for me in D9.5.9

    For the comment in #30 by @wheelercreek by ticking your paragraphs as translatable you might run into this issue:

    1) You have a node in EN and DE
    2) You have a node with a paragraph with 5 items
    3) Delete 1 of the paragraphs in EN
    4) Go and translate DE and you'll see the deleted paragraph is visible and you have no way to delete it from the translation

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Anybody Porta Westfalica

    Re #31 I think the right and safe way would be to make the "published" field translatable and simply set it unpublished in languages where you don't need it (for sync translation)

  • ๐Ÿ‡ง๐Ÿ‡ทBrazil fadonascimento

    Patch #2 worked for me!

    Drupal version: 10.1.4
    Entity Reference Revision version: 1.10

    Thanks!

  • ๐Ÿ‡ง๐Ÿ‡ทBrazil verzola Santana de Parnaรญba

    Patch #2 worked for me as well.

    Drupal version: 10.1.4
    Entity Reference Revision version: 1.10

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom andreastkdf

    Re-roll for 1.11

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.2.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update 11 months ago
    40 pass
  • Patch #35 worked in conjunction with checking "Hide non translatable fields on translation forms" on the relevant paragraph(s).

  • Status changed to Needs review 10 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom andreastkdf
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium xaa Brussels

    Patch #35 for 1.11 applied on d10.2.3. thank you.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance pbonnefoi

    Patch #35 for 1.11 applied on d10.2.3. as well and fixes my problem.

  • Status changed to RTBC 8 months ago
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand stewest Wellington

    Hi, yes, I can confirm that Patch #35 worked in conjunction with checking "Hide non translatable fields on translation forms" on the relevant paragraph(s). It did not work without the "Hide non translatable fields on translation forms" enabled, as I'd get the red errors under all the fields.

    Entity Reference Revision 1.11.0
    Paragraphs: 1.17.0
    Drupal: 10.2.5

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium ant1

    +1

  • Status changed to Needs work 4 months ago
  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland berdir Switzerland

    This needs to be a merge request to run against current tests.

  • Still here on 10.3.2. "Hide non translatable fields on translation forms" enabled.

  • First commit to issue fork.
  • Status changed to Needs review 3 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡ทGreece vensires

    I have updated the MR to represent the changes from #35 โ†’ .

    I am still trying to understand though... I was able to fix the problem in my case without this patch; with the Hide non translatable fields on translation forms enabled. So, my question is, does this fix the whole problem? Or just a portion of it?

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia bgogoi

    I am facing almost similar issue - can not add any new field to any content type:

    he website encountered an unexpected error. Try again later.

    TypeError: Cannot access offset of type Drupal\Core\StringTranslation\TranslatableMarkup in isset or empty in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 45 of core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).

    Drupal\Core\Plugin\DefaultPluginManager->getDefinition() (Line: 16)
    Drupal\Core\Plugin\Factory\ContainerFactory->createInstance() (Line: 76)
    Drupal\Component\Plugin\PluginManagerBase->createInstance() (Line: 136)
    Drupal\field_ui\Form\FieldStorageAddForm->processFieldDefinitions() (Line: 80)
    Drupal\field_ui\Form\FieldStorageAddForm->buildForm()
    call_user_func_array() (Line: 528)
    Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 279)
    Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult()
    call_user_func_array() (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 593)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 183)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 709)
    Drupal\Core\DrupalKernel->handle() (Line: 19)

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine v.dovhaliuk

    The patch #2 has been updated to fix the issue with taxonomy terms.
    Steps to reproduce:
    1. Enable content moderation and set up the following moderation states: Draft, Awaiting Approval, and Published.
    2. Enable workflow for the taxonomy.
    3. Create a taxonomy term.
    4. Create a translation for that term.
    5. Edit the original entity and add an additional paragraph to the `entity_reference_revisions` field.
    6. Save the entity as a draft.
    7. Edit your translation; you will notice that the newly added paragraph does not appear in the specified field.

Production build 0.71.5 2024