Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wp-forms
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wpdesk
wp-forms
Commits
398bb2eb
Unverified
Commit
398bb2eb
authored
3 years ago
by
Bartek Jaskulski
Browse files
Options
Downloads
Patches
Plain Diff
refactor: add consistency in typing and inline docs
parent
cf9cae0e
Branches
feature/add-priority-sorting
Branches containing commit
No related tags found
Tags containing commit
4 merge requests
!28
release: 3.0.0
,
!23
Feature/strong typing pp
,
!19
Add strong typing for 3.0 version
,
!18
feat(fields): #1 add sorting fields by priority field
Pipeline
#5952
passed with stages
in 1 minute and 15 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Field/BasicField.php
+10
-4
10 additions, 4 deletions
src/Field/BasicField.php
tests/integration/Form/FormWithFieldsTest.php
+8
-2
8 additions, 2 deletions
tests/integration/Form/FormWithFieldsTest.php
with
18 additions
and
6 deletions
src/Field/BasicField.php
+
10
−
4
View file @
398bb2eb
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
WPDesk\Forms\Field
;
namespace
WPDesk\Forms\Field
;
use
WPDesk\Forms\Field
;
use
WPDesk\Forms\Field
;
use
WPDesk\Forms\Form\FormWithFields
;
use
WPDesk\Forms\Sanitizer\NoSanitize
;
use
WPDesk\Forms\Sanitizer\NoSanitize
;
use
WPDesk\Forms\Serializer
;
use
WPDesk\Forms\Serializer
;
use
WPDesk\Forms\Serializer\NoSerialize
;
use
WPDesk\Forms\Serializer\NoSerialize
;
...
@@ -25,6 +26,7 @@ abstract class BasicField implements Field {
...
@@ -25,6 +26,7 @@ abstract class BasicField implements Field {
public
function
__construct
()
{
public
function
__construct
()
{
$this
->
meta
[
'class'
]
=
[];
$this
->
meta
[
'class'
]
=
[];
$this
->
meta
[
'priority'
]
=
10
;
}
}
public
function
get_label
()
{
public
function
get_label
()
{
...
@@ -299,12 +301,16 @@ abstract class BasicField implements Field {
...
@@ -299,12 +301,16 @@ abstract class BasicField implements Field {
return
$this
;
return
$this
;
}
}
/** @return int */
public
function
get_priority
():
int
{
public
function
get_priority
()
{
return
$this
->
meta
[
'priority'
];
return
$this
->
meta
[
'priority'
]
??
10
;
}
}
public
function
set_priority
(
int
$priority
)
{
/**
* Fields are sorted by lowest priority value first, when getting FormWithFields
*
* @see FormWithFields::get_fields()
*/
public
function
set_priority
(
int
$priority
):
self
{
$this
->
meta
[
'priority'
]
=
$priority
;
$this
->
meta
[
'priority'
]
=
$priority
;
return
$this
;
return
$this
;
...
...
This diff is collapsed.
Click to expand it.
tests/integration/Form/FormWithFieldsTest.php
+
8
−
2
View file @
398bb2eb
...
@@ -21,10 +21,13 @@ class FormWithFieldsTest extends TestCase {
...
@@ -21,10 +21,13 @@ class FormWithFieldsTest extends TestCase {
$this
->
form
->
add_fields
(
$this
->
form
->
add_fields
(
[
[
(
new
InputTextField
()
)
(
new
InputTextField
()
)
->
set_label
(
'
third
'
),
->
set_label
(
'
fourth
'
),
(
new
SelectField
()
)
(
new
SelectField
()
)
->
set_label
(
'second'
)
->
set_label
(
'second'
)
->
set_priority
(
5
),
->
set_priority
(
5
),
(
new
SelectField
()
)
->
set_label
(
'third'
)
->
set_priority
(
7
),
(
new
InputNumberField
()
)
(
new
InputNumberField
()
)
->
set_label
(
'first'
)
->
set_label
(
'first'
)
->
set_priority
(
1
)
->
set_priority
(
1
)
...
@@ -38,8 +41,11 @@ class FormWithFieldsTest extends TestCase {
...
@@ -38,8 +41,11 @@ class FormWithFieldsTest extends TestCase {
(
new
SelectField
()
)
(
new
SelectField
()
)
->
set_label
(
'second'
)
->
set_label
(
'second'
)
->
set_priority
(
5
),
->
set_priority
(
5
),
(
new
InputTex
tField
()
)
(
new
Selec
tField
()
)
->
set_label
(
'third'
)
->
set_label
(
'third'
)
->
set_priority
(
7
),
(
new
InputTextField
()
)
->
set_label
(
'fourth'
)
];
];
self
::
assertEquals
(
$expected
,
$this
->
form
->
get_fields
());
self
::
assertEquals
(
$expected
,
$this
->
form
->
get_fields
());
...
...
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