PluginProbe
Elementor Website Builder – more than just a page builder / 3.21.3
Elementor Website Builder – more than just a page builder v3.21.3
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 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / nested-elements / base / widget-nested-base.php

widget-nested-base.php in Elementor Website Builder – more than just a page builder 3.21.3, at modules/nested-elements/base/widget-nested-base.php

140 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\NestedElements\Base;
3
4 use Elementor\Plugin;
5 use Elementor\Widget_Base;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 /**
12 * Used to create a new widget that can be nested inside other widgets.
13 */
14 abstract class Widget_Nested_Base extends Widget_Base {
15
16 /**
17 * Get default children elements structure.
18 *
19 * @return array
20 */
21 abstract protected function get_default_children_elements();
22
23 /**
24 * Get repeater title setting key name.
25 *
26 * @return string
27 */
28 abstract protected function get_default_repeater_title_setting_key();
29
30 /**
31 * Get default children title for the navigator, using `%d` as index in the format.
32 *
33 * @note The title in this method is used to set the default title for each created child in nested element.
34 * for handling the children title for new created widget(s), use `get_default_children_elements()` method,
35 * eg:
36 * [
37 * 'elType' => 'container',
38 * 'settings' => [
39 * '_title' => __( 'Tab #1', 'elementor' ),
40 * ],
41 * ],
42 * @return string
43 */
44 protected function get_default_children_title() {
45 return esc_html__( 'Item #%d', 'elementor' );
46 }
47
48 /**
49 * Get default children placeholder selector, Empty string, means will be added at the end view.
50 *
51 * @return string
52 */
53 protected function get_default_children_placeholder_selector() {
54 return '';
55 }
56
57 protected function get_default_children_container_placeholder_selector() {
58 return '';
59 }
60
61 /**
62 * @inheritDoc
63 *
64 * To support nesting.
65 */
66 protected function _get_default_child_type( array $element_data ) {
67 return Plugin::$instance->elements_manager->get_element_types( $element_data['elType'] );
68 }
69
70 /**
71 * @inheritDoc
72 *
73 * Adding new 'defaults' config for handling children elements.
74 */
75 protected function get_initial_config() {
76 return array_merge( parent::get_initial_config(), [
77 'defaults' => [
78 'elements' => $this->get_default_children_elements(),
79 'elements_title' => $this->get_default_children_title(),
80 'elements_placeholder_selector' => $this->get_default_children_placeholder_selector(),
81 'child_container_placeholder_selector' => $this->get_default_children_container_placeholder_selector(),
82 'repeater_title_setting' => $this->get_default_repeater_title_setting_key(),
83 ],
84 'support_nesting' => true,
85 ] );
86 }
87
88 /**
89 * @inheritDoc
90 *
91 * Each element including its children elements.
92 */
93 public function get_raw_data( $with_html_content = false ) {
94 $elements = [];
95 $data = $this->get_data();
96
97 $children = $this->get_children();
98
99 foreach ( $children as $child ) {
100 $child_raw_data = $child->get_raw_data( $with_html_content );
101
102 $elements[] = $child_raw_data;
103 }
104
105 return [
106 'id' => $this->get_id(),
107 'elType' => $data['elType'],
108 'widgetType' => $data['widgetType'],
109 'settings' => $data['settings'],
110 'elements' => $elements,
111 ];
112 }
113
114 /**
115 * Print child, helper method to print the child element.
116 *
117 * @param int $index
118 */
119 public function print_child( $index ) {
120 $children = $this->get_children();
121
122 if ( ! empty( $children[ $index ] ) ) {
123 $children[ $index ]->print_element();
124 }
125 }
126
127 protected function content_template_single_repeater_item() {}
128
129 public function print_template() {
130 parent::print_template();
131 if ( $this->get_initial_config()['support_improved_repeaters'] ?? false ) {
132 ?>
133 <script type="text/html" id="tmpl-elementor-<?php echo esc_attr( $this->get_name() ); ?>-content-single">
134 <?php $this->content_template_single_repeater_item(); ?>
135 </script>
136 <?php
137 }
138 }
139 }
140