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
4b16c753
Commit
4b16c753
authored
Feb 01, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add post loading event to BaseField
parent
968a31b3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
20 deletions
+34
-20
PageController.php
...se/mvc/app/controllers/OPNsense/Sample/PageController.php
+6
-11
BaseModel.php
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
+2
-1
ArrayField.php
...se/mvc/app/models/OPNsense/Base/FieldTypes/ArrayField.php
+3
-5
BaseField.php
...nse/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
+21
-1
page.volt
src/opnsense/mvc/app/views/OPNsense/Sample/page.volt
+2
-2
No files found.
src/opnsense/mvc/app/controllers/OPNsense/Sample/PageController.php
View file @
4b16c753
...
...
@@ -54,7 +54,7 @@ class PageController extends ControllerBase
$node_found
=
$mdlSample
->
setNodeByReference
(
implode
(
"."
,
$refparts
),
$value
);
// new node in the post which is not on disc, create a new child node
// we need to create new nodes in memory for Array types
if
(
$node_found
==
null
&&
strpos
(
$key
,
'childnodes_section_'
)
!==
false
)
{
if
(
$node_found
==
false
&&
strpos
(
$key
,
'childnodes_section_'
)
!==
false
)
{
// because all the array items are numbered in order, we know that any item not found
// must be a new one.
$mdlSample
->
childnodes
->
section
->
add
();
...
...
@@ -140,17 +140,12 @@ class PageController extends ControllerBase
$cnf
=
Config
::
getInstance
();
$cnf
->
save
();
}
}
// redirect to index
$this
->
dispatcher
->
forward
(
array
(
"action"
=>
"index"
));
// redirect to index
$this
->
dispatcher
->
forward
(
array
(
"action"
=>
"index"
));
}
else
{
// Forward flow to the index action
$this
->
dispatcher
->
forward
(
array
(
"action"
=>
"index"
));
}
}
}
src/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php
View file @
4b16c753
...
...
@@ -192,7 +192,8 @@ abstract class BaseModel
// We've loaded the model template, now let's parse it into this object
$this
->
parseXml
(
$model_xml
->
items
,
$config_array
,
$this
->
internalData
)
;
//print_r($this->internalData);
// trigger post loading event
$this
->
internalData
->
eventPostLoading
();
// call Model initializer
$this
->
init
();
...
...
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/ArrayField.php
View file @
4b16c753
...
...
@@ -56,9 +56,10 @@ class ArrayField extends BaseField
}
/**
* copy first node pointer as template node to make sure we always have a template to create new nodes from.
* Copy first node pointer as template node to make sure we always have a template to create new nodes from.
* If the first node is virtual (no source data), remove that from the list.
*/
pr
ivate
function
internalCopyStructure
()
pr
otected
function
actionPostLoadingEvent
()
{
// always make sure there's a node to copy our structure from
if
(
$this
->
internalTemplateNode
==
null
)
{
...
...
@@ -80,8 +81,6 @@ class ArrayField extends BaseField
*/
public
function
add
()
{
$this
->
internalCopyStructure
();
$new_record
=
array
();
foreach
(
$this
->
internalTemplateNode
->
__items
as
$key
=>
$node
)
{
if
(
$node
->
isContainer
())
{
...
...
@@ -113,7 +112,6 @@ class ArrayField extends BaseField
*/
public
function
del
(
$index
)
{
$this
->
internalCopyStructure
();
if
(
array_key_exists
((
string
)
$index
,
$this
->
internalChildnodes
))
{
unset
(
$this
->
internalChildnodes
[
$index
]);
}
...
...
src/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php
View file @
4b16c753
...
...
@@ -80,6 +80,25 @@ abstract class BaseField
*/
protected
$internalIsVirtual
=
false
;
/**
* Template action for post loading actions, triggered by eventPostLoadingEvent.
* Overwrite this method for custom loading hooks.
*/
protected
function
actionPostLoadingEvent
()
{
return
;
}
/**
* trigger post loading event. (executed by BaseModel)
*/
public
function
eventPostLoading
()
{
foreach
(
$this
->
internalChildnodes
as
$nodeName
=>
$node
)
{
$node
->
eventPostLoading
();
}
$this
->
actionPostLoadingEvent
();
}
/**
* @return bool returns if this a container type object (no data)
...
...
@@ -242,7 +261,7 @@ abstract class BaseField
}
/**
* Recursive method to flatten tree structure for easy validation.
* Recursive method to flatten tree structure for easy validation
, returns only leaf nodes
.
* @return array named array with field type nodes, using the internal reference.
*/
public
function
getFlatNodes
()
...
...
@@ -326,4 +345,5 @@ abstract class BaseField
$parts
=
explode
(
"
\\
"
,
get_class
(
$this
));
return
$parts
[
count
(
$parts
)
-
1
];
}
}
src/opnsense/mvc/app/views/OPNsense/Sample/page.volt
View file @
4b16c753
...
...
@@ -12,10 +12,10 @@
and the actual data from the Sample model, which is a combination of the data presented in the config.xml and the defaults set in the model xml.
<br/><br/>
When errors occur while saving this form, they will be shown below:
When errors occur while saving this form, they will be shown below:
<br/>
{% for error_message in error_messages %}
<i style="color:red"> {{ error_message['field'] }} : {{ error_message['msg'] }} </i> <br>
<i style="color:red"> {{ error_message['field'] }} : {{ error_message['msg'] }} </i> <br
/
>
{% endfor %}
<br/><br/>
...
...
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