Textarea.php 788 Bytes
Newer Older
1 2 3 4
<?php

namespace Drupal\config_translation\FormElement;

5
use Drupal\Core\Language\LanguageInterface;
6 7 8 9

/**
 * Defines the textarea element for the configuration translation interface.
 */
10
class Textarea extends FormElementBase {
11 12 13 14

  /**
   * {@inheritdoc}
   */
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 20
    $rows = max($rows_words, $rows_newlines);

21
    return [
22 23
      '#type' => 'textarea',
      '#rows' => $rows,
24
    ] + parent::getTranslationElement($translation_language, $source_config, $translation_config);
25 26 27
  }

}