Tweaking the Form::macro method.
This commit is contained in:
parent
c18dcecb00
commit
52ca2d35e7
|
@ -7,28 +7,25 @@ class Form {
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected static $labels = array();
|
public static $labels = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The registered custom inputs
|
* The registered custom macros.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
public static $macros = array();
|
||||||
protected static $inputs = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dynamically handle calls to custom registered inputs.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static function __callStatic($method, $parameters)
|
/**
|
||||||
|
* Registers a custom macro.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param Closure $input
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function macro($name, $macro)
|
||||||
{
|
{
|
||||||
if (isset(static::$inputs[$method]))
|
static::$macros[$name] = $macro;
|
||||||
{
|
|
||||||
return call_user_func_array(static::$inputs[$method], $parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \Exception("Method [$method] does not exist.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,8 +71,7 @@ public static function open($action = null, $method = 'POST', $attributes = arra
|
||||||
|
|
||||||
// Since PUT and DELETE methods are not actually supported by HTML forms,
|
// Since PUT and DELETE methods are not actually supported by HTML forms,
|
||||||
// we'll create a hidden input element that contains the request method
|
// we'll create a hidden input element that contains the request method
|
||||||
// and set the actual request method to POST. Laravel will look for the
|
// and set the actual request method variable to POST.
|
||||||
// hidden element to determine the request method.
|
|
||||||
if ($method == 'PUT' or $method == 'DELETE')
|
if ($method == 'PUT' or $method == 'DELETE')
|
||||||
{
|
{
|
||||||
$append = static::hidden(Request::spoofer, $method);
|
$append = static::hidden(Request::spoofer, $method);
|
||||||
|
@ -83,19 +79,6 @@ public static function open($action = null, $method = 'POST', $attributes = arra
|
||||||
|
|
||||||
return '<form'.HTML::attributes($attributes).'>'.$append.PHP_EOL;
|
return '<form'.HTML::attributes($attributes).'>'.$append.PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a custom input
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @param Closure $input
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static function register($name, $input)
|
|
||||||
{
|
|
||||||
static::$inputs[$name] = $input;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the appropriate request method to use for a form.
|
* Determine the appropriate request method to use for a form.
|
||||||
|
@ -576,8 +559,7 @@ protected static function id($name, $attributes)
|
||||||
{
|
{
|
||||||
// If an ID has been explicitly specified in the attributes, we will
|
// If an ID has been explicitly specified in the attributes, we will
|
||||||
// use that ID. Otherwise, we will look for an ID in the array of
|
// use that ID. Otherwise, we will look for an ID in the array of
|
||||||
// label names as this makes it convenient to give input elements
|
// label names so labels and their elements have the same ID.
|
||||||
// the same ID as their corresponding labels.
|
|
||||||
if (array_key_exists('id', $attributes))
|
if (array_key_exists('id', $attributes))
|
||||||
{
|
{
|
||||||
return $attributes['id'];
|
return $attributes['id'];
|
||||||
|
@ -589,4 +571,21 @@ protected static function id($name, $attributes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dynamically handle calls to custom macros.
|
||||||
|
*
|
||||||
|
* @param string $method
|
||||||
|
* @param array $parameters
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function __callStatic($method, $parameters)
|
||||||
|
{
|
||||||
|
if (isset(static::$inputs[$method]))
|
||||||
|
{
|
||||||
|
return call_user_func_array(static::$inputs[$method], $parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \Exception("Method [$method] does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue