PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.2
Elementor Website Builder – more than just a page builder v4.3.2
4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 All 455 releases
elementor / modules / atomic-widgets / elements / atomic-list / atomic-list-item / atomic-list-item.php

atomic-list-item.php in Elementor Website Builder – more than just a page builder 4.3.2, at modules/atomic-widgets/elements/atomic-list/atomic-list-item/atomic-list-item.php

186 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_List\Atomic_List_Item;
3
4 use Elementor\Modules\AtomicWidgets\ChildrenDependencies\Child_Dependency;
5 use Elementor\Modules\AtomicWidgets\Controls\Section;
6 use Elementor\Modules\AtomicWidgets\Elements\Atomic_List\Atomic_List\Atomic_List;
7 use Elementor\Modules\AtomicWidgets\Elements\Atomic_List\Atomic_List_Item_Content\Atomic_List_Item_Content;
8 use Elementor\Modules\AtomicWidgets\Elements\Atomic_List\Atomic_List_Item_Marker\Atomic_List_Item_Marker;
9 use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Element_Base;
10 use Elementor\Modules\AtomicWidgets\Elements\Base\Element_Builder;
11 use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Element_Template;
12 use Elementor\Modules\AtomicWidgets\Elements\Base\Html_Tag_Computer;
13 use Elementor\Modules\AtomicWidgets\Elements\Base\Render_Context;
14 use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager;
15 use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type;
16 use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type;
17 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\Boolean_Prop_Type;
18 use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type;
19 use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type;
20 use Elementor\Modules\AtomicWidgets\Styles\Style_Definition;
21 use Elementor\Modules\AtomicWidgets\Styles\Style_Variant;
22 use Elementor\Modules\AtomicWidgets\Utils\Element_Position;
23 use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type;
24
25 if ( ! defined( 'ABSPATH' ) ) {
26 exit; // Exit if accessed directly.
27 }
28
29 class Atomic_List_Item extends Atomic_Element_Base {
30 use Has_Element_Template;
31
32 const BASE_STYLE_KEY = 'base';
33
34 public static $widget_description = 'A locked list item wrapper that contains marker and content slots.';
35
36 public function __construct( $data = [], $args = null ) {
37 parent::__construct( $data, $args );
38 $this->meta( 'permanently_locked', true );
39 }
40
41 public static function get_type() {
42 return 'e-list-item';
43 }
44
45 public static function get_element_type(): string {
46 return self::get_type();
47 }
48
49 public function get_title() {
50 return esc_html__( 'List item', 'elementor' );
51 }
52
53 public function get_icon() {
54 return 'eicon-bullet-list';
55 }
56
57 public function should_show_in_panel() {
58 return false;
59 }
60
61 public static function get_computed_html_tag( array $settings ): string {
62 return Html_Tag_Computer::compute( $settings, 'li' );
63 }
64
65 /**
66 * Define props schema for list items.
67 *
68 * The show_markers is a hidden prop (not shown in panel) that's automatically
69 * synced from the parent list's show_markers setting. It's used by
70 * children_dependencies to conditionally show/hide markers.
71 */
72 protected static function define_props_schema(): array {
73 return [
74 'classes' => Classes_Prop_Type::make()
75 ->default( [] )
76 ->description( 'CSS classes applied to the list item container.' ),
77 'show_markers' => Boolean_Prop_Type::make()
78 ->default( true )
79 ->meta( Overridable_Prop_Type::ignore() )
80 ->description( 'Hidden prop automatically synced from the parent list. Controls whether markers are shown via children dependencies. Do not set manually.' ),
81 'attributes' => Attributes_Prop_Type::make()
82 ->meta( Overridable_Prop_Type::ignore() )
83 ->description( 'Custom HTML attributes applied to the list item element.' ),
84 ];
85 }
86
87 protected function define_atomic_controls(): array {
88 return [
89 Section::make()
90 ->set_label( __( 'Settings', 'elementor' ) )
91 ->set_id( 'settings' )
92 ->set_items( [] ),
93 ];
94 }
95
96 protected function define_base_styles(): array {
97 return [
98 static::BASE_STYLE_KEY => Style_Definition::make()
99 ->add_variant(
100 Style_Variant::make()
101 ->add_props( [
102 'display' => String_Prop_Type::generate( 'flex' ),
103 'flex-direction' => String_Prop_Type::generate( 'row' ),
104 'gap' => Size_Prop_Type::generate( [
105 'size' => 8,
106 'unit' => 'px',
107 ] ),
108 ] )
109 ),
110 ];
111 }
112
113 /**
114 * Define default children for list items.
115 *
116 * Markers are now managed via children_dependencies (see below) and are
117 * conditionally added/removed based on the show_markers setting.
118 * Only the content slot is included as a default child.
119 */
120 protected function define_default_children() {
121 return [
122 Atomic_List_Item_Content::generate()
123 ->hydrate_default_children( true )
124 ->build(),
125 ];
126 }
127
128 /**
129 * Define children dependencies for conditional marker rendering.
130 *
131 * Markers are added when show_markers === true and removed when false.
132 * Stashing preserves all marker customizations when toggled off, allowing
133 * restoration when toggled back on.
134 */
135 protected function define_children_dependencies(): array {
136 return [
137 Child_Dependency::for( Atomic_List_Item_Marker::get_element_type() )
138 ->when(
139 Dependency_Manager::make()->where( [
140 'operator' => 'eq',
141 'path' => [ 'show_markers' ],
142 'value' => true,
143 ] )
144 )
145 ->position( Element_Position::first() )
146 ->stash( true )
147 ->default_model(
148 Element_Builder::make( Atomic_List_Item_Marker::get_element_type() )
149 ->hydrate_default_children( true )
150 ->build()
151 ),
152 ];
153 }
154
155 /**
156 * Sync show_markers setting from parent list via render context.
157 *
158 * This propagates the list-level setting to each item, where children
159 * dependencies use it to determine marker visibility.
160 */
161 protected function define_render_context(): array {
162 $list_context = Render_Context::get( Atomic_List::class );
163
164 return [
165 [
166 'context' => [
167 'show_markers' => $list_context['show_markers'] ?? true,
168 ],
169 ],
170 ];
171 }
172
173 protected function define_allowed_child_types() {
174 return [
175 Atomic_List_Item_Marker::get_element_type(),
176 Atomic_List_Item_Content::get_element_type(),
177 ];
178 }
179
180 protected function get_templates(): array {
181 return [
182 'elementor/elements/atomic-list-item' => __DIR__ . '/atomic-list-item.html.twig',
183 ];
184 }
185 }
186