| 1 |
<?php |
| 2 |
namespace Elementor\Modules\AtomicWidgets\Elements\Grid; |
| 3 |
|
| 4 |
use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager; |
| 5 |
use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Element_Base; |
| 6 |
use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Element_Template; |
| 7 |
use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager; |
| 8 |
use Elementor\Modules\AtomicWidgets\PropTypes\Grid_Track_Size_Prop_Type; |
| 9 |
use Elementor\Modules\AtomicWidgets\PropTypes\Layout_Direction_Prop_Type; |
| 10 |
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\Boolean_Prop_Type; |
| 11 |
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 12 |
use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type; |
| 13 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 14 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| 15 |
use Elementor\Modules\AtomicWidgets\Controls\Section; |
| 16 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Html_Tag_Control; |
| 17 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Link_Control; |
| 18 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control; |
| 19 |
use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type; |
| 20 |
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 21 |
use Elementor\Modules\AtomicWidgets\PropTypes\Link_Prop_Type; |
| 22 |
use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; |
| 23 |
|
| 24 |
if ( ! defined( 'ABSPATH' ) ) { |
| 25 |
exit; // Exit if accessed directly. |
| 26 |
} |
| 27 |
|
| 28 |
class Grid extends Atomic_Element_Base { |
| 29 |
use Has_Element_Template; |
| 30 |
|
| 31 |
const BASE_STYLE_KEY = 'base'; |
| 32 |
|
| 33 |
public function __construct( $data = [], $args = null ) { |
| 34 |
parent::__construct( $data, $args ); |
| 35 |
$this->meta( 'is_container', true ); |
| 36 |
} |
| 37 |
|
| 38 |
public static function get_type() { |
| 39 |
return 'e-grid'; |
| 40 |
} |
| 41 |
|
| 42 |
public static function get_element_type(): string { |
| 43 |
return 'e-grid'; |
| 44 |
} |
| 45 |
|
| 46 |
public function get_title() { |
| 47 |
return esc_html__( 'Grid', 'elementor' ); |
| 48 |
} |
| 49 |
|
| 50 |
public function get_keywords() { |
| 51 |
return [ 'ato', 'atom', 'atoms', 'atomic', 'grid', 'layout' ]; |
| 52 |
} |
| 53 |
|
| 54 |
public function get_icon() { |
| 55 |
return 'eicon-library-grid'; |
| 56 |
} |
| 57 |
|
| 58 |
protected static function define_props_schema(): array { |
| 59 |
$tag_dependencies = Dependency_Manager::make( Dependency_Manager::RELATION_AND ) |
| 60 |
->where( [ |
| 61 |
'operator' => 'ne', |
| 62 |
'path' => [ 'link', 'destination' ], |
| 63 |
'nestedPath' => [ 'group' ], |
| 64 |
'value' => 'action', |
| 65 |
'newValue' => [ |
| 66 |
'$$type' => 'string', |
| 67 |
'value' => 'button', |
| 68 |
], |
| 69 |
] )->where( [ |
| 70 |
'operator' => 'not_exist', |
| 71 |
'path' => [ 'link', 'destination' ], |
| 72 |
'newValue' => [ |
| 73 |
'$$type' => 'string', |
| 74 |
'value' => 'a', |
| 75 |
], |
| 76 |
] )->get(); |
| 77 |
|
| 78 |
return [ |
| 79 |
'classes' => Classes_Prop_Type::make() |
| 80 |
->default( [] ), |
| 81 |
'tag' => String_Prop_Type::make() |
| 82 |
->enum( [ 'div', 'header', 'section', 'article', 'aside', 'footer', 'a', 'button' ] ) |
| 83 |
->default( 'div' ) |
| 84 |
->description( 'The HTML tag for the grid container. Could be div, header, section, article, aside, footer, or a (link).' ) |
| 85 |
->set_dependencies( $tag_dependencies ), |
| 86 |
'link' => Link_Prop_Type::make(), |
| 87 |
'attributes' => Attributes_Prop_Type::make()->meta( Overridable_Prop_Type::ignore() ), |
| 88 |
]; |
| 89 |
} |
| 90 |
|
| 91 |
protected function define_atomic_controls(): array { |
| 92 |
return [ |
| 93 |
Section::make() |
| 94 |
->set_label( __( 'Settings', 'elementor' ) ) |
| 95 |
->set_id( 'settings' ) |
| 96 |
->set_items( [ |
| 97 |
Html_Tag_Control::bind_to( 'tag' ) |
| 98 |
->set_options( [ |
| 99 |
[ |
| 100 |
'value' => 'div', |
| 101 |
'label' => 'Div', |
| 102 |
], |
| 103 |
[ |
| 104 |
'value' => 'header', |
| 105 |
'label' => 'Header', |
| 106 |
], |
| 107 |
[ |
| 108 |
'value' => 'section', |
| 109 |
'label' => 'Section', |
| 110 |
], |
| 111 |
[ |
| 112 |
'value' => 'article', |
| 113 |
'label' => 'Article', |
| 114 |
], |
| 115 |
[ |
| 116 |
'value' => 'aside', |
| 117 |
'label' => 'Aside', |
| 118 |
], |
| 119 |
[ |
| 120 |
'value' => 'footer', |
| 121 |
'label' => 'Footer', |
| 122 |
], |
| 123 |
]) |
| 124 |
->set_label( esc_html__( 'HTML Tag', 'elementor' ) ) |
| 125 |
->set_fallback_labels( [ |
| 126 |
'a' => 'a (link)', |
| 127 |
] ), |
| 128 |
Link_Control::bind_to( 'link' ) |
| 129 |
->set_placeholder( __( 'Type or paste your URL', 'elementor' ) ) |
| 130 |
->set_label( __( 'Link', 'elementor' ) ) |
| 131 |
->set_meta( [ |
| 132 |
'topDivider' => true, |
| 133 |
] ), |
| 134 |
Text_Control::bind_to( '_cssid' ) |
| 135 |
->set_label( __( 'ID', 'elementor' ) ) |
| 136 |
->set_meta( $this->get_css_id_control_meta() ), |
| 137 |
] ), |
| 138 |
]; |
| 139 |
} |
| 140 |
|
| 141 |
protected function define_base_styles(): array { |
| 142 |
return [ |
| 143 |
static::BASE_STYLE_KEY => Style_Definition::make() |
| 144 |
->add_variant( |
| 145 |
Style_Variant::make() |
| 146 |
->set_breakpoint( Breakpoints_Manager::BREAKPOINT_KEY_DESKTOP ) |
| 147 |
->add_prop( 'display', String_Prop_Type::generate( 'grid' ) ) |
| 148 |
->add_prop( 'padding', $this->get_base_padding() ) |
| 149 |
->add_prop( 'grid-template-columns', Grid_Track_Size_Prop_Type::generate( [ |
| 150 |
'size' => 3, |
| 151 |
'unit' => 'fr', |
| 152 |
] ) ) |
| 153 |
->add_prop( 'grid-template-rows', Grid_Track_Size_Prop_Type::generate( [ |
| 154 |
'size' => 2, |
| 155 |
'unit' => 'fr', |
| 156 |
] ) ) |
| 157 |
->add_prop( 'gap', Layout_Direction_Prop_Type::generate( [ |
| 158 |
'column' => Size_Prop_Type::generate( [ |
| 159 |
'size' => 20, |
| 160 |
'unit' => 'px', |
| 161 |
] ), |
| 162 |
'row' => Size_Prop_Type::generate( [ |
| 163 |
'size' => 20, |
| 164 |
'unit' => 'px', |
| 165 |
] ), |
| 166 |
] ) ) |
| 167 |
) |
| 168 |
->add_variant( |
| 169 |
Style_Variant::make() |
| 170 |
->set_breakpoint( Breakpoints_Manager::BREAKPOINT_KEY_MOBILE ) |
| 171 |
->add_prop( 'grid-template-columns', Grid_Track_Size_Prop_Type::generate( [ |
| 172 |
'size' => 1, |
| 173 |
'unit' => 'fr', |
| 174 |
] ) ) |
| 175 |
), |
| 176 |
]; |
| 177 |
} |
| 178 |
|
| 179 |
protected function get_base_padding(): array { |
| 180 |
return Size_Prop_Type::generate( [ |
| 181 |
'size' => 10, |
| 182 |
'unit' => 'px', |
| 183 |
] ); |
| 184 |
} |
| 185 |
|
| 186 |
protected function add_render_attributes() { |
| 187 |
parent::add_render_attributes(); |
| 188 |
$settings = $this->get_atomic_settings(); |
| 189 |
$base_style_class = $this->get_base_styles_dictionary()[ static::BASE_STYLE_KEY ]; |
| 190 |
$initial_attributes = $this->define_initial_attributes(); |
| 191 |
|
| 192 |
$attributes = [ |
| 193 |
'class' => [ |
| 194 |
'e-con', |
| 195 |
'e-atomic-element', |
| 196 |
$base_style_class, |
| 197 |
...( $settings['classes'] ?? [] ), |
| 198 |
], |
| 199 |
]; |
| 200 |
|
| 201 |
if ( ! empty( $settings['_cssid'] ) ) { |
| 202 |
$attributes['id'] = esc_attr( $settings['_cssid'] ); |
| 203 |
} |
| 204 |
|
| 205 |
if ( ! empty( $settings['link']['href'] ) ) { |
| 206 |
$link_attributes = $this->get_link_attributes( $settings['link'] ); |
| 207 |
$attributes = array_merge( $attributes, $link_attributes ); |
| 208 |
} |
| 209 |
|
| 210 |
$this->add_render_attribute( '_wrapper', array_merge( $initial_attributes, $attributes ) ); |
| 211 |
} |
| 212 |
|
| 213 |
protected function get_templates(): array { |
| 214 |
return [ |
| 215 |
'elementor/elements/grid' => __DIR__ . '/grid.html.twig', |
| 216 |
]; |
| 217 |
} |
| 218 |
} |
| 219 |
|