2011-01-16 13:51:39 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class AphrontFormView extends AphrontView {
|
|
|
|
|
|
|
|
private $action;
|
|
|
|
private $method = 'POST';
|
|
|
|
private $header;
|
|
|
|
private $data = array();
|
2011-01-22 18:33:00 -08:00
|
|
|
private $encType;
|
2011-02-05 22:36:21 -08:00
|
|
|
private $workflow;
|
2011-03-22 17:08:08 -07:00
|
|
|
private $id;
|
2013-08-26 11:53:11 -07:00
|
|
|
private $shaded = false;
|
2012-12-11 14:02:29 -08:00
|
|
|
private $sigils = array();
|
2013-07-28 18:21:22 -07:00
|
|
|
private $metadata;
|
|
|
|
|
|
|
|
|
|
|
|
public function setMetadata($metadata) {
|
|
|
|
$this->metadata = $metadata;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMetadata() {
|
|
|
|
return $this->metadata;
|
|
|
|
}
|
2012-08-15 14:15:12 -07:00
|
|
|
|
2011-03-22 17:08:08 -07:00
|
|
|
public function setID($id) {
|
|
|
|
$this->id = $id;
|
|
|
|
return $this;
|
2011-01-30 18:52:29 -08:00
|
|
|
}
|
2011-01-16 13:51:39 -08:00
|
|
|
|
|
|
|
public function setAction($action) {
|
|
|
|
$this->action = $action;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setMethod($method) {
|
|
|
|
$this->method = $method;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-01-22 18:33:00 -08:00
|
|
|
public function setEncType($enc_type) {
|
|
|
|
$this->encType = $enc_type;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-08-26 11:53:11 -07:00
|
|
|
public function setShaded($shaded) {
|
|
|
|
$this->shaded = $shaded;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-01-25 17:17:19 -08:00
|
|
|
public function addHiddenInput($key, $value) {
|
|
|
|
$this->data[$key] = $value;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-02-05 22:36:21 -08:00
|
|
|
public function setWorkflow($workflow) {
|
|
|
|
$this->workflow = $workflow;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-12-11 14:02:29 -08:00
|
|
|
public function addSigil($sigil) {
|
|
|
|
$this->sigils[] = $sigil;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-05-24 12:38:27 -07:00
|
|
|
public function appendInstructions($text) {
|
|
|
|
return $this->appendChild(
|
|
|
|
phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'aphront-form-instructions',
|
|
|
|
),
|
|
|
|
$text));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function appendRemarkupInstructions($remarkup) {
|
|
|
|
return $this->appendInstructions(
|
|
|
|
PhabricatorMarkupEngine::renderOneObject(
|
|
|
|
id(new PhabricatorMarkupOneOff())->setContent($remarkup),
|
|
|
|
'default',
|
|
|
|
$this->getUser()));
|
|
|
|
}
|
|
|
|
|
2011-01-16 13:51:39 -08:00
|
|
|
public function render() {
|
2012-08-15 14:15:12 -07:00
|
|
|
|
2013-08-26 11:53:11 -07:00
|
|
|
require_celerity_resource('phui-form-view-css');
|
|
|
|
$layout = id (new PHUIFormLayoutView())
|
2011-06-09 15:28:29 -07:00
|
|
|
->appendChild($this->renderDataInputs())
|
2013-02-13 14:50:15 -08:00
|
|
|
->appendChild($this->renderChildren());
|
2011-06-09 15:28:29 -07:00
|
|
|
|
2012-02-02 18:09:51 -08:00
|
|
|
if (!$this->user) {
|
2013-03-01 15:37:32 -08:00
|
|
|
throw new Exception(pht('You must pass the user to AphrontFormView.'));
|
2012-02-02 18:09:51 -08:00
|
|
|
}
|
|
|
|
|
2012-12-11 14:02:29 -08:00
|
|
|
$sigils = $this->sigils;
|
|
|
|
if ($this->workflow) {
|
|
|
|
$sigils[] = 'workflow';
|
|
|
|
}
|
|
|
|
|
2013-02-07 15:18:34 -08:00
|
|
|
return phabricator_form(
|
2012-02-02 18:09:51 -08:00
|
|
|
$this->user,
|
2011-01-16 13:51:39 -08:00
|
|
|
array(
|
2013-08-26 11:53:11 -07:00
|
|
|
'class' => $this->shaded ? 'phui-form-shaded' : null,
|
2011-01-22 18:33:00 -08:00
|
|
|
'action' => $this->action,
|
|
|
|
'method' => $this->method,
|
|
|
|
'enctype' => $this->encType,
|
2012-12-11 14:02:29 -08:00
|
|
|
'sigil' => $sigils ? implode(' ', $sigils) : null,
|
2013-07-28 18:21:22 -07:00
|
|
|
'meta' => $this->metadata,
|
2011-03-22 17:08:08 -07:00
|
|
|
'id' => $this->id,
|
2011-01-16 13:51:39 -08:00
|
|
|
),
|
2011-06-09 15:28:29 -07:00
|
|
|
$layout->render());
|
2011-01-16 13:51:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderDataInputs() {
|
|
|
|
$inputs = array();
|
2012-02-02 18:09:51 -08:00
|
|
|
foreach ($this->data as $key => $value) {
|
2011-01-25 17:17:19 -08:00
|
|
|
if ($value === null) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-17 18:39:02 -08:00
|
|
|
$inputs[] = phutil_tag(
|
2011-01-16 13:51:39 -08:00
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => $key,
|
|
|
|
'value' => $value,
|
|
|
|
));
|
|
|
|
}
|
2013-02-07 15:18:34 -08:00
|
|
|
return $inputs;
|
2011-01-16 13:51:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|