Problem/Motivation

Field translatability is defined at two levels:

  • At field storage definition level it's defined whether the field supports translation and thus should have a storage supporting multilingual values.
  • At field definition level it's defined whether the field is enabled for translation and thus actually be assigned multilingual values.

Currently the Field UI creates fields with untranslatable storage, which makes the Content Translation module simply ignore them, so they will never be translated as no UI to enable translation is exposed.

Proposed resolution

Make the Field UI create fields with multilingual storage by default, which is the same default we have in FieldStorageConfig, this way it will be possible to enable or disable translation later. Additionally clean-up the places that were not properly updated when introducing the split between field storage definition and field definition in the first place.

Remaining tasks

  • Commit

User interface changes

None

API changes

None

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because field translation is broken for all fields created through the UI.
Issue priority Critical because this severely reduces the content translation functionality for any entity type relying on the Field UI.

Comments

plach’s picture

Priority: Normal » Critical
Issue tags: +API change

Actually critical :)

plach’s picture

Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new1.48 KB

Let's try this as a start.

plach’s picture

Issue summary: View changes
Issue tags: +sprint

Status: Needs review » Needs work

The last submitted patch, 2: field-ui_untranslatable-2401497-2.patch, failed testing.

plach’s picture

Status: Needs work » Needs review
StatusFileSize
new11.6 KB

This should be better.

Test coverage additions in the next patch.

plach’s picture

Status: Needs review » Needs work

The last submitted patch, 5: field-ui_untranslatable-2401497-5.patch, failed testing.

plach’s picture

Status: Needs work » Needs review
StatusFileSize
new6.42 KB
new17.31 KB
new127.77 KB

This should fix the last failures, no additional test coverage yet.

Now I recall why FieldConfig is currently defaulting to TRUE: that's to be consistent with base fields, which unless overridden share the same value for field storage and field translatability. With the current patch, this is the scenario we get with JS disabled on the Content Translation settings page, before the form is submitted for the first time:

However after saving the form, base field definitions are overriden with untranslatable values for all untranslatable bundles.

Not sure whether we want to retain this inconsistency or the one I was trying to fix by changing FieldConfig's default (Field API vs Field UI). Since fixing the latter involves an API change probably we should keep the current behavior after all. The clean-up implemented here should be ok anyway.

plach’s picture

Issue tags: -Needs tests
StatusFileSize
new2.47 KB
new19.78 KB
new2.47 KB

Added test coverage.

plach’s picture

StatusFileSize
new955 bytes
new20.2 KB

Slightly improved test coverage.

The last submitted patch, 9: field-ui_untranslatable-2401497-9-test-fail.patch, failed testing.

plach’s picture

Issue tags: +D8 upgrade path
plach’s picture

andypost’s picture

+++ b/core/lib/Drupal/Core/Field/FieldConfigBase.php
@@ -115,11 +115,11 @@
    * Flag indicating whether the field is translatable.
...
-   * Defaults to TRUE.
+   * Defaults to FALSE.
...
-  public $translatable = TRUE;
+  public $translatable = FALSE;

Why not make this configurable when field is created?

gábor hojtsy’s picture

@plach: I believe the UI problem shown in #8 is preexisting and is not in scope here neither is due to this patch right? So I don't think we should be concerned with that.

gábor hojtsy’s picture

Fix tags.

andypost’s picture

Priority: Critical » Major
Related issues: +#552604: Adding new fields leads to a confusing "Field settings" form

The related issue changes the forms

berdir’s picture

Priority: Major » Critical

Why the prio change?

This completely breaks the ability to have translated fields, without a workaround other than manually editing config files. Sounds critical to me.

plach’s picture

StatusFileSize
new140.68 KB

@andy:

Well, configurable fields always support multilingual storage, so I don't think it's worth providing an additional concept for users to understand, when in most cases if they don't want a field to be translated they just need to leave translation disabled. The main idea behind making the value alterable, is that modules like Commerce relying on configurable fields for their business logic (not sure that's still the case, btw) can make sure that the Price field, for instance, is never enabled for translation.

@Gabor:

Nope, the inconsistency shown in #8 is introduced by the patch. This is HEAD after performing a clean installation and disabling JS:

To sum up: I think the patch is ready to go, but I changed my mind about the default status of FieldConfig::$translatable. Reverting that change should just imply of a few changes in some assertions and default config files, as most of the changes performed to tests should be good anyway.

gábor hojtsy’s picture

@plach: ok I meant that the entity is not enabled for translation while the fields are; what would be a bad side effect of making them still default to TRUE for their configuration? sounds like that would still be ignored unless the entity bundle is also configured to be translatable?

plach’s picture

Yep, in fact I think that the HEAD inconsistency where the UI creates untranslatable Field definitions as opposed to the API that creates translatable Field definitions, is way less problematic than having base fields and configurable fields behaving differently when handled via the API.

Btw, I just realized that ContentEntityBase::addTranslation() lets you create an entity translation programmatically even if the bundle is not enabled for translation, which is not a Good Thing.

If there are no objections I'd roll a new version of the patch reverting the change to the FieldConfig::$translatable default.

gábor hojtsy’s picture

That sounds like less of a change compared to how it works currently, so fine with me :)

plach’s picture

StatusFileSize
new17.08 KB
new5 KB

Here it is

plach’s picture

Issue summary: View changes
Issue tags: -API change

Updated summary

andypost’s picture

There's a separate issue for default values for fields. So as bug this RTBC
I just wonders why form hardcodes default values when their defaults should be taken from field entities.

+++ b/core/modules/field_ui/src/Form/FieldStorageAddForm.php
@@ -223,11 +223,13 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t
+    // modules can form_alter() the value for newly created fields. By default
+    // we create field storage as translatable so it will be possible to enable
+    // translation at field level.
...
-      '#value' => FALSE,
+      '#value' => TRUE,

Looks good to me.

gábor hojtsy’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/field_ui/src/Form/FieldStorageAddForm.php
    @@ -223,11 +223,13 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t
    -    // Place the 'translatable' property as an explicit value so that
    -    // contrib modules can form_alter() the value for newly created fields.
    +    // Place the 'translatable' property as an explicit value so that contrib
    +    // modules can form_alter() the value for newly created fields. By default
    +    // we create field storage as translatable so it will be possible to enable
    +    // translation at field level.
         $form['translatable'] = array(
           '#type' => 'value',
    -      '#value' => FALSE,
    +      '#value' => TRUE,
         );
    

    So this is the key change in the patch. I looked into what @andypost asked and there does not seem to be a field storage config instance yet to take default values from. We could create one to init this value but then would throw that away later. That may be better to keep consistency.

  2. diff --git a/core/modules/node/src/Tests/NodeAccessLanguageAwareCombinationTest.php b/core/modules/node/src/Tests/NodeAccessLanguageAwareCombinationTest.php
    index f73ac3b..d0e1ee2 100644
    @@ -58,7 +58,6 @@ protected function setUp() {
           'entity_type' => 'node',
           'type' => 'boolean',
           'cardinality' => 1,
    -      'translatable'  => TRUE,
           'settings' => array(
             'on_label' => 'Private',
             'off_label' => 'Not private',
    @@ -69,6 +68,7 @@ protected function setUp() {
    
    @@ -69,6 +68,7 @@ protected function setUp() {
         entity_create('field_config', array(
           'field_storage' => $field_storage,
           'bundle' => 'page',
    +      'translatable'  => TRUE,
           'widget' => array(
             'type' => 'options_buttons',
           ),
    

    Given that the defaults are now both true for storage and field config, neither the removed, neither the added translatable booleans are needed changes, right? At least the added ones don't need to be added, since it still defaults to TRUE? Not having those extra things in the patch would make it much simpler to review.

berdir’s picture

1. Yes, the thing is that at this point, we do not yet know if we will create a new storage or re-use an existing one. However, it is possible that the refactoring that @amateescu is working on in #552604: Adding new fields leads to a confusing "Field settings" form will change that.

plach’s picture

Status: Needs work » Needs review
StatusFileSize
new8.27 KB
new14.42 KB

I agree with #25, however fixing that feels fairly out of scope here.

About #26.2: I reverted some changes, but I added some more to make sure people can use tests as an example of how code should be written. AAMOF there's no need to set anything to translatable, as the default is TRUE everywhere. I'd like to keep this clean-up because the current test code was not cleaned-up when we split translatability between Field and Field storage, and it's currently quite confusing.

plach’s picture

Issue summary: View changes
plach’s picture

Issue summary: View changes
gábor hojtsy’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

ALl changes look good to me and my concerns are addressed. The test cleanups are good. No need to set things to something they are already set to :D

Looks all good to get in.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 942df46 and pushed to 8.0.x. Thanks!

Thanks for completing the beta evaluation.

  • alexpott committed 942df46 on 8.0.x
    Issue #2401497 by plach: Field UI creates fields that can never be...
gábor hojtsy’s picture

Issue tags: -sprint

Yay, thanks!

yched’s picture

@plach++

Status: Fixed » Closed (fixed)

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