Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wp-forms
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wpdesk
wp-forms
Commits
be366df8
Commit
be366df8
authored
5 years ago
by
Grzegorz Rola
Browse files
Options
Downloads
Patches
Plain Diff
Feature/json renderer html class
parent
333dab91
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
changelog.txt
+4
-0
4 additions, 0 deletions
changelog.txt
src/Field.php
+25
-0
25 additions, 0 deletions
src/Field.php
src/Field/BasicField.php
+37
-0
37 additions, 0 deletions
src/Field/BasicField.php
src/Renderer/JsonNormalizedRenderer.php
+14
-0
14 additions, 0 deletions
src/Renderer/JsonNormalizedRenderer.php
with
80 additions
and
0 deletions
changelog.txt
+
4
−
0
View file @
be366df8
# Changelog
## [2.0.3] - 2020-06-22
### Added
- css class in JSON renderer
## 2.0.2 - 2020-06-17
### Changed
- Skip saving empty keys in the PersistentContainer
...
...
This diff is collapsed.
Click to expand it.
src/Field.php
+
25
−
0
View file @
be366df8
...
...
@@ -2,6 +2,8 @@
namespace
WPDesk\Forms
;
use
WPDesk\Forms\Field\BasicField
;
/**
* The idea is that from the moment the factory returns this interface it's values cannot be changed.
* And that is why here are only the getters.
...
...
@@ -116,6 +118,29 @@ interface Field {
/** @return bool */
public
function
is_class_set
(
$name
);
/** bool */
public
function
has_data
();
/**
* @return array
*/
public
function
get_data
();
/**
* @param string $data_name
* @param string $data_value
*
* @return $this
*/
public
function
add_data
(
$data_name
,
$data_value
);
/**
* @param string $data_name
*
* @return $this
*/
public
function
unset_data
(
$data_name
);
/**
* @return mixed
*/
...
...
This diff is collapsed.
Click to expand it.
src/Field/BasicField.php
+
37
−
0
View file @
be366df8
...
...
@@ -137,6 +137,17 @@ abstract class BasicField implements Field {
return
!
empty
(
$this
->
meta
[
'class'
]
);
}
public
function
has_data
()
{
return
!
empty
(
$this
->
meta
[
'data'
]
);
}
/**
* @return array
*/
public
function
get_data
()
{
return
empty
(
$this
->
meta
[
'data'
]
)
?
[]
:
$this
->
meta
[
'data'
];
}
public
function
get_possible_values
()
{
return
isset
(
$this
->
meta
[
'possible_values'
]
)
?
$this
->
meta
[
'possible_values'
]
:
[];
}
...
...
@@ -210,6 +221,32 @@ abstract class BasicField implements Field {
return
$this
;
}
/**
* @param string $data_name
* @param string $data_value
*
* @return $this
*/
public
function
add_data
(
$data_name
,
$data_value
)
{
if
(
!
isset
(
$this
->
meta
[
'data'
]
)
)
{
$this
->
meta
[
'data'
]
=
[];
}
$this
->
meta
[
'data'
][
$data_name
]
=
$data_value
;
return
$this
;
}
/**
* @param string $data_name
*
* @return $this
*/
public
function
unset_data
(
$data_name
)
{
unset
(
$this
->
meta
[
'data'
][
$data_name
]
);
return
$this
;
}
/**
* @param $name
* @param $value
...
...
This diff is collapsed.
Click to expand it.
src/Renderer/JsonNormalizedRenderer.php
+
14
−
0
View file @
be366df8
...
...
@@ -32,6 +32,9 @@ class JsonNormalizedRenderer implements FieldRenderer {
'value '
=>
isset
(
$fields_data
[
$field
->
get_name
()
]
)
?
$fields_data
[
$field
->
get_name
()
]
:
$field
->
get_default_value
()
];
if
(
$field
->
has_classes
()
)
{
$rendered
[
'class'
]
=
$field
->
get_classes
();
}
if
(
$field
->
has_description
()
)
{
$rendered
[
'description'
]
=
$field
->
get_description
();
}
...
...
@@ -45,6 +48,17 @@ class JsonNormalizedRenderer implements FieldRenderer {
if
(
$options
)
{
$rendered
[
'options'
]
=
$options
;
}
if
(
$field
->
has_data
()
)
{
$data
=
$field
->
get_data
();
$rendered
[
'data'
]
=
[];
foreach
(
$data
as
$data_name
=>
$data_value
)
{
$rendered
[
'data'
][]
=
[
'name'
=>
$data_name
,
'value'
=>
$data_value
,
];
}
}
$rendered_fields
[]
=
$rendered
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment