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

122 lines 2.9 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 /**
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', 'elementor' ),
40 * ],
41 * ],
42 * @return string
43 */
44 protected function get_default_children_title() {
45 return esc_html__( 'Item #%d', 'elementor' );
46 }
47
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 }
56
57 /**
58 * @inheritDoc
59 *
60 * To support nesting.
61 */
62 protected function _get_default_child_type( array $element_data ) {
63 return Plugin::$instance->elements_manager->get_element_types( $element_data['elType'] );
64 }
65
66 /**
67 * @inheritDoc
68 *
69 * Adding new 'defaults' config for handling children elements.
70 */
71 protected function get_initial_config() {
72 return array_merge( parent::get_initial_config(), [
73 'defaults' => [
74 'elements' => $this->get_default_children_elements(),
75 'elements_title' => $this->get_default_children_title(),
76 'elements_placeholder_selector' => $this->get_default_children_placeholder_selector(),
77 'repeater_title_setting' => $this->get_default_repeater_title_setting_key(),
78 ],
79 'support_nesting' => true,
80 ] );
81 }
82
83 /**
84 * @inheritDoc
85 *
86 * Each element including its children elements.
87 */
88 public function get_raw_data( $with_html_content = false ) {
89 $elements = [];
90 $data = $this->get_data();
91
92 $children = $this->get_children();
93
94 foreach ( $children as $child ) {
95 $child_raw_data = $child->get_raw_data( $with_html_content );
96
97 $elements[] = $child_raw_data;
98 }
99
100 return [
101 'id' => $this->get_id(),
102 'elType' => $data['elType'],
103 'widgetType' => $data['widgetType'],
104 'settings' => $data['settings'],
105 'elements' => $elements,
106 ];
107 }
108
109 /**
110 * Print child, helper method to print the child element.
111 *
112 * @param int $index
113 */
114 public function print_child( $index ) {
115 $children = $this->get_children();
116
117 if ( ! empty( $children[ $index ] ) ) {
118 $children[ $index ]->print_element();
119 }
120 }
121 }
122