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

149 lines 3.7 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 public function render_markdown(): string {
17 return \Elementor\Element_Base::render_markdown();
18 }
19
20 /**
21 * Get default children elements structure.
22 *
23 * @return array
24 */
25 abstract protected function get_default_children_elements();
26
27 /**
28 * Get repeater title setting key name.
29 *
30 * @return string
31 */
32 abstract protected function get_default_repeater_title_setting_key();
33
34 /**
35 * Get default children title for the navigator, using `%d` as index in the format.
36 *
37 * @note The title in this method is used to set the default title for each created child in nested element.
38 * for handling the children title for new created widget(s), use `get_default_children_elements()` method,
39 * eg:
40 * [
41 * 'elType' => 'container',
42 * 'settings' => [
43 * '_title' => __( 'Tab #1', 'elementor' ),
44 * ],
45 * ],
46 * @return string
47 */
48 protected function get_default_children_title() {
49 /* translators: %d: Item index. */
50 return esc_html__( 'Item #%d', 'elementor' );
51 }
52
53 /**
54 * Get default children placeholder selector, Empty string, means will be added at the end view.
55 *
56 * @return string
57 */
58 protected function get_default_children_placeholder_selector() {
59 return '';
60 }
61
62 protected function get_default_children_container_placeholder_selector() {
63 return '';
64 }
65
66 protected function is_dynamic_content(): bool {
67 return false;
68 }
69
70 /**
71 * @inheritDoc
72 *
73 * To support nesting.
74 */
75 protected function _get_default_child_type( array $element_data ) {
76 return Plugin::$instance->elements_manager->get_element_types( $element_data['elType'] );
77 }
78
79 /**
80 * @inheritDoc
81 *
82 * Adding new 'defaults' config for handling children elements.
83 */
84 protected function get_initial_config() {
85 return array_merge( parent::get_initial_config(), [
86 'defaults' => [
87 'elements' => $this->get_default_children_elements(),
88 'elements_title' => $this->get_default_children_title(),
89 'elements_placeholder_selector' => $this->get_default_children_placeholder_selector(),
90 'child_container_placeholder_selector' => $this->get_default_children_container_placeholder_selector(),
91 'repeater_title_setting' => $this->get_default_repeater_title_setting_key(),
92 ],
93 'support_nesting' => true,
94 ] );
95 }
96
97 /**
98 * @inheritDoc
99 *
100 * Each element including its children elements.
101 */
102 public function get_raw_data( $with_html_content = false ) {
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 $children = $this->get_children();
130
131 if ( ! empty( $children[ $index ] ) ) {
132 $children[ $index ]->print_element();
133 }
134 }
135
136 protected function content_template_single_repeater_item() {}
137
138 public function print_template() {
139 parent::print_template();
140 if ( $this->get_initial_config()['support_improved_repeaters'] ?? false ) {
141 ?>
142 <script type="text/html" id="tmpl-elementor-<?php echo esc_attr( $this->get_name() ); ?>-content-single">
143 <?php $this->content_template_single_repeater_item(); ?>
144 </script>
145 <?php
146 }
147 }
148 }
149