Problem/Motivation

See #3110954: Paragraphs field translatability checked by default when reusing fields.

I think this is a bug/inconsistency in Field UI.

New fields added in the UI default to not-translatable, per #2143291: Clarify handling of field translatability that is done so explicitly, with a comment.

However, when re-using an existing storage then that line is missing and those fields are then translatable by default.

This is especially awkward when translation is not enabled for a bundle, as then the checkbox is disabled and it can't be changed.

This was last touched by #1963340: Change field UI so that adding a field is a separate task, didn't check if that introduced this problem or just moved things around.

This has been like this for a long time, but I think this is a bug that we should fix.

Proposed resolution

Also set translatable => FALSE when creating a field for an existing field storage.

Remaining tasks

Tests

User interface changes

API changes

Data model changes

Release notes snippet

Comments

Berdir created an issue. See original summary.

berdir’s picture

Status: Active » Needs review
StatusFileSize
new677 bytes
primsi’s picture

Adding tests.

berdir’s picture

Status: Needs review » Needs work
+++ b/core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php
@@ -781,4 +781,23 @@ public function testNonExistentFieldUrls() {
+  public function testTranslationDefaults() {
+    $this->createField();
+    $field_storage = FieldStorageConfig::loadByName('node', 'field_' . $this->fieldNameInput);
+    $this->assertTrue($field_storage->isTranslatable(), 'Field storage settings were found.');
+
+    $field = FieldConfig::loadByName('node', $this->contentType, 'field_'. $this->fieldNameInput);
+    $this->assertFalse($field->isTranslatable(), 'Field storage settings were found.');
+
+    $this->addExistingField();
+    $field_storage = FieldStorageConfig::loadByName('node', 'field_' . $this->fieldNameInput);
+    $this->assertTrue($field_storage->isTranslatable(), 'Field storage settings were found.');
+
+    $field = FieldConfig::loadByName('node', $this->contentType, 'field_'. $this->fieldNameInput);
+    $this->assertFalse($field->isTranslatable(), 'Field storage settings were found.');

the message on the assertTrue/False is confusing, lets add a description for what we expect/why.

primsi’s picture

Status: Needs work » Needs review
StatusFileSize
new1.66 KB
new3.05 KB

... copycat leftover. Fixed now, but I am not sure if the storage one that I came up with makes that much more sense.

plach’s picture

Looks good and works as advertised, RTBC +1

it would be good to post a test-only version of the patch.

primsi’s picture

Seems like I wasn't testing that correctly after all - adding an existing field to a content type with the same field. Hopefully addressed that now.

The last submitted patch, 7: field-translatable-3111550-7.testonly.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

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.

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.

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.

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
StatusFileSize
new162 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
Issue tags: -Needs tests
StatusFileSize
new2.55 KB
new3.2 KB

Conflicted with [##2717319] but I think it's still needed.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Agreed this would be nice

Seems to have build errors

berdir’s picture

Title: New fields added through UI are not translatable by default, but they are when re-using existing storage » Tests for: New fields added through UI are not translatable by default, but they are when re-using existing storage
Category: Bug report » Task
Status: Needs work » Needs review
StatusFileSize
new2.56 KB

Yeah, old tests.

Also, conflicted again already in #3346682: Improve re-use an existing field user experience and I think this became kind of a duplicate as the refactoring there seems to have fixed this too.

I assume that was more an unintended side effect even though I didn't look at that other issue, so I doubt tests were added for this. Changing it to a task to add test coverage.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new892 bytes
new2.56 KB

Tests look good and pass locally. Just fixing up a super minor issue.

quietone’s picture

Title: Tests for: New fields added through UI are not translatable by default, but they are when re-using existing storage » Test that new fields are translatable when re-using existing storage but not translatable when added from the UI

  • lauriii committed 357b600b on 10.1.x
    Issue #3111550 by Primsi, Berdir, smustgrave: Test that new fields are...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed 357b600 and pushed to 10.1.x. Thanks!

Status: Fixed » Closed (fixed)

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