Problem/Motivation

On certain entity types, the Published, Authored by, and Authored on fields are displayed twice on the translation form. This is confusing to the users and the behavior after saving is unclear concerning which value of the two is kept.

Steps to reproduce

Set up a multilingual website, allow Media to be translated. Upon translating a media, the 3 aforementioned fields are present twice on the form:

red: published status; blue: authoring information.

Proposed resolution

Show Published, Authored by, and Authored on fields only if those are not provided natively by the entity type.

Look of the form with the patch applied:

Note: nodes and comments currently have logic that hide the duplicated fields: this can be removed in this issue.

Note: blocks should have the published checkbox displayed even though the field is not supported in the blocks UI (see #2834546: UI for publishing/unpublishing block_content blocks) so for those, we force-display the field.

Remaining tasks

Should this be postponed on #2834546: UI for publishing/unpublishing block_content blocks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#81 2971390-81.patch21.12 KBkostyashupenko
#80 2971390-nr-bot.txt85 bytesneeds-review-queue-bot
#75 2971390-75.patch21.11 KBquietone
#75 interdiff-68-75.txt2.3 KBquietone
#71 Screenshot 2023-07-21 at 15-08-53 Create German translation of IMG_2110.JPG Drush Site-Install.png49.01 KBmathilde_dumond
#71 do-2971390-before.png80.37 KBmathilde_dumond
#68 2971390-68.patch21.13 KBBerdir
#67 2971390-nr-bot.txt144 bytesneeds-review-queue-bot
#62 2971390-62.patch21.16 KBBerdir
#61 2971390-60.patch21.19 KBBerdir
#60 2971390-60.patch21.64 KBBerdir
#57 2971390-57-interdiff.txt1.98 KBBerdir
#57 2971390-57.patch21.67 KBBerdir
#55 interdiff_53_55.txt1.17 KBanmolgoyal74
#55 2971390-55.patch19.7 KBanmolgoyal74
#53 2971390-53.patch19.65 KBBerdir
#47 2971390-47.patch19.7 KBBerdir
#46 2971390-46.patch23.97 KBManuel Garcia
#46 interdiff-2971390-45-46.txt852 bytesManuel Garcia
#45 2971390-45.patch24.58 KBBerdir
#44 2971390-44.patch24.58 KBBerdir
#39 2971390-39-interdiff.txt9.57 KBBerdir
#39 2971390-39.patch24.92 KBBerdir
#35 2971390-35.patch19.81 KBManuel Garcia
#35 interdiff-2971390-32-35.txt938 bytesManuel Garcia
#32 2971390-32.patch19.94 KBManuel Garcia
#32 interdiff-2971390-31-32.txt884 bytesManuel Garcia
#31 2971390-31.patch20.4 KBManuel Garcia
#31 interdiff-2971390-28-31.txt7.29 KBManuel Garcia
#28 2971390-28.patch20.69 KBManuel Garcia
#25 2971390-25.patch20.84 KBManuel Garcia
#25 interdiff-2971390-22-25.txt1.24 KBManuel Garcia
#22 2971390-22.patch20.83 KBManuel Garcia
#22 interdiff-2971390-21-22.txt3.36 KBManuel Garcia
#21 2971390-21.patch20.59 KBManuel Garcia
#21 interdiff-2971390-19-21.txt932 bytesManuel Garcia
#19 2971390-19.patch20.59 KBManuel Garcia
#14 disallow-users-to-change-translation-fields-2971390-14-interdiff.txt768 bytesmbovan
#14 disallow-users-to-change-translation-fields-2971390-14.patch20.14 KBmbovan
#12 disallow-users-to-change-translation-fields-2971390-12-interdiff.txt25.61 KBmbovan
#12 disallow-users-to-change-translation-fields-2971390-12.patch20.1 KBmbovan
#10 disallow-users-to-change-translation-fields-2971390-10.patch7.11 KBmbovan
#6 prevent-content-translation-uid-change-6.interdiff.txt668 bytesmbovan
#6 prevent-content-translation-uid-change-6.patch1.38 KBmbovan
#6 prevent-content-translation-uid-change-6-TEST-ONLY.patch668 bytesmbovan
#4 prevent-content-translation-uid-change-4.patch743 bytesmbovan
#2 prevent-content-translation-uid-change-2971390.patch707 bytesmbovan

Issue fork drupal-2971390

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

mbovan created an issue. See original summary.

mbovan’s picture

Title: Do not allow content translation author field change » Disallow users to change content translation uid metadata field
Status: Active » Needs review
Issue tags: +Needs tests
FileSize
707 bytes

Providing a fix for the metadata field name.

Status: Needs review » Needs work
mbovan’s picture

Status: Needs work » Needs review
FileSize
743 bytes

Oops, the above patch contains invalid paths. Fixed.

Berdir’s picture

Status: Needs review » Needs work

Setting to needs work for tests.

mbovan’s picture

mbovan’s picture

This also affects Media and other commonly translated entities. We could possibly think about moving the fix from #6 into \Drupal\content_translation\ContentTranslationHandler::entityFormAlter().

Connection with the related issue #2974560: Introduce a permission to check whether a user is able to access uid field.

Berdir’s picture

On the handler, we have things like \Drupal\content_translation\ContentTranslationHandler::hasAuthor() and and hasPublishedStatus() + hasCreated(). This hardcoded logic probably predates those generic checks and field definitions by a long time.

Maybe we can use those to dynamically define those fields only if necessary. We then likely also need to update the submit logic to not call setAuthor() and so on if we don't have the field exposed. Not quite sure how that even works right now to be honest. I can imagine the value is actually replaced anyway.

mbovan’s picture

I am uploading a patch that implements the idea from #9 - conditionally displaying content_translation_status, content_translation_uid and content_translation_created fields depending whether an entity type has those fields defined.

Edit: Sorry for no interdiff patch. It is based on a new idea, so not sure how relevant it would be.

Status: Needs review » Needs work

The last submitted patch, 10: disallow-users-to-change-translation-fields-2971390-10.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mbovan’s picture

Quite some changes in this patch. Hopefully, tests are passing.

Comments:

  1. +++ b/core/modules/block_content/src/BlockContentTranslationHandler.php
    @@ -5,12 +5,26 @@
    +      // Block content entity does not expose the status field. Make content
    +      // translation status field visible instead.
    +      $form['content_translation']['status']['#access'] = TRUE;
    

    Not sure about this part...

  2. +++ b/core/modules/comment/src/CommentTranslationHandler.php
    @@ -41,7 +26,6 @@ public function entityFormEntityBuild($entity_type, EntityInterface $entity, arr
    -      $translation['name'] = $entity->getAuthorName();
    

    This look like a leftover that could be removed.

  3. +++ b/core/modules/content_translation/src/ContentTranslationHandler.php
    @@ -455,6 +455,8 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En
    +        // Show status field if it is not natively provided by the entity type.
    +        '#access' => !$this->hasPublishedStatus(),
    
    @@ -501,6 +503,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En
    +        '#access' => !$this->hasAuthor(),
    
    @@ -510,6 +513,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En
    +        '#access' => !$this->hasCreatedTime(),
    

    I'm not sure whether we need to display content translation metadata fields if native metadata are available but hidden in the form display configuration... So something like: !$this->hasAuthor() || !$form_display->getComponent('uid') or not. That would allow translators to fill the metadata if native metadata is hidden. On the other hand, a site-builder would not be able to hide those fields through UI if they want?

  4. +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationMetadataTrait.php
    @@ -0,0 +1,74 @@
    +trait ContentTranslationMetadataTrait {
    

    This aims to dynamically support all the content entities where \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase or deprecated \Drupal\content_translation\Tests\ContentTranslationUITestBase are used. However, it has a dirty special case for created field.

  5. +++ b/core/modules/node/src/NodeTranslationHandler.php
    @@ -17,14 +17,6 @@ class NodeTranslationHandler extends ContentTranslationHandler {
    -    if (isset($form['content_translation'])) {
    -      // We do not need to show these values on node forms: they inherit the
    -      // basic node property values.
    -      $form['content_translation']['status']['#access'] = FALSE;
    -      $form['content_translation']['name']['#access'] = FALSE;
    -      $form['content_translation']['created']['#access'] = FALSE;
    -    }
    -
    

    By dynamically showing the content translation metadata fields depending on the native metadata fields this becomes obsolete.

  6. +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulChanged.php
    @@ -55,6 +55,12 @@ class EntityTestMulChanged extends EntityTestMul implements EntityChangedInterfa
    +    // Show the created field in the edit form.
    +    $fields['created']->setDisplayOptions('form', [
    +      'type' => 'datetime_timestamp',
    +      'weight' => 10,
    +    ]);
    +
    
    +++ b/core/modules/system/tests/modules/entity_test/src/EntityTestTranslationHandler.php
    @@ -0,0 +1,25 @@
    +/**
    + * Defines the translation handler for entity test entities.
    + */
    +class EntityTestTranslationHandler extends ContentTranslationHandler {
    

    This seems to be a requirement for \Drupal\Tests\content_translation\Functional\ContentTestTranslationUITest.

  7. +++ b/core/modules/system/tests/modules/entity_test/src/EntityTestTranslationHandler.php
    @@ -0,0 +1,25 @@
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state) {
    +    if ($form_state->hasValue('content_translation')) {
    +      $translation = &$form_state->getValue('content_translation');
    +      $translation['created'] = format_date($entity->get('created')->value, 'custom', 'Y-m-d H:i:s O');
    +    }
    +    parent::entityFormEntityBuild($entity_type, $entity, $form, $form_state);
    +  }
    

    I'm wondering why do we need to do this per entity type. In Drupal\content_translation\ContentTranslationHandler::entityFormEntityBuild(), if there is no content translation metadata field value set, we could possibly get those values from the entity itself and the Drupal\entity_test\EntityTestTranslationHandler::entityFormEntityBuild() method would not be needed.

    E.g:

    $created_time = !empty($values['created']) ? strtotime($values['created']) : NULL;
    if (!$value) {
    // @todo: Possibly needs a check whether an entity has created field.
     $value = $entity->getCreatedTime() ?: REQUEST_TIME;
    }
    $metadata->setCreatedTime($value);
    

Status: Needs review » Needs work
mbovan’s picture

Berdir’s picture

Looks quite nice to me, lets get some feedback from @plach about the direction before we continue with it.

  1. +++ b/core/modules/block_content/src/BlockContentTranslationHandler.php
    @@ -5,12 +5,26 @@
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
    +    parent::entityFormAlter($form, $form_state, $entity);
    +
    +    if (isset($form['content_translation'])) {
    +      // Block content entity does not expose the status field. Make content
    +      // translation status field visible instead.
    +      $form['content_translation']['status']['#access'] = TRUE;
    +    }
    +  }
    +
    

    This is actually a temporary state:

    #2834546: UI for publishing/unpublishing block_content blocks

    We should at least add a todo or even consider to postpone..

  2. +++ b/core/modules/comment/src/CommentTranslationHandler.php
    @@ -41,7 +26,6 @@ public function entityFormEntityBuild($entity_type, EntityInterface $entity, arr
           $translation = &$form_state->getValue('content_translation');
           /** @var \Drupal\comment\CommentInterface $entity */
           $translation['status'] = $entity->isPublished();
    -      $translation['name'] = $entity->getAuthorName();
         }
    

    why can we only remove the name but not the status logic?

  3. +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationMetadataTrait.php
    @@ -0,0 +1,74 @@
    +  protected function hasMetadataField($field_name) {
    +    $has_metadata_field = array_key_exists($field_name, $this->fieldStorageDefinitions) && $this->fieldStorageDefinitions[$field_name]->isTranslatable();
    +    // Check if the entity type implements EntityOwnerInterface for uid field.
    +    if ($field_name === 'uid') {
    +      return $has_metadata_field && $this->container->get('entity_type.manager')->getDefinition($this->entityTypeId)->entityClassImplements(EntityOwnerInterface::class);
    +    }
    +
    

    you're actually calling $this->container here anyway, is that just to avoid repeated calls? IMHO not worth it for a test helper.

    you can also use isset($this->fieldStorageDefinitions), array_key_exists() is only necessary when the value of the array key could be NULL

  4. +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
    @@ -49,6 +50,15 @@
     
    +  /**
    +   * {@inheritdoc}
    +   */
    +  protected function setUp() {
    +    parent::setUp();
    +
    +    $this->fieldStorageDefinitions = $this->container->get('entity_field.manager')->getFieldStorageDefinitions($this->entityTypeId);
    +  }
    +
    

    I think this is a rather strange pattern, I know some don't agree but IMHO it is fine to just use \Drupal:: in test code, then you don't need to implement that setUp() method multiple times.

  5. +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulChanged.php
    @@ -55,6 +55,12 @@ class EntityTestMulChanged extends EntityTestMul implements EntityChangedInterfa
     
    +    // Show the created field in the edit form.
    +    $fields['created']->setDisplayOptions('form', [
    +      'type' => 'datetime_timestamp',
    +      'weight' => 10,
    +    ]);
    +
         $fields['changed'] = BaseFieldDefinition::create('changed_test')
    

    those additions are necessary because we test that they are shown/not shown in the generic test?

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

borisson_’s picture

Status: Needs review » Needs work

Setting back to needs work to resolve the issues raised in #16, we should also try to point this issue at @plach for that review.

Manuel Garcia’s picture

Status: Needs work » Needs review

Reroll of #14 - manually fixed conflicts on:

  • core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
  • core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php

Since these moved to using getAccountName()

Triggering test bot by setting to needs review, but this still needs work (see #17).

Manuel Garcia’s picture

Helps if i attach the patch...

Status: Needs review » Needs work

The last submitted patch, 19: 2971390-19.patch, failed testing. View results

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
932 bytes
20.59 KB

Oops!

Manuel Garcia’s picture

I'm new to the patch, but in the hope of pushing this forward here is a bit of work on it:

Re #15:
1. I've added a @TODO for now, hopefully the other issue lands earlier than this.
2. I think we can remove this indeed. Done.
3.

you're actually calling $this->container here anyway, is that just to avoid repeated calls? IMHO not worth it for a test helper.

Not entirely sure what you mean, left as is.

you can also use isset($this->fieldStorageDefinitions), array_key_exists() is only necessary when the value of the array key could be NULL

Done.
4. I have no opinion one way or the other, so left it as is.
5. That would be my guess, left it as is.

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

Status: Needs review » Needs work

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

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
1.24 KB
20.84 KB

Seems like we do need to use array_key_exists()

Status: Needs review » Needs work

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

Manuel Garcia’s picture

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
20.69 KB

Rerolled, manually fixed conflicts on :

  • core/modules/content_translation/src/ContentTranslationHandler.php
  • core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php
  • core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php

Status: Needs review » Needs work

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

Berdir’s picture

  1. +++ b/core/modules/block_content/src/BlockContentTranslationHandler.php
    @@ -14,6 +15,21 @@ class BlockContentTranslationHandler extends ContentTranslationHandler {
    +    if (isset($form['content_translation'])) {
    +      // @TODO this will not be necessary once this issue lands:
    +      // https://www.drupal.org/project/drupal/issues/2899923
    +      // Block content entity does not expose the status field. Make content
    +      // translation status field visible instead.
    +      $form['content_translation']['status']['#access'] = TRUE;
    +    }
    

    Formatting for @todo is not correct, I'd put it below the explanation, lowercase and then the second line needs to be indented by two spaces.

    Also, the issue seems to be wrong, might be my fault, that's the issue for taxonomy status, there should be a separate one for block_content.

  2. +++ b/core/modules/block_content/tests/src/Functional/BlockContentTranslationUITest.php
    @@ -125,6 +125,19 @@ protected function getEditValues($values, $langcode, $new = FALSE) {
    +  protected function hasMetadataField($field_name) {
    +    $result = parent::hasMetadataField($field_name);
    +    // Block content entities has status field but it does not expose it.
    +    if ($field_name === 'status') {
    +      return FALSE;
    

    this should get the same @todo so we don't forget to remove it.

  3. +++ b/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php
    @@ -57,6 +59,15 @@
    +
    +    $this->fieldStorageDefinitions = $this->container->get('entity_field.manager')->getFieldStorageDefinitions($this->entityTypeId);
    +  }
    

    what I mean is that we should drop $this->fieldStorageDefinitions, just get them directly in the trait, also use \Drupal::service() there.

  4. +++ b/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php
    @@ -323,16 +336,15 @@ protected function doTestAuthoringInfo() {
    +      $edit += $this->getMetadataValueAndAssertNoField('created', format_date($values[$langcode]['created'], 'custom', 'Y-m-d H:i:s O'));
    

    format_date() is deprecated, that seems to be the reason for all the test fails.

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
7.29 KB
20.4 KB

Thanks for the review @Berdir!

#30.1 Great catch on the wrong issue, fixed that and the formatting. Linking now to #2834546: UI for publishing/unpublishing block_content blocks
#30.2 Added.
#30.3 Got it, done.
#30.4 Fixed.

Manuel Garcia’s picture

Forgot to remove the setUp from \Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase, sorry test bot...

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

Status: Needs review » Needs work

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

Manuel Garcia’s picture

Re #15.2 - On #12.2 its mentioned that the title could be a leftover that could be removed. However if we remove the line for the status, seems like the status isn't saved. NodeTranslationHandler::entityFormEntityBuild() has the same logic so I believe we need that in place, so re-adding it here.

Manuel Garcia’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 35: 2971390-35.patch, failed testing. View results

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Berdir’s picture

Status: Needs work » Needs review
FileSize
24.92 KB
9.57 KB

Various improvements:

* terms need the same hack now as block_content, this is pretty sad, will talk to @amateescu about this as well if we can provide a more generic solution for this. Maybe check the form display configuration of the field definition?
* Improved the generic test logic to handle widget form elements like status[value] and uid[0][target_id]
* Improved entityFormEntityBuild() to only set the value if the form element is accessible, that works also for the block_content and term cases.
* With that fix, we actually can remove the overrides in node and comment, because the parent doesn't try to override the values anymore.

amateescu’s picture

Discussed a bit with @Berdir and my opinion is that CT should alter the form display for publishable entity types and expose their status field rather than doing it with form alters :)

bkline’s picture

Title: Disallow users to change content translation uid metadata field » Make exposure of translation meta fields conditional
bkline’s picture

Issue summary: View changes

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Berdir’s picture

Rerolled. term status is now exposed, so that's one less to worry about.

Berdir’s picture

Another reroll.

Manuel Garcia’s picture

Berdir’s picture

Version: 8.9.x-dev » 9.0.x-dev
FileSize
19.7 KB

Reroll for 9.0,x, only change is the removed old base test class.

xjm’s picture

Version: 9.0.x-dev » 9.1.x-dev

This would be a minor-only change. Since 8.9.x and 9.0.x are now in beta, I'm moving this to 9.1.x. Thanks!

Anybody’s picture

Whao, thank you all very much, this solved a heavy bug for us after #2899923: UI for publishing/unpublishing taxonomy terms which made it impossible to unpublish commerce product variation translations through the UI! While the core status checkbox could be unchecked in the translation, the content_translation checkbox was disabled="disabled" and could not be changed. That lead to overridden value for the status checkbox. So the status could not be changed to disabled anymore.

In #2899923#76 I posted a screenshot of a further case, where the published status is also affected by this and can not be changed due to the bug:
Checkbox status disabled
Top checkbox is disabled, can not be changed but overrides the checkbox below.

We're using #46 in 8.8.6 in production on a large site since some days and I can finally confirm it works very well and without any problems. Thank you so much.

So RTBC+1 for #46 on 8.x. Would be very helpful to also fix this in 8.9.x as follow-up fix for #2899923. I don't see this as a new feature, but much more as an important bugfix for a broken UI as described above.

Anybody’s picture

Hi @Berdir & @xjm, is this ready for RTBC? And do we have a chance to backport this as written in #49 to also fix 8.x installations where this bug is also still unfixed?

hchonov’s picture

It is tagged as "Needs issue summary update". I would go through the patch after the IS is updated to reflect the taken decisions.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Berdir’s picture

Status: Needs review » Needs work

The last submitted patch, 53: 2971390-53.patch, failed testing. View results

anmolgoyal74’s picture

Status: Needs work » Needs review
FileSize
19.7 KB
1.17 KB

Updated deprecation notices.

Status: Needs review » Needs work

The last submitted patch, 55: 2971390-55.patch, failed testing. View results

Berdir’s picture

Status: Needs work » Needs review
FileSize
21.67 KB
1.98 KB

Thanks for the updates. The changes to ContentTranslationWorkflowsTest that are failing are pretty new, so that makes sense. Another (test) entity type with "inconsistent" field definitions (a status field without form display configuration) though, that is a bit trickier, Will get back to that in a follow-up comment.

Berdir’s picture

So, this patch does have basically two effects:

a) Prevents duplicate author/created/status fields from showing up if already exposed as widgets in the given entity form. Some entity types like node and comment have custom handlers in place to hide those fields, but most entity types don't, even in core. For example taxonomy terms and media. So this causes a change for those entity types but I think that might be acceptable in a minor release. The duplicate fields are very confusing and cause bugs, like overwriting the actual field widgets.

b) The logic for showing/hiding those extra fields automatically is however tied to just whether the field exists or not and not if it's visible in the form. For entity types that have for example a status field but don't show it in the UI (like block_content and test entities in core), that results then in neither the regular status field nor the content translation status field being exposed. To keep the current behavior in e.g. block_content, that results in having to override it to show those fields anyway and some entity types need form display configuration for our translation tests to work.

Like this:

+++ b/core/modules/block_content/src/BlockContentTranslationHandler.php
@@ -5,12 +5,28 @@
+
+    if (isset($form['content_translation'])) {
+      // Block content entities do not expose the status field. Make the content
+      // translation status field visible instead.
+      // @todo This will not be necessary once this issue lands:
+      //   https://www.drupal.org/project/drupal/issues/2834546
+      $form['content_translation']['status']['#access'] = TRUE;
+    }
+  }

Question is: How much change is allowed and how strict do we need to be with BC with these changes? Form structures are not included in our BC promise, but what about form structures by a default implementation of an entity handler?

Options:

1) This is fine, we're OK with the change and move forward. Hopefully block_content will eventually expose the status field and we can remove these overrides again.

2) We check not whether an entity type has a field but also if it is enabled in the current form display. I don't like this, seems very unpredictable. Maybe you don't need the node author/created field on a node type, hide it and then instead one pops up from content_translation and only on translations? Yep, weird.

3) We make the new behavior strictly opt-in, with a new base class maybe or a entity type definition flag. You need to explicitly set that in D9 and in D10 it becomes the default and the old class is removed (or the new opt-in flag removed). That would mean no unexpected changes happen to your entity type, but a lot of contrib/custom entity types would then also not benefit from these imho rather important UX fixes unless they explicitly change something in their code. Not in D9 anyway. And they would only get deprecation messages if they have explicit content_translation test coverage. If they would, they'd have already customized this.

Thoughts?

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Berdir’s picture

Another reroll due to test conflicts.

Berdir’s picture

Another one.

Berdir’s picture

Another reroll, this time conflicted on PHP 8.1 related changes in EntityTestMulRevPub.php.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Anybody’s picture

Thanks @Berdir! Just wanted to inform that we're using the patch(es) successfully since #46. So far RTBC +1.

Sadly I'm not experienced enough in this topic to decide on #58, Who could?

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
144 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Berdir’s picture

Status: Needs work » Needs review
FileSize
21.13 KB

git apply -3 still appllied fine.

smustgrave’s picture

Status: Needs review » Needs work

For the issue summary update.

Haven't done a review yet.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mathilde_dumond’s picture

I updated the summary

mathilde_dumond’s picture

Issue summary: View changes

small fix in the summary about the blocks published state

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Bug Smash Initiative, +Needs Review Queue Initiative

Confirmed the issue on a standard install
Adding a 2nd language for the Image media bundle
Applied patch #68 and am no longer seeing the duplicates

Berdir’s picture

Thanks, really hoping this will finally land :)

+++ b/core/modules/block_content/src/BlockContentTranslationHandler.php
@@ -5,12 +5,28 @@
 
+  /**
+   * {@inheritdoc}
+   */
+  public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
+    parent::entityFormAlter($form, $form_state, $entity);
+
+    if (isset($form['content_translation'])) {
+      // Block content entities do not expose the status field. Make the content
+      // translation status field visible instead.
+      // @todo This will not be necessary once this issue lands:
+      //   https://www.drupal.org/project/drupal/issues/2834546
+      $form['content_translation']['status']['#access'] = TRUE;
+    }
+  }
+

