@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 AphrontFormHandlesControl extends AphrontFormControl {
4
5 private $isInvisible;
6
7 protected function getCustomControlClass() {
8 return 'aphront-form-control-handles';
9 }
10
11 public function setIsInvisible($is_invisible) {
12 $this->isInvisible = $is_invisible;
13 return $this;
14 }
15
16 public function getIsInvisible() {
17 return $this->isInvisible;
18 }
19
20 protected function shouldRender() {
21 return (bool)$this->getValue();
22 }
23
24 public function getLabel() {
25 // TODO: This is a bit funky and still rendering a few pixels of padding
26 // on the form, but there's currently no way to get a control to only emit
27 // hidden inputs. Clean this up eventually.
28
29 if ($this->getIsInvisible()) {
30 return null;
31 }
32
33 return parent::getLabel();
34 }
35
36 protected function renderInput() {
37 $value = $this->getValue();
38 $viewer = $this->getUser();
39
40 $out = array();
41
42 if (!$this->getIsInvisible()) {
43 $list = $viewer->renderHandleList($value);
44 $list = id(new PHUIBoxView())
45 ->addPadding(PHUI::PADDING_SMALL_TOP)
46 ->appendChild($list);
47 $out[] = $list;
48 }
49
50 $inputs = array();
51 foreach ($value as $phid) {
52 $inputs[] = phutil_tag(
53 'input',
54 array(
55 'type' => 'hidden',
56 'name' => $this->getName().'[]',
57 'value' => $phid,
58 ));
59 }
60 $out[] = $inputs;
61
62 return $out;
63 }
64
65}