"Hide non translatable fields" does not work for custom blocks

Created on 22 January 2020, almost 5 years ago
Updated 3 April 2023, over 1 year ago

The content translation "Hide non translatable fields on translation forms" option does not work for custom blocks. When using symmetric translation, all block fields are displayed on the block translation form, even fields that are not translatable.

Steps to reproduce:

  1. Create a custom block type with two text fields, named: "Translatable text" and "Nontranslatable text"
  2. On /admin/config/regional/content-language, enable translation for the custom block type. Enable translation for the "Translatable text" field, and disable translation for the "Nontranslatable text" field.
  3. Enable the "Hide non translatable fields on translation forms" option for the custom block type.
  4. Create a layout builder node.
  5. Add an instance of your custom block type to the layout and save.
  6. Create a translation of the node.
  7. Edit the layout of the translation, and edit your custom block.

Expected result: The "Nontranslatable text" field should not be visible when editing the translation.
Actual result: The "Nontranslatable text" field is visible when editing the translation.

🐛 Bug report
Status

RTBC

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • 🇦🇹Austria fago Vienna

    Patch is straight forward and comes with test coverage. Works without issues still, please merge!

  • Status changed to Needs work over 1 year ago
  • 🇦🇹Austria arthur_lorenz Vienna

    This patch only works well on simple fields like text fields. On more complex fields, e.g. entity_reference_revisions, you are not able to translate the referenced entity and its fields.

  • 🇸🇮Slovenia useernamee Ljubljana

    I can confirm what arthur_lorenz wrote - this patch breaks complex fields translatability. We have paragraph blocks and their fields are translatable if this patch is not used. When this patch is applied, fields on paragraphs in block are no longer translatable.

  • 🇦🇹Austria fago Vienna

    so what about having a list of form-widgets that are still shown? we could make a simple hook that allows modules to add more form widgets to the list.

  • 🇸🇮Slovenia useernamee Ljubljana

    @fago When making paragraphs translatable entity revision field should not be made translatable on the parent entity ( docs ). So I guess patch from #8 works as expected but when using inline form widgets, it's effect is just not desirable. So to make things a bit more clear, where should the logic to not hide the field be configured - should it be per content type, per field or site-wide per widget? So the end result would be hide untranslatable fields except for widget we don't want too.

  • 🇦🇹Austria fago Vienna

    I don't think it needs config, why not generally allow known widgets like inline-form-widgets? The hook would be for allowing modules to add further widgets.

  • heddn Nicaragua
    +++ b/src/Form/BlockContentInlineBlockTranslateForm.php
    @@ -136,6 +137,18 @@ final class BlockContentInlineBlockTranslateForm extends BlockContentForm {
    +        if (($field_definition = $this->entity->getFieldDefinition($key))
    

    Could we add:

    $ignored_types = array_flip(['actions', 'value', 'hidden', 'vertical_tabs', 'token', 'details', 'link']);
    // Ignore non-widget form elements.
    if (isset($ignored_types[$form[$key]['#type']])) {
    continue;
    }

    Would that resolve the paragraphs fields?

Production build 0.71.5 2024