Skip to content
Snippets Groups Projects
Unverified Commit 398bb2eb authored by Bartek Jaskulski's avatar Bartek Jaskulski
Browse files

refactor: add consistency in typing and inline docs

parent cf9cae0e
No related branches found
No related tags found
4 merge requests!28release: 3.0.0,!23Feature/strong typing pp,!19Add strong typing for 3.0 version,!18feat(fields): #1 add sorting fields by priority field
Pipeline #5952 passed
......@@ -3,6 +3,7 @@
namespace WPDesk\Forms\Field;
use WPDesk\Forms\Field;
use WPDesk\Forms\Form\FormWithFields;
use WPDesk\Forms\Sanitizer\NoSanitize;
use WPDesk\Forms\Serializer;
use WPDesk\Forms\Serializer\NoSerialize;
......@@ -25,6 +26,7 @@ abstract class BasicField implements Field {
public function __construct() {
$this->meta['class'] = [];
$this->meta['priority'] = 10;
}
public function get_label() {
......@@ -299,12 +301,16 @@ abstract class BasicField implements Field {
return $this;
}
/** @return int */
public function get_priority() {
return $this->meta['priority'] ?? 10;
public function get_priority(): int {
return $this->meta['priority'];
}
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;
return $this;
......
......@@ -21,10 +21,13 @@ class FormWithFieldsTest extends TestCase {
$this->form->add_fields(
[
( new InputTextField() )
->set_label('third'),
->set_label('fourth'),
( new SelectField() )
->set_label('second')
->set_priority(5),
( new SelectField() )
->set_label('third')
->set_priority(7),
( new InputNumberField() )
->set_label('first')
->set_priority(1)
......@@ -38,8 +41,11 @@ class FormWithFieldsTest extends TestCase {
( new SelectField() )
->set_label('second')
->set_priority(5),
( new InputTextField() )
( new SelectField() )
->set_label('third')
->set_priority(7),
( new InputTextField() )
->set_label('fourth')
];
self::assertEquals($expected, $this->form->get_fields());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment