added macro method.
This commit is contained in:
1 parent
28832d5d71
commit
a5751249be
1 file changed
+36
@@ -41,6 +41,13 @@ class FormBuilder {
|
|||||||
*/
|
*/
|
||||||
protected $labels = array();
|
protected $labels = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The registered form builder macros.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $macros = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The reserved form open attributes.
|
* The reserved form open attributes.
|
||||||
*
|
*
|
||||||
@@ -475,6 +482,18 @@ class FormBuilder {
|
|||||||
return '<button'.Html::attributes($attributes).'>'.e($value).'</button>';
|
return '<button'.Html::attributes($attributes).'>'.e($value).'</button>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a custom form macro.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param callable $macro
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function macro($name, $macro)
|
||||||
|
{
|
||||||
|
$this->macros[$name] = $macro;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the form action method.
|
* Parse the form action method.
|
||||||
*
|
*
|
||||||
@@ -591,4 +610,21 @@ class FormBuilder {
|
|||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dynamically handle calls to the form builder.
|
||||||
|
*
|
||||||
|
* @param string $method
|
||||||
|
* @param array $parameters
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function __call($method, $parameters)
|
||||||
|
{
|
||||||
|
if (isset($this->macros[$method]))
|
||||||
|
{
|
||||||
|
return call_user_func_array($this->macros[$method], $parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \BadMethodCallException("Method {$method} does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user