Select Git revision
ContainerForm.php
BasicField.php 5.55 KiB
<?php
namespace WPDesk\Forms\Field;
use WPDesk\Forms\Field;
use WPDesk\Forms\Sanitizer;
use WPDesk\Forms\Sanitizer\NoSanitize;
use WPDesk\Forms\Serializer;
use WPDesk\Forms\Serializer\NoSerialize;
use WPDesk\Forms\Validator;
use WPDesk\Forms\Validator\ChainValidator;
use WPDesk\Forms\Validator\RequiredValidator;
/**
* Base class for fields. Is responsible for settings all required field values and provides standard implementation for
* the field interface.
*
* @package WPDesk\Forms
*/
abstract class BasicField implements Field {
use Field\Traits\HtmlAttributes;
const DEFAULT_PRIORITY = 10;
/** @var array<string,int,bool> */
protected $meta;
/** @var string */
protected $default_value;
public function __construct() {
$this->meta['class'] = [];
$this->meta['priority'] = self::DEFAULT_PRIORITY;
}
public function get_label(): string {
return $this->meta['label'];
}
public function set_label( string $value ): Field {
$this->meta['label'] = $value;
return $this;
}
public function get_description_tip(): string {
return $this->meta['description_tip'];
}
public function has_description_tip(): bool {
return isset( $this->meta['description_tip'] );
}
public function should_override_form_template(): bool {
return $this->attributes['overrite_template'] ?? false;
}
public function get_description(): string {
return $this->meta['description'];
}
public function has_label(): bool {
return isset( $this->meta['label'] );
}
public function has_description(): bool {
return isset( $this->meta['description'] );
}
public function set_description( string $value ): Field {