Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Kulya
OpnSense
Commits
ab386c00
Commit
ab386c00
authored
Nov 07, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(mvc) fix previous, support custom prefix in validate()
parent
34c6a6db
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
5 deletions
+8
-5
ApiMutableModelControllerBase.php
...ntrollers/OPNsense/Base/ApiMutableModelControllerBase.php
+8
-5
No files found.
src/opnsense/mvc/app/controllers/OPNsense/Base/ApiMutableModelControllerBase.php
View file @
ab386c00
...
...
@@ -111,11 +111,12 @@ abstract class ApiMutableModelControllerBase extends ApiControllerBase
* Use the reference node and tag to rename validation output for a specific node to a new offset, which makes
* it easier to reference specific uuids without having to use them in the frontend descriptions.
* @param $node reference node, to use as relative offset
* @param $prefix prefix to use when $node is provided (defaults to static::$internalModelName)
* @return array result / validation output
*/
protected
function
validateAndSave
(
$node
=
null
)
protected
function
validateAndSave
(
$node
=
null
,
$prefix
=
null
)
{
$result
=
$this
->
validate
();
$result
=
$this
->
validate
(
$node
,
$prefix
);
if
(
empty
(
$result
[
'result'
]))
{
return
$this
->
save
();
}
...
...
@@ -125,11 +126,13 @@ abstract class ApiMutableModelControllerBase extends ApiControllerBase
/**
* validate this model
* @param $node reference node, to use as relative offset
* @param $prefix prefix to use when $node is provided (defaults to static::$internalModelName)
* @return array result / validation output
*/
protected
function
validate
(
$node
=
null
)
protected
function
validate
(
$node
=
null
,
$prefix
=
null
)
{
$result
=
array
(
"result"
=>
""
);
$resultPrefix
=
empty
(
$prefix
)
?
static
::
$internalModelName
:
$prefix
;
// perform validation
$valMsgs
=
$this
->
getModel
()
->
performValidation
();
foreach
(
$valMsgs
as
$field
=>
$msg
)
{
...
...
@@ -139,10 +142,10 @@ abstract class ApiMutableModelControllerBase extends ApiControllerBase
}
// replace absolute path to attribute for relative one at uuid.
if
(
$node
!=
null
)
{
$fieldnm
=
str_replace
(
$node
->
__reference
,
static
::
$internalModelName
,
$msg
->
getField
());
$fieldnm
=
str_replace
(
$node
->
__reference
,
$resultPrefix
,
$msg
->
getField
());
$result
[
"validations"
][
$fieldnm
]
=
$msg
->
getMessage
();
}
else
{
$result
[
"validations"
][
static
::
$internalModelName
.
"."
.
$msg
->
getField
()]
=
$msg
->
getMessage
();
$result
[
"validations"
][
$resultPrefix
.
"."
.
$msg
->
getField
()]
=
$msg
->
getMessage
();
}
}
return
$result
;
...
...
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