PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.0.8
UiCore Elements – Free widgets and templates for Elementor v1.0.8
1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 41 releases
uicore-elements / includes / class-nested-widget-base.php

class-nested-widget-base.php in UiCore Elements – Free widgets and templates for Elementor 1.0.8, at includes/class-nested-widget-base.php

175 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UiCoreElements;
3
4 use Elementor\Plugin;
5
6 /**
7 * Base for nested widgets.
8 * Based on Elementor Nested Widget Class. Keep it in sync with future updates on Elementor core.
9 *
10 * @since 1.0.6
11 */
12
13 abstract class UiCoreNestedWidget extends UiCoreWidget {
14
15 /**
16 * Get default children elements structure.
17 *
18 * @return array
19 */
20 abstract protected function get_default_children_elements();
21
22 /**
23 * Get repeater title setting key name.
24 *
25 * @return string
26 */
27 abstract protected function get_default_repeater_title_setting_key();
28
29 /**
30 * Get default children title for the navigator, using `%d` as index in the format.
31 *
32 * @note The title in this method is used to set the default title for each created child in nested element.
33 * for handling the children title for new created widget(s), use `get_default_children_elements()` method,
34 * eg:
35 * [
36 * 'elType' => 'container',
37 * 'settings' => [
38 * '_title' => __( 'Tab #1', 'elementor' ),
39 * ],
40 * ],
41 * @return string
42 */
43 protected function get_default_children_title() {
44 return esc_html__( 'Item #%d', 'elementor' );
45 }
46
47 /**
48 * Get default children placeholder selector, Empty string, means will be added at the end view.
49 *
50 * @return string
51 */
52 protected function get_default_children_placeholder_selector() {
53 return '';
54 }
55
56 protected function get_default_children_container_placeholder_selector() {
57 return '';
58 }
59
60 /**
61 * @inheritDoc
62 *
63 * To support nesting.
64 */
65 protected function _get_default_child_type( array $element_data ) {
66 return Plugin::$instance->elements_manager->get_element_types( $element_data['elType'] );
67 }
68
69 /**
70 * @inheritDoc
71 *
72 * Adding new 'defaults' config for handling children elements.
73 */
74 protected function get_initial_config() {
75 return array_merge( parent::get_initial_config(), [
76 'defaults' => [
77 'elements' => $this->get_default_children_elements(),
78 'elements_title' => $this->get_default_children_title(),
79 'elements_placeholder_selector' => $this->get_default_children_placeholder_selector(),
80 'child_container_placeholder_selector' => $this->get_default_children_container_placeholder_selector(),
81 'repeater_title_setting' => $this->get_default_repeater_title_setting_key(),
82 ],
83 'support_nesting' => true,
84 ] );
85 }
86
87 /**
88 * @inheritDoc
89 *
90 * Each element including its children elements.
91 */
92 public function get_raw_data( $with_html_content = false ) {
93 $elements = [];
94 $data = $this->get_data();
95
96 $children = $this->get_children();
97
98 foreach ( $children as $child ) {
99 $child_raw_data = $child->get_raw_data( $with_html_content );
100
101 $elements[] = $child_raw_data;
102 }
103
104 return [
105 'id' => $this->get_id(),
106 'elType' => $data['elType'],
107 'widgetType' => $data['widgetType'],
108 'settings' => $data['settings'],
109 'elements' => $elements,
110 ];
111 }
112
113 /**
114 * Print child, helper method to print the child element.
115 *
116 * @param int $index
117 */
118 public function print_child( $index ) {
119 $children = $this->get_children();
120
121 if ( ! empty( $children[ $index ] ) ) {
122 $children[ $index ]->print_element();
123 }
124 }
125
126 protected function content_template_single_repeater_item() {}
127
128 public function print_template() {
129 parent::print_template();
130 if ( $this->get_initial_config()['support_improved_repeaters'] ?? false ) {
131 ?>
132 <script type="text/html" id="tmpl-elementor-<?php echo esc_attr( $this->get_name() ); ?>-content-single">
133 <?php $this->content_template_single_repeater_item(); ?>
134 </script>
135 <?php
136 }
137 }
138
139 /**
140 * Displays fallback content for the nesting feature.
141 *
142 * @param string $type The type of fallback content. Can be `controls` or `text`. Default is `text`.
143 * @return void
144 * @since 1.0.6
145 */
146 public function nesting_fallback(string $type = 'text') {
147
148 if ( 'text' === $type ) {
149
150 echo esc_html__('Please, enable the Nested Elements experiment in Elementor settings to use this widget.', 'uicore-elements');
151
152 } else if ('controls' === $type ){
153 $this->start_controls_section(
154 'section_tabs',
155 [
156 'label' => esc_html__( 'Tabs', 'uicore-elements' ),
157 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
158 ]
159 );
160
161 $this->add_control(
162 'tabs_alert',
163 [
164 'type' => \Elementor\Controls_Manager::ALERT,
165 'alert_type' => 'danger',
166 'heading' => esc_html__( 'Feature Disabled.', 'uicore-elements' ),
167 'content' => esc_html__( 'Please, enable the Nested Elements experiment in Elementor settings to use this widget.', 'uicore-elements' ),
168 ]
169 );
170
171 $this->end_controls_section();
172 }
173 }
174 }
175