@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
3final class AphrontTokenizerTemplateView extends AphrontView {
4
5 private $value;
6 private $name;
7 private $id;
8 private $browseURI;
9 private $initialValue;
10
11 public function setBrowseURI($browse_uri) {
12 $this->browseURI = $browse_uri;
13 return $this;
14 }
15
16 public function setID($id) {
17 $this->id = $id;
18 return $this;
19 }
20
21 /**
22 * @param array<PhabricatorTypeaheadTokenView> $value
23 */
24 public function setValue(array $value) {
25 assert_instances_of($value, PhabricatorTypeaheadTokenView::class);
26 $this->value = $value;
27 return $this;
28 }
29
30 public function getValue() {
31 return $this->value;
32 }
33
34 public function setName($name) {
35 $this->name = $name;
36 return $this;
37 }
38
39 public function getName() {
40 return $this->name;
41 }
42
43 public function setInitialValue(array $initial_value) {
44 $this->initialValue = $initial_value;
45 return $this;
46 }
47
48 public function getInitialValue() {
49 return $this->initialValue;
50 }
51
52 public function render() {
53 require_celerity_resource('aphront-tokenizer-control-css');
54
55 $id = $this->id;
56 $name = $this->getName();
57 $tokens = nonempty($this->getValue(), array());
58
59 $input = javelin_tag(
60 'input',
61 array(
62 'mustcapture' => true,
63 'name' => $name,
64 'class' => 'jx-tokenizer-input',
65 'sigil' => 'tokenizer-input',
66 'style' => 'width: 0px;',
67 'disabled' => 'disabled',
68 'type' => 'text',
69 ));
70
71 $content = $tokens;
72 $content[] = $input;
73 $content[] = phutil_tag('div', array('style' => 'clear: both;'), '');
74
75 $container = javelin_tag(
76 'div',
77 array(
78 'id' => $id,
79 'class' => 'jx-tokenizer-container',
80 'sigil' => 'tokenizer-container',
81 ),
82 $content);
83
84 $browse = id(new PHUIButtonView())
85 ->setTag('a')
86 ->setIcon('fa-search')
87 ->addClass('tokenizer-browse-button')
88 ->setColor(PHUIButtonView::GREY)
89 ->addSigil('tokenizer-browse');
90
91 $classes = array();
92 $classes[] = 'jx-tokenizer-frame';
93
94 if ($this->browseURI) {
95 $classes[] = 'has-browse';
96 }
97
98 $initial = array();
99 $initial_value = $this->getInitialValue();
100 if ($initial_value) {
101 foreach ($this->getInitialValue() as $value) {
102 $initial[] = phutil_tag(
103 'input',
104 array(
105 'type' => 'hidden',
106 'name' => $name.'.initial[]',
107 'value' => $value,
108 ));
109 }
110 }
111
112 $frame = javelin_tag(
113 'div',
114 array(
115 'class' => implode(' ', $classes),
116 'sigil' => 'tokenizer-frame',
117 ),
118 array(
119 $container,
120 $browse,
121 $initial,
122 ));
123
124 return $frame;
125 }
126
127}