As mentioned before and also in the issue summary. this part is a bit weird and an edge case between a change and a bugfix.

This is keeping the current status, which is arguably strange as the default translation has no status, but the translations then do.

We could also say it's a bugfix, there shouldn't be a translation status, but people might have unpublished translations and then they couldn't publish them anymore.

I think this is very unlikely to happen to any other contrib/custom entity type, either they have a status, and then also a UI or not.

quietone’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review
FileSize
2.3 KB
21.11 KB

I'm triaging RTBC issues.

I read the IS and comments. I did not find unanswered questions. Both #15 and #22.1 question whether this should be postponed on #2834546: UI for publishing/unpublishing block_content blocks. There wasn't any discussion about that. Should this be postponed? I've added this question to the remaining tasks.

I read the comments in the patch and had the following thoughts. Since this is testing against 10.1 instead of 11.x I will make a new patch for item 2 below.

  1. +++ b/core/modules/block_content/src/BlockContentTranslationHandler.php
    @@ -5,12 +5,28 @@
    +      // @todo This will not be necessary once this issue lands:
    +      //   https://www.drupal.org/project/drupal/issues/2834546
    

    It would be more helpful in the @todo gave a hint at what to do here. It is to remove that next line? But then what is the purpose of the form alter? And I guess this is not needed if the other issue is completed first, which goes back to the postponing question.

    This applies to the other instances of the @todo as well.

  2. +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationMetadataTrait.php
    @@ -0,0 +1,77 @@
    + * Provides helps to assert content translation meta data fields.
    

    A bit of incorrect grammar here I think. How about "Provides methods to assert ..."

