/** * 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)); }
/** * 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); }
/** * 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; }
/** * 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); }
/** * 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)); }
/** * 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); }
/** * 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; }
/** * 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); } }
/** * 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)); }