4308969e2dcc18702f0b1b8f26985c1b2c039469
[yaffs-website] / web / core / modules / config_translation / src / FormElement / Textarea.php
1 <?php
2
3 namespace Drupal\config_translation\FormElement;
4
5 use Drupal\Core\Language\LanguageInterface;
6
7 /**
8  * Defines the textarea element for the configuration translation interface.
9  */
10 class Textarea extends FormElementBase {
11
12   /**
13    * {@inheritdoc}
14    */
15   public function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {
16     // Estimate a comfortable size of the input textarea.
17     $rows_words = ceil(str_word_count($translation_config) / 5);
18     $rows_newlines = substr_count($translation_config, "\n") + 1;
19     $rows = max($rows_words, $rows_newlines);
20
21     return [
22       '#type' => 'textarea',
23       '#rows' => $rows,
24     ] + parent::getTranslationElement($translation_language, $source_config, $translation_config);
25   }
26
27 }