Overview

For symmetric translations it should be possible for a content entity translation to only store the string translatable inputs and rely on the default language translation for other inputs

for instance looking at tests/modules/canvas_test_sdc/components/my-hero/my-hero.component.yml

    heading:
      type: string
      title: Heading
      description: The main heading of the hero
      examples:
        - There goes my hero
        - Submit now
    subheading:
      type: string
      title: Sub-heading
      description: 'See the <a href="https://www.example.com/icons">icon library</a> for icons.'
      examples:
        - Watch him as he goes!
    cta1:
      type: string
      title: CTA 1 text
      examples:
        - View
    # ℹ️ For an example of a CTA that supports only absolute URLs, see the my-cta SDC.
    cta1href:
      type: string
      format: uri-reference
      title: CTA 1 link
      examples:
        - https://example.com
        - /node/1
    cta2:
      type: string
      title: CTA 2 text
      examples:
        - Click
    # @see \Drupal\Core\Template\ComponentsTwigExtension::mergeAdditionalRenderContext()
    attributes:
      type: Drupal\Core\Template\Attribute
      name: Attributes
      title: Attributes

The cta1href and attributes properties should not be translatable.

But if you don't store the cta1href property with the translation you will get the error like

LogicException: inputs.208452de-10d6-4fb8-89a1-10e340b3744c.cta1href: The property cta1href is required.

and

Drupal\Core\Entity\EntityStorageException: inputs.208452de-10d6-4fb8-89a1-10e340b3744c.cta1href: The property cta1href is required.

#3582478: [exploration] Symmetrically translatable config-defined component trees, part 2: change config schema type for `inputs` to avoid indescribable and hence untranslatable JSON blobs deals with similar problem but for config entities that implement \Drupal\canvas\Entity\ComponentTreeConfigEntityBase

There are other problems with making these properties separate elements in forms provided by content_translation and tmgmt_content but this issue only deals with storage and programmatically saving

Proposed resolution

As start update \Drupal\Tests\canvas\Functional\TranslationTest::createCanvasNodeWithTranslation to unset cta1href and attributes in the translation. This will result in the errors above.

Figure out how to solve this. Probably this will mean updating validators and maybe \Drupal\canvas\Plugin\Field\FieldType\ComponentTreeItem, maybe getInputs and getInput

It probably makes sense to look at how #3582478: [exploration] Symmetrically translatable config-defined component trees, part 2: change config schema type for `inputs` to avoid indescribable and hence untranslatable JSON blobs is solving this for config.

Specifically in config/schema/canvas.schema.yml it has

    inputs:
      type: mapping
      class: '\Drupal\canvas\Config\Schema\ComponentSpecificInputs'
      label: 'Input values for each component in the component tree'

ComponentSpecificInputs looks at the component source inputs to determine which ones are translatable. Eventually we will probably want to API to get the translatable properties for a component source but for now we can probably copy some of that logic.

User interface changes

Issue fork canvas-3583684

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:

Comments

tedbow created an issue. See original summary.

tedbow’s picture

Status: Active » Needs work
tedbow’s picture

Assigned: Unassigned » tedbow
wim leers’s picture

Component: … to be triaged » Data model
Issue tags: +Needs ADR
wim leers’s picture

I just realized I thought about something related a ~year ago. See the asymmetric translation explicit input locking: across al component instances and/or per component instance bit in #3520449: [META] Production-ready data storage

tedbow’s picture

still very much a rough sketch of idea. not ready for review