PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.3.17
UiCore Elements – Free widgets and templates for Elementor v1.3.17
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.3.17, at includes/class-nested-widget-base.php

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