@@ -15,36 +15,43 @@ public function get_format() {
15
15
return 'globals/colors/{id} ' ;
16
16
}
17
17
18
- protected function get_kit_items () {
19
- $ result = array ();
20
- $ global_kit = Plugin::elementor ()->kits_manager ->get_active_kit_for_frontend ();
21
-
22
- $ system_items = $ global_kit ->get_settings_for_display ( 'system_colors ' );
23
- $ custom_items = $ global_kit ->get_settings_for_display ( 'custom_colors ' );
24
-
25
- if ( ! $ system_items ) {
26
- $ system_items = array ();
27
- }
28
-
29
- if ( ! $ custom_items ) {
30
- $ custom_items = array ();
18
+ /**
19
+ * Adds global kit colors if page kit colors are not set.
20
+ *
21
+ * @param $result
22
+ * @param $kit_result
23
+ * @return mixed
24
+ */
25
+ protected function get_set_colors ( $ result , $ kit_result ) {
26
+ foreach ( $ kit_result as $ key => $ value ) {
27
+ if ( ! empty ( $ value ['value ' ] ) ) {
28
+
29
+ if ( ! isset ( $ result [ $ key ] ) ) {
30
+ $ result [ $ key ] = $ value ;
31
+ continue ;
32
+ }
33
+
34
+ $ old_value = $ result [ $ key ];
35
+
36
+ if ( empty ( $ old_value ['value ' ] ) ) {
37
+ $ result [ $ key ] = $ value ;
38
+ }
39
+ }
31
40
}
32
41
33
- $ items = array_merge ( $ system_items , $ custom_items );
42
+ return $ result ;
43
+ }
34
44
35
- // Custom hack for getting the active kit on page.
36
- $ current_page_id = Options::get_instance ()->get ( 'ang_current_page_id ' );
37
- $ kit = false ;
38
- if ( $ current_page_id ) {
39
- $ kit = Utils::get_document_kit ( $ current_page_id );
40
- }
45
+ protected function get_kit_colors ( $ kit ) {
46
+ $ result = array ();
41
47
42
- // Fallback to global kit.
43
- if ( ! $ kit ) {
44
- $ kit = $ global_kit ;
48
+ if ( ! $ kit && method_exists ( $ kit , 'get_id ' ) && ! Plugin::elementor ()->kits_manager ->is_kit ( $ kit ->get_id () ) ) {
49
+ return $ result ;
45
50
}
46
51
47
52
$ color_keys = array (
53
+ 'system_colors ' ,
54
+ 'custom_colors ' ,
48
55
'ang_global_background_colors ' ,
49
56
'ang_global_accent_colors ' ,
50
57
'ang_global_text_colors ' ,
@@ -55,6 +62,8 @@ protected function get_kit_items() {
55
62
'ang_global_tertiary_part_two_colors ' ,
56
63
);
57
64
65
+ $ items = array ();
66
+
58
67
foreach ( $ color_keys as $ color_key ) {
59
68
$ colors = $ kit ->get_settings_for_display ( $ color_key );
60
69
@@ -63,6 +72,7 @@ protected function get_kit_items() {
63
72
}
64
73
65
74
$ items = array_merge ( $ items , $ colors );
75
+
66
76
}
67
77
68
78
foreach ( $ items as $ index => $ item ) {
@@ -77,6 +87,37 @@ protected function get_kit_items() {
77
87
return $ result ;
78
88
}
79
89
90
+ protected function get_kit_items () {
91
+ $ global_kit = Plugin::elementor ()->kits_manager ->get_active_kit_for_frontend ();
92
+
93
+ // Whether to also get the globals data.
94
+ $ also_inline_global_kit = Options::get_instance ()->get ( 'also_inline_global_kit ' );
95
+
96
+ // Custom hack for getting the active kit on page.
97
+ $ current_page_id = Options::get_instance ()->get ( 'ang_current_page_id ' );
98
+ $ kit = false ;
99
+
100
+ if ( $ current_page_id ) {
101
+ $ kit = Utils::get_document_kit ( $ current_page_id );
102
+ }
103
+
104
+ // Fallback to global kit.
105
+ if ( ! $ kit ) {
106
+ $ kit = $ global_kit ;
107
+ }
108
+
109
+ $ result = $ this ->get_kit_colors ( $ kit );
110
+
111
+ if ( $ also_inline_global_kit ) {
112
+ // In case there is a page kit we add the global kit data.
113
+ $ global_kit_result = $ this ->get_kit_colors ( $ global_kit );
114
+ $ result = array_merge ( $ global_kit_result , $ result );
115
+ $ result = $ this ->get_set_colors ( $ result , $ global_kit_result );
116
+ }
117
+
118
+ return $ result ;
119
+ }
120
+
80
121
protected function convert_db_format ( $ item ) {
81
122
return array (
82
123
'_id ' => $ item ['id ' ],
0 commit comments