[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/view/form/ -> PHUIFormInsetView.php (source)

   1  <?php
   2  
   3  final class PHUIFormInsetView extends AphrontView {
   4  
   5    private $title;
   6    private $description;
   7    private $rightButton;
   8    private $content;
   9    private $hidden = array();
  10  
  11    private $divAttributes;
  12  
  13    public function setTitle($title) {
  14      $this->title = $title;
  15      return $this;
  16    }
  17  
  18    public function setDescription($description) {
  19      $this->description = $description;
  20      return $this;
  21    }
  22  
  23    public function setRightButton($button) {
  24      $this->rightButton = $button;
  25      return $this;
  26    }
  27  
  28    public function setContent($content) {
  29      $this->content = $content;
  30      return $this;
  31    }
  32  
  33    public function addHiddenInput($key, $value) {
  34      if (is_array($value)) {
  35        foreach ($value as $hidden_key => $hidden_value) {
  36          $this->hidden[] = array($key.'['.$hidden_key.']', $hidden_value);
  37        }
  38      } else {
  39        $this->hidden[] = array($key, $value);
  40      }
  41      return $this;
  42    }
  43  
  44    public function addDivAttributes(array $attributes) {
  45      $this->divAttributes = $attributes;
  46      return $this;
  47    }
  48  
  49    public function render() {
  50  
  51      $right_button = $desc = '';
  52  
  53      $hidden_inputs = array();
  54      foreach ($this->hidden as $inp) {
  55        list($key, $value) = $inp;
  56        $hidden_inputs[] = phutil_tag(
  57          'input',
  58          array(
  59            'type' => 'hidden',
  60            'name' => $key,
  61            'value' => $value,
  62          ));
  63      }
  64  
  65      if ($this->rightButton) {
  66        $right_button = phutil_tag(
  67          'div',
  68          array(
  69            'style' => 'float: right;',
  70          ),
  71          $this->rightButton);
  72        $right_button = phutil_tag_div('grouped', $right_button);
  73      }
  74  
  75      if ($this->description) {
  76        $desc = phutil_tag(
  77          'p',
  78          array(),
  79          $this->description);
  80      }
  81  
  82      $div_attributes = $this->divAttributes;
  83      $classes = array('phui-form-inset');
  84      if (isset($div_attributes['class'])) {
  85        $classes[] = $div_attributes['class'];
  86      }
  87  
  88      $div_attributes['class'] = implode(' ', $classes);
  89  
  90      $content = $hidden_inputs;
  91      $content[] = $right_button;
  92      $content[] = $desc;
  93  
  94      if ($this->title != '') {
  95        array_unshift($content, phutil_tag('h1', array(), $this->title));
  96      }
  97  
  98      if ($this->content) {
  99        $content[] = $this->content;
 100      }
 101  
 102      $content = array_merge($content, $this->renderChildren());
 103  
 104      return phutil_tag('div', $div_attributes, $content);
 105    }
 106  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1