Textarea.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Drupal\Core\Render\Element;
  3. use Drupal\Core\Form\FormStateInterface;
  4. /**
  5. * Provides a form element for input of multiple-line text.
  6. *
  7. * Properties:
  8. * - #rows: Number of rows in the text box.
  9. * - #cols: Number of columns in the text box.
  10. * - #resizable: Controls whether the text area is resizable. Allowed values
  11. * are "none", "vertical", "horizontal", or "both" (defaults to "vertical").
  12. * - #maxlength: The maximum amount of characters to accept as input.
  13. *
  14. * Usage example:
  15. * @code
  16. * $form['text'] = array(
  17. * '#type' => 'textarea',
  18. * '#title' => $this->t('Text'),
  19. * );
  20. * @endcode
  21. *
  22. * @see \Drupal\Core\Render\Element\Textfield
  23. * @see \Drupal\filter\Element\TextFormat
  24. *
  25. * @FormElement("textarea")
  26. */
  27. class Textarea extends FormElement {
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function getInfo() {
  32. $class = get_class($this);
  33. return [
  34. '#input' => TRUE,
  35. '#cols' => 60,
  36. '#rows' => 5,
  37. '#resizable' => 'vertical',
  38. '#process' => [
  39. [$class, 'processAjaxForm'],
  40. [$class, 'processGroup'],
  41. ],
  42. '#pre_render' => [
  43. [$class, 'preRenderGroup'],
  44. ],
  45. '#theme' => 'textarea',
  46. '#theme_wrappers' => ['form_element'],
  47. ];
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
  53. if ($input !== FALSE && $input !== NULL) {
  54. // This should be a string, but allow other scalars since they might be
  55. // valid input in programmatic form submissions.
  56. return is_scalar($input) ? (string) $input : '';
  57. }
  58. return NULL;
  59. }
  60. }