for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Faulancer\Form\Type\Base;
use Faulancer\Form\Type\AbstractType;
/**
* Class Checkbox
*
* @package Faulancer\Form\Type\Base
* @author Florian Knapp <[email protected]>
*/
class Checkbox extends AbstractType
{
/** @var string */
protected $inputType = 'input';
protected $element = '';
* @return self
public function create()
parent::create();
$output = '';
if (!empty($this->definition['default'])) {
$output .= '<' . $this->inputType;
$output .= ' type="hidden"';
$output .= ' name="' . $this->definition['attributes']['name'] . '"';
$output .= ' ' . 'value="' . $this->definition['default'] . '"';
$output .= '/>';
}
foreach ($this->definition['attributes'] as $attr => $value) {
$output .= ' ' . $attr . '="' . $value . '" ';
if (!empty($this->getValue()) && $this->definition['attributes']['value'] === $this->getValue()) {
$output .= ' checked="checked"';
} elseif (empty($this->getValue()) && isset($this->definition['checked']) && $this->definition['checked'] === true) {
$this->element = $output;
return $this;