Skip to content
Snippets Groups Projects
Select Git revision
  • 443a4c3e1a9787dd65b7cd6be899da85ee26c3e2
  • master default protected
  • feat/npm-publish
  • feat/demo-deploy
  • change-demo-deploy
  • remove-smoke
  • feat/acceptance-tests
  • feature/deploy-composer.json
  • feature/mysql-bin-logs
  • skip-codecept-for-libs
  • include-composer-json
  • exclude-wp-assets
  • update_codecept_image
  • fix/silenced-copy
  • remove-free-translations
  • codeception-with-optional-step
  • improve-parallelization
  • linter-exit
  • change-images
  • fix/linter
  • globally-raise-mem-limit
  • no-symlink2
22 results

integration.yml

Blame
  • HtmlAttributes.php 1.18 KiB
    <?php
    
    namespace WPDesk\Forms\Field\Traits;
    
    /**
     * Implementation of HTML attributes like id, name, action etc.
     *
     * @package WPDesk\Forms\Field\Traits
     */
    trait HtmlAttributes {
    
    	/** @var string[] */
    	protected $attributes;
    
    	/**
    	 * Get list of all attributes except given.
    	 *
    	 * @param string[] $except
    	 *
    	 * @return string[]
    	 */
    	public function get_attributes( array $except = [ 'name', 'type' ] ): array {
    		return array_filter(
    			$this->attributes,
    			static function ( $value, $key ) use ( $except ) {
    				return ! in_array( $key, $except, true );
    			},
    			ARRAY_FILTER_USE_BOTH
    		);
    	}
    
    	/**
    	 * @return \WPDesk\Forms\Field|\WPDesk\Forms\Form
    	 */
    	public function set_attribute( string $name, string $value ) {
    		$this->attributes[ $name ] = $value;
    
    		return $this;
    	}
    
    	/**
    	 * @return \WPDesk\Forms\Field|\WPDesk\Forms\Form
    	 */
    	public function unset_attribute( string $name ) {
    		unset( $this->attributes[ $name ] );
    
    		return $this;
    	}
    
    	public function is_attribute_set( string $name ): bool {
    		return isset( $this->attributes[ $name ] );
    	}
    
    	public function get_attribute( string $name, string $default = null ): string {
    		return $this->attributes[ $name ] ?? $default ?? '';
    	}
    }