Skip to content
Snippets Groups Projects
Select Git revision
  • dcc87fa08ba25f2a4275acb13e7c6815eb5effa4
  • master default protected
  • devel
  • feature/add-escaping-to-templates
  • feature/add-priority-sorting
  • 3.3.0
  • 3.2.1
  • 3.2.0
  • 3.1.0
  • 3.0.0
  • 2.4.12
  • 2.4.11
  • 2.4.10
  • 2.4.9
  • 2.4.8
  • 2.4.7
  • 2.4.6
  • 2.4.5
  • 2.4.4
  • 2.4.2
  • 2.4.1
  • 2.4.0
  • 2.3.2
  • 2.3.1
  • 2.3
25 results

ContainerForm.php

Blame
  • 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 {