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

187 lines 5.0 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 use Elementor\Settings;
6
7 /**
8 * Base for nested widgets.
9 * Based on Elementor Nested Widget Class. Keep it in sync with future updates on Elementor core.
10 *
11 * @since 1.0.6
12 */
13
14 abstract class UiCoreNestedWidget extends UiCoreWidget {
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', 'uicore-elements' ),
40 * ],
41 * ],
42 * @return string
43 */
44 protected function get_default_children_title() {
45 /* translators: item number */
46 return esc_html__( 'Item #%d', 'uicore-elements' );
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 /**
63 * @inheritDoc
64 *
65 * To support nesting.
66 */
67 protected function _get_default_child_type( array $element_data ) {
68 return Plugin::$instance->elements_manager->get_element_types( $element_data['elType'] );
69 }
70
71 /**
72 * @inheritDoc
73 *
74 * Adding new 'defaults' config for handling children elements.
75 */
76 protected function get_initial_config() {
77 return array_merge( parent::get_initial_config(), [
78 'defaults' => [
79 'elements' => $this->get_default_children_elements(),
80 'elements_title' => $this->get_default_children_title(),
81 'elements_placeholder_selector' => $this->get_default_children_placeholder_selector(),
82 'child_container_placeholder_selector' => $this->get_default_children_container_placeholder_selector(),
83 'repeater_title_setting' => $this->get_default_repeater_title_setting_key(),
84 ],
85 'support_nesting' => true,
86 ] );
87 }
88
89 /**
90 * @inheritDoc
91 *
92 * Each element including its children elements.
93 */
94 public function get_raw_data( $with_html_content = false ) {
95 $elements = [];
96 $data = $this->get_data();
97
98 $children = $this->get_children();
99
100 foreach ( $children as $child ) {
101 $child_raw_data = $child->get_raw_data( $with_html_content );
102
103 $elements[] = $child_raw_data;
104 }
105
106 return [
107 'id' => $this->get_id(),
108 'elType' => $data['elType'],
109 'widgetType' => $data['widgetType'],
110 'settings' => $data['settings'],
111 'elements' => $elements,
112 ];
113 }
114
115 /**
116 * Print child, helper method to print the child element.
117 *
118 * @param int $index
119 */
120 public function print_child( $index ) {
121 $children = $this->get_children();
122 // \error_log('print_child');
123 // \error_log( print_r( $children, true ) );
124 // \error_log( print_r( $index, true ) );
125 if ( ! empty( $children[ $index ] ) ) {
126 $children[ $index ]->print_element();
127 }
128 }
129
130 protected function content_template_single_repeater_item() {}
131
132 public function print_template() {
133 parent::print_template();
134 if ( $this->get_initial_config()['support_improved_repeaters'] ?? false ) {
135 ?>
136 <script type="text/html" id="tmpl-elementor-<?php echo esc_attr( $this->get_name() ); ?>-content-single">
137 <?php $this->content_template_single_repeater_item(); ?>
138 </script>
139 <?php
140 }
141 }
142
143 /**
144 * Displays fallback content for the nesting feature.
145 *
146 * @param string $type The type of fallback content. Can be `controls` or `text`. Default is `text`.
147 * @return void
148 * @since 1.0.6
149 */
150 public function nesting_fallback(string $type = 'text') {
151
152 /* translators: 1: Opening anchor tag, 2: Closing anchor tag for the link to the Elementor settings page. */
153 $warning = sprintf(
154 /* translators: 1: opening url tags 2: closing url tag */
155 __('Please, %1$s click here %2$s and enable the Nested Elements experiment in Elementor settings', 'uicore-elements'),
156 '<a href="' . esc_attr( Settings::get_settings_tab_url('experiments') ) . '" target="_blank">',
157 '</a>'
158 );
159
160 if ( 'text' === $type ) {
161
162 echo wp_kses_post($warning);
163
164 } else if ('controls' === $type ){
165 $this->start_controls_section(
166 'section_tabs',
167 [
168 'label' => esc_html__( 'Tabs', 'uicore-elements' ),
169 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
170 ]
171 );
172
173 $this->add_control(
174 'tabs_alert',
175 [
176 'type' => \Elementor\Controls_Manager::ALERT,
177 'alert_type' => 'danger',
178 'heading' => esc_html__( 'Feature Disabled.', 'uicore-elements' ),
179 'content' => wp_kses_post($warning)
180 ]
181 );
182
183 $this->end_controls_section();
184 }
185 }
186 }
187