Example #1
0
 /**
  * Return a string representation of a field
  *
  * @return String
  * @author Dan Cox
  */
 public function output(array $extras = array())
 {
     if ($this->field->value == $this->field->values) {
         $extras = array_merge($extras, ['checked' => 'checked']);
     }
     return sprintf('<input type="%1$s" name="%2$s" id="%2$s" value="%3$s" %4$s/>', $this->field->type, $this->field->id, $this->field->value, Str::arrayToHtmlProperties($extras));
 }
Example #2
0
 /**
  * Returns a string representation of the select field
  *
  * @return String
  * @author Dan Cox
  */
 public function output(array $extras = array())
 {
     $options = '';
     foreach ($this->field->values as $key => $value) {
         $options .= sprintf('<option value="%s"%s>%s</option>', $value, $this->field->value == $value ? 'selected="selected"' : '', $key);
     }
     return sprintf('<select name="%1$s" id="%1$s" %2$s>%3$s</select>', $this->field->id, Str::arrayToHtmlProperties($extras), $options);
 }
Example #3
0
 /**
  * Returns string representation of the field
  *
  * @return String
  * @author Dan Cox
  */
 public function output(array $extras = array())
 {
     $group = '';
     foreach ($this->field->values as $label => $value) {
         $e = $extras;
         if ($this->field->value == $value) {
             $e = array_merge($e, ['checked' => 'checked']);
         }
         $group .= '<label>';
         $group .= sprintf('<input type="%s" name="%s" value="%s" %s/>', $this->field->type, $this->field->id, $value, Str::arrayToHtmlProperties($e));
         $group .= sprintf('%s</label>', $label);
     }
     return $group;
 }
Example #4
0
 /**
  * Output field
  *
  * @param Array $extras
  * @param String $value
  * @return String
  * @author Dan Cox
  */
 public function output(array $extras = array())
 {
     return sprintf('<textarea name="%1$s" id="%1$s" %2$s>%3$s</textarea>', $this->field->id, Str::arrayToHtmlProperties($extras), $this->field->value);
 }
Example #5
0
 /**
  * Outputs string representation of the input field
  *
  * @param Array $extras
  * @param String $value
  * @return String
  * @author Dan Cox
  */
 public function output(array $extras = array())
 {
     return sprintf('<input type="%1$s" name="%2$s" id="%2$s" value="%3$s" %4$s/>', $this->field->type, $this->field->id, $this->field->value, Str::arrayToHtmlProperties($extras));
 }
Example #6
0
 /**
  * Creates a label element
  *
  * @param Array $elementExtras
  * @return String
  * @author Dan Cox
  */
 public function label(array $elementExtras = array())
 {
     $elementExtras = array_merge($elementExtras, ['for' => $this->id]);
     return sprintf('<label %s>%s</label>', Str::arrayToHtmlProperties($elementExtras), $this->label);
 }
Example #7
0
 /**
  * Returns an opening form element
  *
  * @param Array $properties
  * @return String
  * @author Dan Cox
  */
 public function open(array $properties = array())
 {
     $this->generateCSRF();
     $html = '';
     $html .= sprintf('<form action="%s" method="%s" %s>', $this->url, strtoupper($this->method), Str::arrayToHtmlProperties($properties));
     $html .= sprintf('<input type="hidden" name="token" value="%s" />', $this->token);
     return $html;
 }
Example #8
0
 /**
  * Hooks onto the pre update event to update slug if title has changed
  *
  * @ORM\PreUpdate
  * @return void
  * @author Dan Cox
  */
 public function preUpdateSlug()
 {
     if (!is_null($this->title) && Str::slug($this->title) !== $this->slug) {
         $this->slug = Str::slug($this->title);
     }
 }
Example #9
0
 /**
  * Test converting an array to html properties
  *
  * @return void
  * @author Dan Cox
  */
 public function test_htmlProperties()
 {
     $arr = array('class' => 'my-class', 'data-object' => '5');
     $this->assertEquals('class="my-class" data-object="5"', Str::arrayToHtmlProperties($arr));
 }