You are here

protected function TranslateBlockForm::createTranslationElement in Layout Builder Symmetric Translations 8

Creates translation element.

Parameters

\Drupal\Core\Language\LanguageInterface $source_language: The source language.

\Drupal\Core\Language\LanguageInterface $translation_language: The translation language.

\Drupal\Core\TypedData\TraversableTypedDataInterface $typed_data: The typed data of the configuration settings.

array $translated_configuration: The translated configuration.

Return value

array The translation element render array.

1 call to TranslateBlockForm::createTranslationElement()
TranslateBlockForm::buildForm in src/Form/TranslateBlockForm.php
Builds the block translation form.

File

src/Form/TranslateBlockForm.php, line 168

Class

TranslateBlockForm
Provides a form to translate a block plugin in the Layout Builder.

Namespace

Drupal\layout_builder_st\Form

Code

protected function createTranslationElement(LanguageInterface $source_language, LanguageInterface $translation_language, TraversableTypedDataInterface $typed_data, array $translated_configuration) {
  if ($this->moduleHandler
    ->moduleExists('config_translation')) {

    // If config_translation is installed let it handle creating complex
    // schema.
    $form_element = ConfigTranslationFormBase::createFormElement($typed_data);
    $element_build = $form_element
      ->getTranslationBuild($source_language, $translation_language, $typed_data
      ->getValue(), $translated_configuration, []);
  }
  else {

    // If config_translation is not enabled only provide the 'label'
    // translation.
    if (($label_data = $typed_data
      ->get('label')) && $label_data instanceof StringData) {
      $element_build['label']['source'] = [
        '#type' => 'item',
        '#title' => $this
          ->t('Label'),
        '#markup' => $label_data
          ->getValue() ?: '(' . $this
          ->t('Empty') . ')',
        '#parents' => [
          'source',
          'label',
        ],
      ];
      $element_build['label']['translation'] = [
        '#type' => 'textfield',
        '#title' => $this
          ->t('Label'),
        '#default_value' => isset($translated_configuration['label']) ? $translated_configuration['label'] : '',
        '#parents' => [
          'translation',
          'label',
        ],
      ];
    }
  }
  $element_build['#tree'] = TRUE;
  return $element_build;
}