attributes-trait.php
4 years ago
builder-helper.php
4 years ago
condition-helper.php
4 years ago
curl-helper.php
4 years ago
factory.php
4 years ago
gallery.php
4 years ago
get-icon-trait.php
4 years ago
get-template-trait.php
4 years ago
instance-trait.php
4 years ago
listing-filter-manager.php
4 years ago
listing-filter.php
4 years ago
messages-helper-trait.php
4 years ago
tools.php
4 years ago
attributes-trait.php
82 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Classes; |
| 5 | |
| 6 | |
| 7 | use Jet_Form_Builder\Blocks\Render\Base; |
| 8 | |
| 9 | trait Attributes_Trait { |
| 10 | public $attrs = array(); |
| 11 | |
| 12 | /** |
| 13 | * Add attribute |
| 14 | * |
| 15 | * @param $attr |
| 16 | * @param null $value |
| 17 | */ |
| 18 | public function add_attribute( $attr, $value = null ) { |
| 19 | |
| 20 | if ( '' === $value ) { |
| 21 | return; |
| 22 | } |
| 23 | if ( ! isset( $this->attrs[ $attr ] ) ) { |
| 24 | $this->attrs[ $attr ] = $value; |
| 25 | } else { |
| 26 | $this->attrs[ $attr ] .= ' ' . $value; |
| 27 | } |
| 28 | |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Reset attributes array |
| 33 | */ |
| 34 | public function reset_attributes() { |
| 35 | $this->attrs = array(); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Render current attributes string |
| 40 | * |
| 41 | * @return void |
| 42 | */ |
| 43 | public function render_attributes_string() { |
| 44 | $this->render_attributes_string_save(); |
| 45 | $this->attrs = array(); |
| 46 | } |
| 47 | |
| 48 | public function render_attributes_string_save() { |
| 49 | echo $this->get_attributes_string_save(); |
| 50 | } |
| 51 | |
| 52 | public function get_attributes_string_save() { |
| 53 | $response = ''; |
| 54 | $attrs = $this->attrs; |
| 55 | |
| 56 | if ( $this instanceof Base ) { |
| 57 | $attrs = apply_filters( |
| 58 | "jet-form-builder/render/{$this->get_name()}/attributes", |
| 59 | $attrs, |
| 60 | $this |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | foreach ( $attrs as $attr => $value ) { |
| 65 | if ( is_array( $value ) ) { |
| 66 | $value = implode( ' ', $value ); |
| 67 | } |
| 68 | $response .= sprintf( ' %1$s="%2$s"', $attr, $value ); |
| 69 | } |
| 70 | |
| 71 | return $response; |
| 72 | } |
| 73 | |
| 74 | public function get_attributes_string() { |
| 75 | $response = $this->get_attributes_string_save(); |
| 76 | $this->attrs = array(); |
| 77 | |
| 78 | return $response; |
| 79 | } |
| 80 | |
| 81 | |
| 82 | } |