PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.0
Elementor Website Builder – more than just a page builder v4.2.0
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 4.2.0, at modules/nested-elements/base/widget-nested-base.php

145 lines 3.6 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 /* translators: %d: Item index. */
46 return esc_html__( 'Item #%d', 'elementor' );
47 }
48
49 /**
50 * Get default children placeholder selector, Empty string, means will be added at the end view.
51 *
52 * @return string
53 */
54 protected function get_default_children_placeholder_selector() {
55 return '';
56 }
57
58 protected function get_default_children_container_placeholder_selector() {
59 return '';
60 }
61
62 protected function is_dynamic_content(): bool {
63 return false;
64 }
65
66 /**
67 * @inheritDoc
68 *
69 * To support nesting.
70 */
71 protected function _get_default_child_type( array $element_data ) {
72 return Plugin::$instance->elements_manager->get_element_types( $element_data['elType'] );
73 }
74
75 /**
76 * @inheritDoc
77 *
78 * Adding new 'defaults' config for handling children elements.
79 */
80 protected function get_initial_config() {
81 return array_merge( parent::get_initial_config(), [
82 'defaults' => [
83 'elements' => $this->get_default_children_elements(),
84 'elements_title' => $this->get_default_children_title(),
85 'elements_placeholder_selector' => $this->get_default_children_placeholder_selector(),
86 'child_container_placeholder_selector' => $this->get_default_children_container_placeholder_selector(),
87 'repeater_title_setting' => $this->get_default_repeater_title_setting_key(),
88 ],
89 'support_nesting' => true,
90 ] );
91 }
92
93 /**
94 * @inheritDoc
95 *
96 * Each element including its children elements.
97 */
98 public function get_raw_data( $with_html_content = false ) {
99 $elements = [];
100 $data = $this->get_data();
101
102 $children = $this->get_children();
103
104 foreach ( $children as $child ) {
105 $child_raw_data = $child->get_raw_data( $with_html_content );
106
107 $elements[] = $child_raw_data;
108 }
109
110 return [
111 'id' => $this->get_id(),
112 'elType' => $data['elType'],
113 'widgetType' => $data['widgetType'],
114 'settings' => $data['settings'],
115 'elements' => $elements,
116 ];
117 }
118
119 /**
120 * Print child, helper method to print the child element.
121 *
122 * @param int $index
123 */
124 public function print_child( $index ) {
125 $children = $this->get_children();
126
127 if ( ! empty( $children[ $index ] ) ) {
128 $children[ $index ]->print_element();
129 }
130 }
131
132 protected function content_template_single_repeater_item() {}
133
134 public function print_template() {
135 parent::print_template();
136 if ( $this->get_initial_config()['support_improved_repeaters'] ?? false ) {
137 ?>
138 <script type="text/html" id="tmpl-elementor-<?php echo esc_attr( $this->get_name() ); ?>-content-single">
139 <?php $this->content_template_single_repeater_item(); ?>
140 </script>
141 <?php
142 }
143 }
144 }
145