[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class AphrontFormView extends AphrontView { 4 5 private $action; 6 private $method = 'POST'; 7 private $header; 8 private $data = array(); 9 private $encType; 10 private $workflow; 11 private $id; 12 private $shaded = false; 13 private $sigils = array(); 14 private $metadata; 15 16 17 public function setMetadata($metadata) { 18 $this->metadata = $metadata; 19 return $this; 20 } 21 22 public function getMetadata() { 23 return $this->metadata; 24 } 25 26 public function setID($id) { 27 $this->id = $id; 28 return $this; 29 } 30 31 public function setAction($action) { 32 $this->action = $action; 33 return $this; 34 } 35 36 public function setMethod($method) { 37 $this->method = $method; 38 return $this; 39 } 40 41 public function setEncType($enc_type) { 42 $this->encType = $enc_type; 43 return $this; 44 } 45 46 public function setShaded($shaded) { 47 $this->shaded = $shaded; 48 return $this; 49 } 50 51 public function addHiddenInput($key, $value) { 52 $this->data[$key] = $value; 53 return $this; 54 } 55 56 public function setWorkflow($workflow) { 57 $this->workflow = $workflow; 58 return $this; 59 } 60 61 public function addSigil($sigil) { 62 $this->sigils[] = $sigil; 63 return $this; 64 } 65 66 public function appendInstructions($text) { 67 return $this->appendChild( 68 phutil_tag( 69 'div', 70 array( 71 'class' => 'aphront-form-instructions', 72 ), 73 $text)); 74 } 75 76 public function appendRemarkupInstructions($remarkup) { 77 return $this->appendInstructions( 78 PhabricatorMarkupEngine::renderOneObject( 79 id(new PhabricatorMarkupOneOff())->setContent($remarkup), 80 'default', 81 $this->getUser())); 82 } 83 84 public function buildLayoutView() { 85 return id(new PHUIFormLayoutView()) 86 ->appendChild($this->renderDataInputs()) 87 ->appendChild($this->renderChildren()); 88 } 89 90 public function render() { 91 require_celerity_resource('phui-form-view-css'); 92 93 $layout = $this->buildLayoutView(); 94 95 if (!$this->user) { 96 throw new Exception(pht('You must pass the user to AphrontFormView.')); 97 } 98 99 $sigils = $this->sigils; 100 if ($this->workflow) { 101 $sigils[] = 'workflow'; 102 } 103 104 return phabricator_form( 105 $this->user, 106 array( 107 'class' => $this->shaded ? 'phui-form-shaded' : null, 108 'action' => $this->action, 109 'method' => $this->method, 110 'enctype' => $this->encType, 111 'sigil' => $sigils ? implode(' ', $sigils) : null, 112 'meta' => $this->metadata, 113 'id' => $this->id, 114 ), 115 $layout->render()); 116 } 117 118 private function renderDataInputs() { 119 $inputs = array(); 120 foreach ($this->data as $key => $value) { 121 if ($value === null) { 122 continue; 123 } 124 $inputs[] = phutil_tag( 125 'input', 126 array( 127 'type' => 'hidden', 128 'name' => $key, 129 'value' => $value, 130 )); 131 } 132 return $inputs; 133 } 134 135 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |