Skip to content
Snippets Groups Projects
Commit 9717dd41 authored by dyszczo's avatar dyszczo
Browse files

no value field fix

parent c48871ff
No related branches found
No related tags found
1 merge request!2Feature/field and templates
Pipeline #4006 failed
......@@ -2,10 +2,9 @@
namespace WPDesk\Forms\Field;
use WPDesk\Forms\NoValueField;
class Header extends NoValueField {
public function __construct() {
parent::__construct();
$this->meta['header_size'] = '';
}
......
......@@ -2,7 +2,6 @@
namespace WPDesk\Forms\Field;
use WPDesk\Forms\Sanitizer\TextFieldSanitizer;
class HiddenField extends BasicField {
......
......@@ -2,7 +2,6 @@
namespace WPDesk\Forms\Field;
use WPDesk\Forms\Sanitizer\TextFieldSanitizer;
class InputTextField extends BasicField {
......
......@@ -2,7 +2,6 @@
namespace WPDesk\Forms\Field;
use WPDesk\Forms\Validator\NonceValidator;
class NoOnceField extends BasicField {
......
......@@ -2,8 +2,6 @@
namespace WPDesk\Forms\Field;
use WPDesk\Forms\NoValueField;
class Paragraph extends NoValueField {
public function get_template_name() {
return 'paragraph';
......
......@@ -2,7 +2,6 @@
namespace WPDesk\Forms\Field;
class RadioField extends BasicField {
public function get_template_name() {
return 'input-radio';
......
......@@ -2,7 +2,6 @@
namespace WPDesk\Forms\Field;
class SelectField extends BasicField {
public function get_template_name() {
......
......@@ -2,8 +2,6 @@
namespace WPDesk\Forms\Field;
use WPDesk\Forms\NoValueField;
class SubmitField extends NoValueField {
public function get_template_name() {
return 'input-submit';
......
......@@ -2,7 +2,6 @@
namespace WPDesk\Forms\Field;
class TextAreaField extends BasicField {
public function __construct() {
parent::__construct();
......
......@@ -2,7 +2,6 @@
namespace WPDesk\Forms\Field;
class WyswigField extends BasicField {
public function __construct() {
parent::__construct();
......
......@@ -12,6 +12,11 @@ use WPDesk\View\Renderer\Renderer;
* @package WPDesk\Forms
*/
interface Form {
/**
* Checks if form should be active.
*
* @return bool
*/
public function is_active();
public function is_submitted();
......@@ -35,5 +40,12 @@ interface Form {
public function get_data();
public function get_normalized_data();
/**
* return form Id
*
* @return string
*/
public function get_form_id();
}
......@@ -10,8 +10,22 @@ use WPDesk\Persistence\Adapter\ArrayContainer;
use WPDesk\Persistence\ElementNotExistsException;
use WPDesk\View\Renderer\Renderer;
class FormWithFields extends AbstractForm implements Form, FieldProvider {
/** @var Field[] */
class FormWithFields implements Form, FieldProvider {
/**
* Unique form_id.
*
* @var string
*/
protected $form_id = 'form';
/**
* Updated data.
*
* @var array
*/
private $updated_data;
/**
* @var Field[]
*/
private $fields;
public function __construct( array $fields, $form_id = 'form' ) {
......@@ -28,6 +42,15 @@ class FormWithFields extends AbstractForm implements Form, FieldProvider {
$this->fields[] = $field;
}
/**
* Checks if form should be active.
*
* @return bool
*/
public function is_active() {
return true;
}
/**
* @param Field[] $fields
*/
......@@ -68,8 +91,6 @@ class FormWithFields extends AbstractForm implements Form, FieldProvider {
* @param array|ContainerInterface $data
*/
public function set_data( $data ) {
$this->update_form_data($data); // backward compatibility
if ( is_array( $data ) ) {
$data = new ArrayContainer( $data );
}
......@@ -110,7 +131,7 @@ class FormWithFields extends AbstractForm implements Form, FieldProvider {
}
public function get_data() {
$data = \array_merge( $this->create_form_data(), $this->updated_data ?: [] );
$data = $this->updated_data;
foreach ( $this->get_fields() as $field ) {
$data_key = $field->get_name();
......@@ -122,15 +143,20 @@ class FormWithFields extends AbstractForm implements Form, FieldProvider {
return $data;
}
public function get_normalized_data() {
return $this->get_data();
public function get_fields() {
return $this->fields;
}
protected function create_form_data() {
return [];
/**
* return form Id
*
* @return string
*/
public function get_form_id() {
return $this->form_id;
}
public function get_fields() {
return $this->fields;
public function get_normalized_data() {
return $this->get_data();
}
}
......@@ -7,6 +7,8 @@ use WPDesk\Forms\Form;
/**
* FormsCollection class store AbstractForm instances and merges forms data from all collections
*
* @deprecated Use ony for backward compatibility with Forms 1.x
*
* @package WPDesk\Forms
*/
class FormsCollection {
......@@ -17,6 +19,20 @@ class FormsCollection {
*/
protected $forms = array();
/**
* Unique form_id.
*
* @var string
*/
protected $form_id = 'form';
/**
* Updated data.
*
* @var array
*/
protected $updated_data = array();
/**
* Add forms. All keys in this array must be unique, otherwise add_form will throw exception.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment