/** * Factory method * * @param string $type Element type * @param array $options Element options * @param array $attr HTML attributes * @return Element */ public function build($type, array $options = [], array $attr = []) { if (isset($this->builder)) { return $this->builder->build($type, $options, $attr); } $this->convertCustomType($type, $options, $attr); if (is_string($type) && $type[0] === ':') { $method = 'build' . str_replace(' ', '', ucwords(preg_replace('/[^a-zA-Z0-9]/', ' ', substr($type, 1)))); if (!method_exists($this, $method)) { throw new \Exception("Unknown field '" . substr($type, 1) . "'"); } return $this->{$method}(null, $options, $attr); } $element = FormBuilder::element($type, $options, $attr); $element->builder = $this; return $element; }
/** * Check if element is a button * * @param Element $element * @return boolean */ protected static function isButton($element) { if (!$element instanceof Element) { return false; } return $element instanceof Button || $element instanceof Input && in_array($element->attr['type'], ['button', 'submit', 'reset']) || $element->hasClass('btn') || $element->getOption('btn'); }