Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
52ca2d35
Commit
52ca2d35
authored
Mar 21, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tweaking the Form::macro method.
parent
c18dcecb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
32 deletions
+31
-32
form.php
laravel/form.php
+31
-32
No files found.
laravel/form.php
View file @
52ca2d35
...
...
@@ -7,28 +7,25 @@ class Form {
*
* @var array
*/
p
rotected
static
$labels
=
array
();
p
ublic
static
$labels
=
array
();
/**
* The registered custom
inputs
* The registered custom
macros.
*
* @var array
*/
protected
static
$inputs
=
array
();
public
static
$macros
=
array
();
/**
* Dynamically handle calls to custom registered inputs.
* Registers a custom macro.
*
* @param string $name
* @param Closure $input
* @return void
*/
public
static
function
__callStatic
(
$method
,
$parameters
)
public
static
function
macro
(
$name
,
$macro
)
{
if
(
isset
(
static
::
$inputs
[
$method
]))
{
return
call_user_func_array
(
static
::
$inputs
[
$method
],
$parameters
);
}
throw
new
\Exception
(
"Method [
$method
] does not exist."
);
static
::
$macros
[
$name
]
=
$macro
;
}
/**
...
...
@@ -74,8 +71,7 @@ class Form {
// Since PUT and DELETE methods are not actually supported by HTML forms,
// 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
// hidden element to determine the request method.
// and set the actual request method variable to POST.
if
(
$method
==
'PUT'
or
$method
==
'DELETE'
)
{
$append
=
static
::
hidden
(
Request
::
spoofer
,
$method
);
...
...
@@ -84,19 +80,6 @@ class Form {
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.
*
...
...
@@ -576,8 +559,7 @@ class Form {
{
// 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
// label names as this makes it convenient to give input elements
// the same ID as their corresponding labels.
// label names so labels and their elements have the same ID.
if
(
array_key_exists
(
'id'
,
$attributes
))
{
return
$attributes
[
'id'
];
...
...
@@ -589,4 +571,21 @@ class Form {
}
}
/**
* 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."
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment