@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * @concrete-extensible
5 */
6class AphrontFormTextAreaControl extends AphrontFormControl {
7
8 const HEIGHT_VERY_SHORT = 'very-short';
9 const HEIGHT_SHORT = 'short';
10 const HEIGHT_VERY_TALL = 'very-tall';
11
12 private $height;
13 private $readOnly;
14 private $customClass;
15 private $placeHolder;
16 private $sigil;
17
18 public function setSigil($sigil) {
19 $this->sigil = $sigil;
20 return $this;
21 }
22
23 public function getSigil() {
24 return $this->sigil;
25 }
26
27 public function setPlaceHolder($place_holder) {
28 $this->placeHolder = $place_holder;
29 return $this;
30 }
31 private function getPlaceHolder() {
32 return $this->placeHolder;
33 }
34
35 /**
36 * @param string $height One of the AphrontFormTextAreaControl::HEIGHT_*
37 * variables
38 */
39 public function setHeight($height) {
40 $this->height = $height;
41 return $this;
42 }
43
44 public function setReadOnly($read_only) {
45 $this->readOnly = $read_only;
46 return $this;
47 }
48
49 protected function getReadOnly() {
50 return $this->readOnly;
51 }
52
53 protected function getCustomControlClass() {
54 return 'aphront-form-control-textarea';
55 }
56
57 public function setCustomClass($custom_class) {
58 $this->customClass = $custom_class;
59 return $this;
60 }
61
62 /**
63 * @return PhutilSafeHTML HTML textarea element
64 */
65 protected function renderInput() {
66
67 $height_class = null;
68 switch ($this->height) {
69 case self::HEIGHT_VERY_SHORT:
70 case self::HEIGHT_SHORT:
71 case self::HEIGHT_VERY_TALL:
72 $height_class = 'aphront-textarea-'.$this->height;
73 break;
74 }
75
76 $classes = array();
77 $classes[] = $height_class;
78 $classes[] = $this->customClass;
79 $classes = trim(implode(' ', $classes));
80
81 // NOTE: This needs to be string cast, because if we pass `null` the
82 // tag will be self-closed and some browsers aren't thrilled about that.
83 $value = phutil_string_cast($this->getValue());
84
85 // NOTE: We also need to prefix the string with a newline, because browsers
86 // ignore a newline immediately after a <textarea> tag, so they'll eat
87 // leading newlines if we don't do this. See T8707.
88 $value = "\n".$value;
89
90 // Prefer the corresponding textarea "label" as "aria-label". If an element
91 // does not have one, fall back to element "name".
92 $aria_label = $this->getLabel();
93 if (!phutil_nonempty_string($aria_label)) {
94 $aria_label = $this->getName();
95 }
96
97 return javelin_tag(
98 'textarea',
99 array(
100 'name' => $this->getName(),
101 'aria-label' => $aria_label,
102 'disabled' => $this->getDisabled() ? 'disabled' : null,
103 'readonly' => $this->getReadOnly() ? 'readonly' : null,
104 'class' => $classes,
105 'style' => $this->getControlStyle(),
106 'id' => $this->getID(),
107 'sigil' => $this->sigil,
108 'placeholder' => $this->getPlaceHolder(),
109 ),
110 $value);
111 }
112
113}