PluginProbe
Elementor Website Builder – more than just a page builder / 3.6.0-dev1
Elementor Website Builder – more than just a page builder v3.6.0-dev1
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 / default-values / module.php

module.php in Elementor Website Builder – more than just a page builder 3.6.0-dev1, at modules/default-values/module.php

128 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\DefaultValues;
3
4 use Elementor\Plugin;
5 use Elementor\Controls_Stack;
6 use Elementor\Core\Utils\Collection;
7 use Elementor\Core\Experiments\Manager;
8 use Elementor\Core\Base\Module as BaseModule;
9 use Elementor\Modules\DefaultValues\Data\Controller;
10 use Elementor\Modules\DefaultValues\Data\Repository;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // Exit if accessed directly.
14 }
15
16 class Module extends BaseModule {
17 /**
18 * @return string
19 */
20 public function get_name() {
21 return 'default-values';
22 }
23
24 /**
25 * @return array
26 */
27 public static function get_experimental_data() {
28 return [
29 'name' => 'default-values',
30 'title' => esc_html__( 'Custom Default Widget Styles', 'elementor' ),
31 'description' => esc_html__( 'Define the custom style settings of a widget as the default for other widgets when they are dragged onto the editor. This will help manage your site’s design system and keep your styling consistent.', 'elementor' ),
32 'release_status' => Manager::RELEASE_STATUS_ALPHA,
33 'default' => Manager::STATE_INACTIVE,
34 ];
35 }
36
37 private function enqueue_scripts() {
38 wp_enqueue_script(
39 'editor-default-values',
40 $this->get_js_assets_url( 'editor-default-values' ),
41 [ 'elementor-common' ],
42 ELEMENTOR_VERSION,
43 true
44 );
45 }
46
47 private function update_control_defaults( Controls_Stack $element ) {
48 $dynamic_defaults = new Collection(
49 Repository::instance()->get( $element->get_name() )['settings']
50 );
51
52 $this->update_local_control_defaults( $element, $dynamic_defaults );
53 $this->update_global_control_defaults( $element, $dynamic_defaults );
54 }
55
56 private function update_local_control_defaults( Controls_Stack $element, Collection $defaults ) {
57 $local_defaults = $defaults->filter( function ( $value, $key ) {
58 return '__globals__' !== $key;
59 } );
60
61 foreach ( $local_defaults as $setting_name => $value ) {
62 $control = $element->get_controls( $setting_name );
63
64 if ( ! $control ) {
65 continue;
66 }
67
68 $element->update_control(
69 $setting_name,
70 $this->prepare_default_data_for_update(
71 $control,
72 $value
73 ),
74 [ 'recursive' => true ]
75 );
76 }
77 }
78
79 private function update_global_control_defaults( Controls_Stack $element, Collection $defaults ) {
80 $global_defaults = new Collection(
81 $defaults->get( '__globals__', [] )
82 );
83
84 foreach ( $global_defaults as $setting_name => $value ) {
85 $control = $element->get_controls( $setting_name );
86
87 if ( ! $control ) {
88 continue;
89 }
90
91 $element->update_control(
92 $setting_name,
93 [
94 'global' => $this->prepare_default_data_for_update(
95 isset( $control['global'] ) ? $control['global'] : [],
96 $value
97 ),
98 ],
99 [ 'recursive' => true ]
100 );
101 }
102 }
103
104 private function prepare_default_data_for_update( array $control, $value ) {
105 $data = [ 'default' => $value ];
106
107 if ( isset( $control['default'] ) ) {
108 $data['hardcoded_default'] = $control['default'];
109 }
110
111 return $data;
112 }
113
114 public function __construct() {
115 parent::__construct();
116
117 add_action( 'elementor/editor/before_enqueue_scripts', function () {
118 $this->enqueue_scripts();
119 } );
120
121 add_action( 'elementor/control_stack/controls/init', function ( Controls_Stack $element ) {
122 $this->update_control_defaults( $element );
123 } );
124
125 Plugin::$instance->data_manager_v2->register_controller( new Controller() );
126 }
127 }
128