/**
  * @since  2014-09-17
  * @author Patrick Forget <*****@*****.**>
  */
 public function format(\Informant\Input\BaseElement $input, $options = array())
 {
     $value = $input->getValue() === null ? $input->getDefaultValue() : $input->getValue();
     $inputName = $input->getName() === null ? $input->getId() : $input->getName();
     $itemWrapperOptions = isset($options['itemWrapperOptions']) ? $options['itemWrapperOptions'] : array();
     $baseItemAttributes = isset($options['itemAttributes']) ? $options['itemAttributes'] : array();
     ob_start();
     foreach ($input->getChoices() as $key => $label) {
         $itemAttributes = array('value' => $key, 'type' => 'radio', 'name' => $inputName);
         if ($key == $value) {
             $itemAttributes['checked'] = 'true';
         }
         //if
         echo h::tag('label', array_merge($itemWrapperOptions, array('content' => h::tag('input', array('attributes' => array_merge($baseItemAttributes, $itemAttributes), 'appendContent' => " {$label}", 'shortClosing' => true)), 'rawContent' => true)));
     }
     //foreach
     $radioListCode = ob_get_contents();
     ob_end_clean();
     $attributes = array('id' => $input->getId());
     if (isset($options['attributes'])) {
         $attributes = array_merge($attributes, $options['attributes']);
     }
     //if
     return h::tag('div', array('attributes' => $attributes, 'content' => $radioListCode, 'rawContent' => true));
 }
Ejemplo n.º 2
0
 /**
  * @since  2014-09-23
  * @author Patrick Forget <*****@*****.**>
  */
 public function format(\Informant\Input\BaseElement $input, $options = array())
 {
     $formatter = $options['formatter'];
     $formatterName = $options['formatterName'];
     switch ($formatterName) {
         case 'radioListInput':
             $inputOptions = isset($options['inputOptions']) ? $options['inputOptions'] : array();
             $errorOptions = isset($options['errorOptions']) ? $options['errorOptions'] : array();
             if (!isset($options['attributes'])) {
                 $options['attributes'] = array();
             }
             //if
             $options['attributes'] = array_merge(array('class' => 'form-group'), $options['attributes']);
             ob_start();
             echo h::tag('label', array('content' => $input->getLabel(), 'rawContent' => true));
             echo $formatter->radioListInput($input, $options);
             echo $formatter->error($input, $errorOptions);
             $content = ob_get_contents();
             ob_end_clean();
             $attributes = array('class' => substr($formatterName, 0, -5));
             if (isset($options['attributes'])) {
                 $attributes = array_merge($attributes, $options['attributes']);
             }
             //if
             return h::tag('div', array('attributes' => $attributes, 'content' => $content, 'rawContent' => true)) . "\n";
             break;
         case 'checkboxInput':
         case 'radioInput':
             $inputOptions = isset($options['inputOptions']) ? $options['inputOptions'] : array();
             $errorOptions = isset($options['errorOptions']) ? $options['errorOptions'] : array();
             ob_start();
             echo h::tag('label', array('content' => call_user_func(array($formatter, $formatterName), $input, $inputOptions) . ' ' . $input->getLabel(), 'rawContent' => true));
             echo $formatter->error($input, $errorOptions);
             $content = ob_get_contents();
             ob_end_clean();
             $attributes = array('class' => substr($formatterName, 0, -5));
             if (isset($options['attributes'])) {
                 $attributes = array_merge($attributes, $options['attributes']);
             }
             //if
             return h::tag('div', array('attributes' => $attributes, 'content' => $content, 'rawContent' => true)) . "\n";
             break;
         default:
             if (!isset($options['attributes'])) {
                 $options['attributes'] = array();
             }
             //if
             $options['attributes'] = array_merge(array('class' => 'form-group'), $options['attributes']);
             return parent::format($input, $options);
             break;
     }
     //switch
 }
 /**
  * @since  2014-09-20
  * @author Patrick Forget <*****@*****.**>
  */
 public function format(\Informant\Input\BaseElement $input, $options = array())
 {
     if (!isset($options['attributes'])) {
         $options['attributes'] = array();
     }
     //if
     $value = $input->getValue();
     if ($value !== null && $value == $input->getDefaultValue()) {
         $options['attributes']['checked'] = 'true';
     }
     //if
     $options['attributes']['type'] = 'checkbox';
     return parent::format($input, $options);
 }
 /**
  * @since  2014-09-17
  * @author Patrick Forget <*****@*****.**>
  */
 public function format(\Informant\Input\BaseElement $input, $options = array())
 {
     $value = $input->getValue() === null ? $input->getDefaultValue() : $input->getValue();
     ob_start();
     foreach ($input->getChoices() as $key => $label) {
         $optionAttributes = array('value' => $key);
         if ($key == $value) {
             $optionAttributes['selected'] = 'true';
         }
         //if
         echo h::tag('option', array('attributes' => $optionAttributes, 'content' => $label));
     }
     //foreach
     $optionsCode = ob_get_contents();
     ob_end_clean();
     $attributes = array('id' => $input->getId(), 'name' => $input->getId());
     if ($input->getMultipleValues() === true) {
         $attributes['multiple'] = 'true';
         $attributes['name'] .= '[]';
     }
     //if
     if (isset($options['attributes'])) {
         $attributes = array_merge($attributes, $options['attributes']);
     }
     //if
     return h::tag('select', array('attributes' => $attributes, 'content' => $optionsCode, 'rawContent' => true));
 }
Ejemplo n.º 5
0
 /**
  * @since  2014-05-09
  * @author Patrick Forget <*****@*****.**>
  */
 public function format(\Informant\Input\BaseElement $input, $options = array())
 {
     $attributes = array('id' => $input->getId(), 'name' => $input->getName() === null ? $input->getId() : $input->getName(), 'value' => $input->getValue() === null ? $input->getDefaultValue() : $input->getValue());
     if ($input->getMultipleValues() === true) {
         $attributes['name'] .= '[]';
     }
     //if
     if (isset($options['attributes'])) {
         $attributes = array_merge($attributes, $options['attributes']);
     }
     //if
     return h::tag('input', array('attributes' => $attributes, 'shortClosing' => true));
 }
Ejemplo n.º 6
0
 /**
  * @since  2014-05-08
  * @author Patrick Forget <*****@*****.**>
  */
 protected static function getDefaultValues()
 {
     static $defaultValues = null;
     if ($defaultValues === null) {
         $defaultValues = array_merge(parent::getDefaultValues(), array('required' => false, 'name' => null, 'defaultValue' => '', 'value' => null, 'multipleValues' => false));
     }
     //if
     return $defaultValues;
 }
Ejemplo n.º 7
0
 /**
  * @since  2014-05-09
  * @author Patrick Forget <*****@*****.**>
  */
 protected function getMessages(\Informant\Input\BaseElement $input)
 {
     return $input->getErrors();
 }