TextFormat.php

Same filename in this branch
  1. 8.9.x core/modules/filter/src/Element/TextFormat.php
Same filename in other branches
  1. 9 core/modules/config_translation/src/FormElement/TextFormat.php
  2. 9 core/modules/filter/src/Element/TextFormat.php
  3. 10 core/modules/config_translation/src/FormElement/TextFormat.php
  4. 10 core/modules/filter/src/Element/TextFormat.php
  5. 11.x core/modules/config_translation/src/FormElement/TextFormat.php
  6. 11.x core/modules/filter/src/Element/TextFormat.php

Namespace

Drupal\config_translation\FormElement

File

core/modules/config_translation/src/FormElement/TextFormat.php

View source
<?php

namespace Drupal\config_translation\FormElement;

use Drupal\Core\Language\LanguageInterface;

/**
 * Defines the text_format element for the configuration translation interface.
 */
class TextFormat extends FormElementBase {
    
    /**
     * {@inheritdoc}
     */
    public function getSourceElement(LanguageInterface $source_language, $source_config) {
        // Instead of the formatted output show a disabled textarea. This allows for
        // easier side-by-side comparison, especially with formats with text
        // editors.
        return $this->getTranslationElement($source_language, $source_config, $source_config) + [
            '#value' => $source_config['value'],
            '#disabled' => TRUE,
            '#allow_focus' => TRUE,
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {
        return [
            '#type' => 'text_format',
            // Override the #default_value property from the parent class.
'#default_value' => $translation_config['value'],
            '#format' => $translation_config['format'],
            // @see \Drupal\config_translation\Element\FormElementBase::getTranslationElement()
'#allowed_formats' => [
                $source_config['format'],
            ],
        ] + parent::getTranslationElement($translation_language, $source_config, $translation_config);
    }

}

Classes

Title Deprecated Summary
TextFormat Defines the text_format element for the configuration translation interface.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.