Custom blocks translaion of text_format not avaialble

Created on 15 February 2024, about 1 year ago

Problem/Motivation

Given a block with a text_format field created within a module, adding this block inside a layout, when it gets translated the html content is not copied over to the translated field, nor there is a ckeditor available.
If I use the same block in the main Drupal block layout ( /admin/structure/block ) the html content is copied over to the translation field, although there is no ckeditor but that I think is by design and/or another issue in core.

Steps to reproduce

  public function build() {
    $build = [
      '#type' => 'container',
      'label' => ['#markup' => 'Body: '],
      '#theme' => 'my_module',
    ];
    if (!empty($this->configuration['body'])) {
      $build['body'] = [
        '#type' => 'processed_text',
        '#text' => $this->configuration['body']['value'],
        '#format' => $this->configuration['body']['format'],
      ];
    }
    return $build;
  }
  public function blockForm($form, FormStateInterface $form_state) {
    $body = !empty($this->configuration['body']) ? $this->configuration['body'] : [];
    $form['body'] = [
      '#type' => 'text_format',
      '#title' => 'Body',
      '#format' => isset($body['format']) ? $body['format'] : 'basic_html',
      '#default_value' => isset($body['value']) ? $body['value'] : '',
    ];
    return $form;
  }
  public function blockSubmit($form, FormStateInterface $form_state) {
    $values = $form_state->getValues();
    $this->configuration['body'] = $form_state->getValue('body');
  }
block.settings.my_module:
  type: block_settings
  label: 'Last Item block settings'
  translatable: true
  mapping:
    body:
      type: mapping
      label: 'Free text with text format support'
      mapping:
        value:
          type: text
          label: 'Custom Text'
          translatable: true
        format:
          type: string
          label: 'Text format'
🐛 Bug report
Status

Active

Version

2.13

Component

Code

Created by

🇪🇸Spain cimo75

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

Comments & Activities

Production build 0.71.5 2024