3 final class AphrontFormView
extends AphrontView
{
6 private $method = 'POST';
8 private $data = array();
12 private $sigils = array();
14 private $controls = array();
15 private $fullWidth = false;
16 private $classes = array();
18 public function setMetadata($metadata) {
19 $this->metadata
= $metadata;
23 public function getMetadata() {
24 return $this->metadata
;
27 public function setID($id) {
32 public function setAction($action) {
33 $this->action
= $action;
37 public function setMethod($method) {
38 $this->method
= $method;
42 public function setEncType($enc_type) {
43 $this->encType
= $enc_type;
47 public function addHiddenInput($key, $value) {
48 $this->data
[$key] = $value;
52 public function setWorkflow($workflow) {
53 $this->workflow
= $workflow;
57 public function addSigil($sigil) {
58 $this->sigils
[] = $sigil;
62 public function addClass($class) {
63 $this->classes
[] = $class;
67 public function setFullWidth($full_width) {
68 $this->fullWidth
= $full_width;
72 public function getFullWidth() {
73 return $this->fullWidth
;
76 public function appendInstructions($text) {
77 return $this->appendChild(
81 'class' => 'aphront-form-instructions',
86 public function appendRemarkupInstructions($remarkup) {
87 $view = $this->newInstructionsRemarkupView($remarkup);
88 return $this->appendInstructions($view);
91 public function newInstructionsRemarkupView($remarkup) {
92 $viewer = $this->getViewer();
93 $view = new PHUIRemarkupView($viewer, $remarkup);
95 $view->setRemarkupOptions(
97 PHUIRemarkupView
::OPTION_PRESERVE_LINEBREAKS
=> false,
103 public function buildLayoutView() {
104 foreach ($this->controls
as $control) {
105 $control->setViewer($this->getViewer());
106 $control->willRender();
109 return id(new PHUIFormLayoutView())
110 ->setFullWidth($this->getFullWidth())
111 ->appendChild($this->renderDataInputs())
112 ->appendChild($this->renderChildren());
117 * Append a control to the form.
119 * This method behaves like @{method:appendChild}, but it only takes
120 * controls. It will propagate some information from the form to the
121 * control to simplify rendering.
123 * @param AphrontFormControl Control to append.
126 public function appendControl(AphrontFormControl
$control) {
127 $this->controls
[] = $control;
128 return $this->appendChild($control);
132 public function render() {
133 require_celerity_resource('phui-form-view-css');
135 $layout = $this->buildLayoutView();
137 if (!$this->hasViewer()) {
140 'You must pass the user to %s.',
144 $sigils = $this->sigils
;
145 if ($this->workflow
) {
146 $sigils[] = 'workflow';
149 return phabricator_form(
152 'class' => implode(' ', $this->classes
),
153 'action' => $this->action
,
154 'method' => $this->method
,
155 'enctype' => $this->encType
,
156 'sigil' => $sigils ?
implode(' ', $sigils) : null,
157 'meta' => $this->metadata
,
163 private function renderDataInputs() {
165 foreach ($this->data
as $key => $value) {
166 if ($value === null) {
169 $inputs[] = phutil_tag(