quietone’s picture

I don't think the question about postponing and #75.1 block this from RTBC. But I really shouldn't restore RTBC because of the edit I made to a comment.

Berdir’s picture

> Both #15 and #22.1 question whether this should be postponed on #2834546: UI for publishing/unpublishing block_content blocks. Should this be postponed? I've added this question to the remaining tasks.

:shrug:

It would simplify the patch, but we've been soft-blocked by that issue for 5 years now. It's classified as a feature, this is a bug that fixes some pretty annoying issues for multilingual sites.

Nothing changes if we get this in compared to HEAD for blocks, we just need a bit of a workaround for it, which the other issue can easily remove again. The change that happens is technically also correct, if the module for some reason doesn't want to have a status visible, why should translations? We're just doing this for BC. Thinking this through, this whole concept maybe shouldn't exist at all, it's a leftover of Drupal 7 really where modules didn't have the ability to have translatable base fields/properties. Of course, no idea how to remove it now in a way that is backwards compatible.

IMHO the hidden concern is the last paragraph of #74, whether or not there are any custom or contrib entity types with a similar case, we would have never thought of that without the current state of block_content. IMHO it's fairly unlikely. I did just create a change record to notify about the UI changes and impacts on entity types: https://www.drupal.org/node/3383265.

The comment change in #75 is fine, the interdiff seems a bit confused about some line changes, but I think nothing changed there.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

For what it's worth I am trying to get #2834546: UI for publishing/unpublishing block_content blocks into 10.2 or 10.3. But since there could be some back n forth on that one agree with @Berdir about moving this forward.

quietone’s picture

@Berdir, thanks for the explanation.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
FileSize
85 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

kostyashupenko’s picture

Status: Needs work » Needs review
FileSize
21.12 KB

Rerolled

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

All green from reroll. Restoring status

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 81: 2971390-81.patch, failed testing. View results

andypost’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 81: 2971390-81.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Seems unrelated

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work

The Needs Review Queue Bot tested this issue.

While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Rerunning tests but patch still applies cleanly.

smustgrave’s picture

Status: Reviewed & tested by the community » Needs work

Found out why there's no MR

Anybody’s picture

@smustgrave what does #89 mean? Or should it mean "Find" (active)

Berdir’s picture

Status: Needs work » Needs review

Created MR and rerolled.

smustgrave’s picture

Status: Needs review » Needs work

Left some comments that I should of noticed before but appears to have phpcs errors also.

Thanks for picking this one back up.