"Fossies" - the Fresh Open Source Software Archive

Member "drupal-9.1.0-rc1/core/modules/config_translation/src/FormElement/TextFormat.php" (18 Nov 2020, 1353 Bytes) of package /linux/www/drupal-9.1.0-rc1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 
    3 namespace Drupal\config_translation\FormElement;
    4 
    5 use Drupal\Core\Language\LanguageInterface;
    6 
    7 /**
    8  * Defines the text_format element for the configuration translation interface.
    9  */
   10 class TextFormat extends FormElementBase {
   11 
   12   /**
   13    * {@inheritdoc}
   14    */
   15   public function getSourceElement(LanguageInterface $source_language, $source_config) {
   16     // Instead of the formatted output show a disabled textarea. This allows for
   17     // easier side-by-side comparison, especially with formats with text
   18     // editors.
   19     return $this->getTranslationElement($source_language, $source_config, $source_config) + [
   20       '#value' => $source_config['value'],
   21       '#disabled' => TRUE,
   22       '#allow_focus' => TRUE,
   23     ];
   24   }
   25 
   26   /**
   27    * {@inheritdoc}
   28    */
   29   public function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {
   30     return [
   31       '#type' => 'text_format',
   32       // Override the #default_value property from the parent class.
   33       '#default_value' => $translation_config['value'],
   34       '#format' => $translation_config['format'],
   35       // @see \Drupal\config_translation\Element\FormElementBase::getTranslationElement()
   36       '#allowed_formats' => [$source_config['format']],
   37     ] + parent::getTranslationElement($translation_language, $source_config, $translation_config);
   38   }
   39 
   40 }