PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.3.18
UiCore Elements – Free widgets and templates for Elementor v1.3.18
1.3.18 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 All 42 releases
← All changes | includes/class-nested-widget-base.php +156 -141 1.0.9 → 1.3.18 View file →
@@ -1,5 +1,6 @@
1 1 <?php
2 +
2 3 namespace UiCoreElements;
3 4
4 5 use Elementor\Plugin;
5 6 use Elementor\Settings;
@@ -10,172 +11,186 @@
10 11 *
11 12 * @since 1.0.6
12 13 */
13 14
14 -abstract class UiCoreNestedWidget extends UiCoreWidget {
15 +abstract class UiCoreNestedWidget extends UiCoreWidget
16 +{
15 17
16 18 /**
17 - * Get default children elements structure.
18 - *
19 - * @return array
20 - */
21 - abstract protected function get_default_children_elements();
19 + * Get default children elements structure.
20 + *
21 + * @return array
22 + */
23 + abstract protected function get_default_children_elements();
22 24
23 - /**
24 - * Get repeater title setting key name.
25 - *
26 - * @return string
27 - */
28 - abstract protected function get_default_repeater_title_setting_key();
25 + /**
26 + * Get repeater title setting key name.
27 + *
28 + * @return string
29 + */
30 + abstract protected function get_default_repeater_title_setting_key();
29 31
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 - }
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 + }
47 51
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 - }
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 + }
56 61
57 - protected function get_default_children_container_placeholder_selector() {
58 - return '';
59 - }
62 + protected function get_default_children_container_placeholder_selector()
63 + {
64 + return '';
65 + }
60 66
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 - }
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 + }
69 76
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 - }
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 + }
87 95
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 + * @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();
96 105
97 - $children = $this->get_children();
106 + $children = $this->get_children();
98 107
99 - foreach ( $children as $child ) {
100 - $child_raw_data = $child->get_raw_data( $with_html_content );
108 + foreach ($children as $child) {
109 + $child_raw_data = $child->get_raw_data($with_html_content);
101 110
102 - $elements[] = $child_raw_data;
103 - }
111 + $elements[] = $child_raw_data;
112 + }
104 113
105 - return [
106 - 'id' => $this->get_id(),
107 - 'elType' => $data['elType'],
108 - 'widgetType' => $data['widgetType'],
109 - 'settings' => $data['settings'],
110 - 'elements' => $elements,
111 - ];
112 - }
114 + return [
115 + 'id' => $this->get_id(),
116 + 'elType' => $data['elType'],
117 + 'widgetType' => $data['widgetType'],
118 + 'settings' => $data['settings'],
119 + 'elements' => $elements,
120 + ];
121 + }
113 122
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();
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 + }
121 138
122 - if ( ! empty( $children[ $index ] ) ) {
123 - $children[ $index ]->print_element();
124 - }
125 - }
139 + protected function content_template_single_repeater_item() {}
126 140
127 - protected function content_template_single_repeater_item() {}
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 + }
128 152
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 - }
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 + {
139 162
140 - /**
141 - * Displays fallback content for the nesting feature.
142 - *
143 - * @param string $type The type of fallback content. Can be `controls` or `text`. Default is `text`.
144 - * @return void
145 - * @since 1.0.6
146 - */
147 - public function nesting_fallback(string $type = 'text') {
148 -
163 + /* translators: 1: Opening anchor tag, 2: Closing anchor tag for the link to the Elementor settings page. */
149 164 $warning = sprintf(
150 - __('Please, %s click here %s and enable the Nested Elements experiment in Elementor settings', 'uicore-elements'),
151 - '<a href="' . esc_attr( Settings::get_settings_tab_url('experiments') ) . '" target="_blank">',
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">',
152 168 '</a>'
153 169 );
154 170
155 - if ( 'text' === $type ) {
171 + if ('text' === $type) {
156 172
157 - echo wp_kses_post($warning);
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 + );
158 182
159 - } else if ('controls' === $type ){
160 - $this->start_controls_section(
161 - 'section_tabs',
162 - [
163 - 'label' => esc_html__( 'Tabs', 'uicore-elements' ),
164 - 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
165 - ]
166 - );
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 + );
167 192
168 - $this->add_control(
169 - 'tabs_alert',
170 - [
171 - 'type' => \Elementor\Controls_Manager::ALERT,
172 - 'alert_type' => 'danger',
173 - 'heading' => esc_html__( 'Feature Disabled.', 'uicore-elements' ),
174 - 'content' => wp_kses_post($warning)
175 - ]
176 - );
177 -
178 - $this->end_controls_section();
179 - }
193 + $this->end_controls_section();
194 + }
180 195 }
181 196 }