| 1 |
<?php |
| 2 |
namespace Elementor\Modules\AtomicWidgets\Elements\Atomic_List\Atomic_List; |
| 3 |
|
| 4 |
use Elementor\Modules\AtomicWidgets\Controls\Section; |
| 5 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Elements\List_Items_Control; |
| 6 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Switch_Control; |
| 7 |
use Elementor\Modules\AtomicWidgets\Controls\Types\Text_Control; |
| 8 |
use Elementor\Modules\AtomicWidgets\Elements\Atomic_List\Atomic_List_Item\Atomic_List_Item; |
| 9 |
use Elementor\Modules\AtomicWidgets\Elements\Atomic_List\Atomic_List_Item_Content\Atomic_List_Item_Content; |
| 10 |
use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Element_Base; |
| 11 |
use Elementor\Modules\AtomicWidgets\Elements\Base\Has_Element_Template; |
| 12 |
use Elementor\Modules\AtomicWidgets\PropTypes\Attributes_Prop_Type; |
| 13 |
use Elementor\Modules\AtomicWidgets\PropTypes\Classes_Prop_Type; |
| 14 |
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\Boolean_Prop_Type; |
| 15 |
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 16 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Definition; |
| 17 |
use Elementor\Modules\AtomicWidgets\Styles\Style_Variant; |
| 18 |
use Elementor\Modules\Components\PropTypes\Overridable_Prop_Type; |
| 19 |
|
| 20 |
if ( ! defined( 'ABSPATH' ) ) { |
| 21 |
exit; // Exit if accessed directly. |
| 22 |
} |
| 23 |
|
| 24 |
class Atomic_List extends Atomic_Element_Base { |
| 25 |
use Has_Element_Template; |
| 26 |
|
| 27 |
const BASE_STYLE_KEY = 'base'; |
| 28 |
|
| 29 |
public static $widget_description = 'Create a semantic list with structured list items, marker slots, and content slots.'; |
| 30 |
|
| 31 |
public function __construct( $data = [], $args = null ) { |
| 32 |
parent::__construct( $data, $args ); |
| 33 |
$this->meta( 'is_container', true ); |
| 34 |
$this->meta( 'is_compound', true ); |
| 35 |
} |
| 36 |
|
| 37 |
public static function get_type() { |
| 38 |
return 'e-list'; |
| 39 |
} |
| 40 |
|
| 41 |
public static function get_element_type(): string { |
| 42 |
return self::get_type(); |
| 43 |
} |
| 44 |
|
| 45 |
public function get_title() { |
| 46 |
return esc_html__( 'List', 'elementor' ); |
| 47 |
} |
| 48 |
|
| 49 |
public function get_keywords() { |
| 50 |
return [ 'ato', 'atom', 'atoms', 'atomic', 'list' ]; |
| 51 |
} |
| 52 |
|
| 53 |
public function get_icon() { |
| 54 |
return 'eicon-bullet-list'; |
| 55 |
} |
| 56 |
|
| 57 |
public static function get_computed_html_tag( array $settings ): string { |
| 58 |
return 'ul'; |
| 59 |
} |
| 60 |
|
| 61 |
protected static function define_props_schema(): array { |
| 62 |
return [ |
| 63 |
'classes' => Classes_Prop_Type::make() |
| 64 |
->default( [] ) |
| 65 |
->description( 'CSS classes applied to the list container.' ), |
| 66 |
'tag' => String_Prop_Type::make() |
| 67 |
->default( 'ul' ) |
| 68 |
->meta( Overridable_Prop_Type::ignore() ) |
| 69 |
->description( 'The HTML tag for the list container. Currently hardcoded to ul (unordered list). Future phases may support ol (ordered list).' ), |
| 70 |
'show_markers' => Boolean_Prop_Type::make() |
| 71 |
->default( true ) |
| 72 |
->description( 'Controls marker visibility for all list items. When true, markers are shown; when false, markers are hidden but preserved (stashed) for restoration.' ), |
| 73 |
'attributes' => Attributes_Prop_Type::make() |
| 74 |
->meta( Overridable_Prop_Type::ignore() ) |
| 75 |
->description( 'Custom HTML attributes applied to the list container element.' ), |
| 76 |
]; |
| 77 |
} |
| 78 |
|
| 79 |
protected function define_atomic_controls(): array { |
| 80 |
return [ |
| 81 |
Section::make() |
| 82 |
->set_label( __( 'Content', 'elementor' ) ) |
| 83 |
->set_id( 'content' ) |
| 84 |
->set_items( [ |
| 85 |
List_Items_Control::make() |
| 86 |
->set_label( __( 'List Items', 'elementor' ) ) |
| 87 |
->set_meta( [ |
| 88 |
'layout' => 'custom', |
| 89 |
] ), |
| 90 |
Switch_Control::bind_to( 'show_markers' ) |
| 91 |
->set_label( __( 'Show Markers', 'elementor' ) ), |
| 92 |
] ), |
| 93 |
Section::make() |
| 94 |
->set_label( __( 'Settings', 'elementor' ) ) |
| 95 |
->set_id( 'settings' ) |
| 96 |
->set_items( [ |
| 97 |
Text_Control::bind_to( '_cssid' ) |
| 98 |
->set_label( __( 'ID', 'elementor' ) ) |
| 99 |
->set_meta( $this->get_css_id_control_meta() ), |
| 100 |
] ), |
| 101 |
]; |
| 102 |
} |
| 103 |
|
| 104 |
protected function define_base_styles(): array { |
| 105 |
return [ |
| 106 |
static::BASE_STYLE_KEY => Style_Definition::make() |
| 107 |
->add_variant( |
| 108 |
Style_Variant::make() |
| 109 |
->add_props( [ |
| 110 |
'list-style-type' => String_Prop_Type::generate( 'none' ), |
| 111 |
] ) |
| 112 |
), |
| 113 |
]; |
| 114 |
} |
| 115 |
|
| 116 |
protected function define_default_children() { |
| 117 |
return [ |
| 118 |
Atomic_List_Item::generate() |
| 119 |
->settings( [ |
| 120 |
'show_markers' => Boolean_Prop_Type::generate( true ), |
| 121 |
] ) |
| 122 |
->hydrate_default_children( true ) |
| 123 |
->editor_settings( [ |
| 124 |
'title' => esc_html__( 'Item 1', 'elementor' ), |
| 125 |
'initial_position' => 1, |
| 126 |
] ) |
| 127 |
->build(), |
| 128 |
]; |
| 129 |
} |
| 130 |
|
| 131 |
protected function define_allowed_child_types() { |
| 132 |
return [ Atomic_List_Item::get_element_type() ]; |
| 133 |
} |
| 134 |
|
| 135 |
protected function define_render_context(): array { |
| 136 |
return [ |
| 137 |
[ |
| 138 |
'context' => [ |
| 139 |
'show_markers' => $this->get_atomic_setting( 'show_markers' ), |
| 140 |
], |
| 141 |
], |
| 142 |
]; |
| 143 |
} |
| 144 |
|
| 145 |
public function render_markdown(): string { |
| 146 |
$children = $this->get_children(); |
| 147 |
|
| 148 |
if ( empty( $children ) ) { |
| 149 |
return ''; |
| 150 |
} |
| 151 |
|
| 152 |
$lines = []; |
| 153 |
|
| 154 |
foreach ( $children as $child ) { |
| 155 |
if ( $child::get_element_type() !== Atomic_List_Item::get_element_type() ) { |
| 156 |
continue; |
| 157 |
} |
| 158 |
|
| 159 |
$item_children = $child->get_children(); |
| 160 |
$content_text = ''; |
| 161 |
|
| 162 |
foreach ( $item_children as $item_child ) { |
| 163 |
if ( $item_child::get_element_type() === Atomic_List_Item_Content::get_element_type() ) { |
| 164 |
$content_children = $item_child->get_children(); |
| 165 |
$content_parts = []; |
| 166 |
foreach ( $content_children as $content_child ) { |
| 167 |
if ( method_exists( $content_child, 'render_markdown' ) ) { |
| 168 |
$md = $content_child->render_markdown(); |
| 169 |
if ( ! empty( trim( $md ) ) ) { |
| 170 |
$content_parts[] = $md; |
| 171 |
} |
| 172 |
} |
| 173 |
} |
| 174 |
$content_text = implode( ' ', $content_parts ); |
| 175 |
break; |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
if ( empty( trim( $content_text ) ) ) { |
| 180 |
continue; |
| 181 |
} |
| 182 |
|
| 183 |
$lines[] = '- ' . trim( $content_text ); |
| 184 |
} |
| 185 |
|
| 186 |
if ( empty( $lines ) ) { |
| 187 |
return ''; |
| 188 |
} |
| 189 |
|
| 190 |
return implode( "\n", $lines ); |
| 191 |
} |
| 192 |
|
| 193 |
protected function get_templates(): array { |
| 194 |
return [ |
| 195 |
'elementor/elements/atomic-list' => __DIR__ . '/atomic-list.html.twig', |
| 196 |
]; |
| 197 |
} |
| 198 |
} |
| 199 |
|