]> _ Git - physioassist-wordpress.git/blob
e2305b99c46a0f09557e52207b2759928239367a
[physioassist-wordpress.git] /
1 <?php
2
3 namespace WPML\PB\Elementor\LanguageSwitcher;
4
5 use Elementor\Controls_Manager;
6 use Elementor\Group_Control_Typography;
7 use Elementor\Core\Schemes\Color as SchemeColor;
8
9 class WidgetAdaptor {
10
11         /** @var Widget $widget */
12         private $widget;
13
14         public function setTarget( Widget $widget ) {
15                 $this->widget = $widget;
16         }
17
18         /** @return string */
19         public function getName() {
20                 return 'wpml-language-switcher';
21         }
22
23         /** @return string */
24         public function getTitle() {
25                 return __( 'WPML Language Switcher', 'sitepress' );
26         }
27
28         /** @return string */
29         public function getIcon() {
30                 return 'fa fa-globe';
31         }
32
33         /** @return array */
34         public function getCategories() {
35                 return [ 'general' ];
36         }
37
38         /**
39          * Register controls.
40          *
41          * Used to add new controls to any element type. For example, external
42          * developers use this method to register controls in a widget.
43          *
44          * Should be inherited and register new controls using `add_control()`,
45          * `add_responsive_control()` and `add_group_control()`, inside control
46          * wrappers like `start_controls_section()`, `start_controls_tabs()` and
47          * `start_controls_tab()`.
48          */
49         public function registerControls() {
50                 //Content Tab
51                 $this->widget->start_controls_section(
52                         'section_content',
53                         [
54                                 'label' => __( 'Content', 'sitepress' ),
55                                 'type'  => Controls_Manager::SECTION,
56                                 'tab'   => Controls_Manager::TAB_CONTENT,
57                         ]
58                 );
59
60                 $this->widget->add_control(
61                         'style',
62                         [
63                                 'label'   => __('Language switcher type', 'sitepress'),
64                                 'type'    => Controls_Manager::SELECT,
65                                 'default' => 'custom',
66                                 'options' => [
67                                         'custom'            => __( 'Custom', 'sitepress' ),
68                                         'footer'            => __( 'Footer', 'sitepress' ),
69                                         'post_translations' => __( 'Post Translations', 'sitepress' ),
70                                 ],
71                         ]
72                 );
73
74                 $this->widget->add_control(
75                         'display_flag',
76                         [
77                                 'label'        => __( 'Display Flag', 'sitepress' ),
78                                 'type'         => Controls_Manager::SWITCHER,
79                                 'return_value' => 1,
80                                 'default'      => 1,
81                         ]
82                 );
83
84                 $this->widget->add_control(
85                         'link_current',
86                         [
87                                 'label'        => __( 'Show Active Language - has to be ON with Dropdown', 'sitepress' ),
88                                 'type'         => Controls_Manager::SWITCHER,
89                                 'return_value' => 1,
90                                 'default'      => 1,
91                         ]
92                 );
93
94                 $this->widget->add_control(
95                         'native_language_name',
96                         [
97                                 'label'        => __( 'Native language name', 'sitepress' ),
98                                 'type'         => Controls_Manager::SWITCHER,
99                                 'return_value' => 1,
100                                 'default'      => 1,
101                         ]
102                 );
103
104                 $this->widget->add_control(
105                         'language_name_current_language',
106                         [
107                                 'label'        => __( 'Language name in current language', 'sitepress' ),
108                                 'type'         => Controls_Manager::SWITCHER,
109                                 'return_value' => 1,
110                                 'default'      => 1,
111                         ]
112                 );
113
114                 $this->widget->end_controls_section();
115
116                 $this->widget->start_controls_section(
117                         'style_section',
118                         [
119                                 'label' => __( 'Style', 'sitepress' ),
120                                 'tab'   => Controls_Manager::TAB_STYLE,
121                         ]
122                 );
123                 $this->widget->start_controls_tabs( 'style_tabs' );
124
125                 $this->widget->start_controls_tab(
126                         'style_normal_tab',
127                         [
128                                 'label' => __( 'Normal', 'sitepress' ),
129                         ]
130                 );
131
132                 $this->widget->add_group_control(
133                         Group_Control_Typography::get_type(),
134                         [
135                                 'name'     => 'switcher_typography',
136                                 'selector' => '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-item',
137                         ]
138                 );
139
140                 $this->widget->add_control(
141                         'switcher_text_color',
142                         [
143                                 'label'     => __( 'Text Color', 'sitepress' ),
144                                 'type'      => Controls_Manager::COLOR,
145                                 'scheme'    => [
146                                         'type'  => SchemeColor::get_type(),
147                                         'value' => SchemeColor::COLOR_3,
148                                 ],
149                                 'default'   => '',
150                                 'selectors' => [
151                                         '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link, 
152                                         {{WRAPPER}} .wpml-elementor-ls .wpml-ls-legacy-dropdown a' => 'color: {{VALUE}}',
153                                 ],
154                         ]
155                 );
156
157                 $this->widget->add_control(
158                         'switcher_bg_color',
159                         [
160                                 'label'     => __( 'Background Color', 'sitepress' ),
161                                 'type'      => Controls_Manager::COLOR,
162                                 'default'   => '',
163                                 'selectors' => [
164                                         '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link, 
165                                         {{WRAPPER}} .wpml-elementor-ls .wpml-ls-legacy-dropdown a' => 'background-color: {{VALUE}}',
166                                 ],
167                         ]
168                 );
169
170                 $this->widget->end_controls_tab();
171
172                 $this->widget->start_controls_tab(
173                         'style_hover_tab',
174                         [
175                                 'label' => __( 'Hover', 'sitepress' ),
176                         ]
177                 );
178                 $this->widget->add_group_control(
179                         Group_Control_Typography::get_type(),
180                         [
181                                 'name'     => 'switcher_hover_typography',
182                                 'selector' => '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-item:hover,
183                                         {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item.wpml-ls-item__active,
184                                         {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item.highlighted,
185                                         {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item:focus',
186                         ]
187                 );
188
189                 $this->widget->add_control(
190                         'switcher_hover_color',
191                         [
192                                 'label'     => __( 'Text Color', 'sitepress' ),
193                                 'type'      => Controls_Manager::COLOR,
194                                 'scheme'    => [
195                                         'type'  => SchemeColor::get_type(),
196                                         'value' => SchemeColor::COLOR_4,
197                                 ],
198                                 'selectors' => [
199                                         '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-legacy-dropdown a:hover,
200                                         {{WRAPPER}} .wpml-elementor-ls .wpml-ls-legacy-dropdown a:focus,
201                                         {{WRAPPER}} .wpml-elementor-ls .wpml-ls-legacy-dropdown .wpml-ls-current-language:hover>a,
202                                         {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link:hover,
203                                         {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link.wpml-ls-link__active,
204                                         {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link.highlighted,
205                                         {{WRAPPER}} .wpml-elementor-ls .wpml-ls-item .wpml-ls-link:focus' => 'color: {{VALUE}}',
206                                 ],
207                         ]
208                 );
209
210                 $this->widget->end_controls_tab();
211
212                 $this->widget->end_controls_tabs();
213
214                 $this->widget->end_controls_section();
215
216                 $this->widget->start_controls_section(
217                         'language_flag',
218                         [
219                                 'label'     => __( 'Language Flag', 'sitepress' ),
220                                 'tab'       => Controls_Manager::TAB_STYLE,
221                                 'condition' => [
222                                         'display_flag' => [ 1 ],
223                                 ],
224                         ]
225                 );
226
227                 $this->widget->add_control(
228                         'flag_margin',
229                         [
230                                 'label'      => __( 'Margin', 'sitepress' ),
231                                 'type'       => Controls_Manager::DIMENSIONS,
232                                 'size_units' => [ 'px', '%', 'em' ],
233                                 'selectors'  => [
234                                         '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-flag' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
235                                 ],
236                         ]
237                 );
238
239                 $this->widget->end_controls_section();
240
241                 $this->widget->start_controls_section(
242                         'post_translation_text',
243                         [
244                                 'label'     => __( 'Post Translation Text', 'sitepress' ),
245                                 'tab'       => Controls_Manager::TAB_STYLE,
246                                 'condition' => [
247                                         'style' => [ 'post_translations' ],
248                                 ],
249                         ]
250                 );
251
252                 $this->widget->add_group_control(
253                         Group_Control_Typography::get_type(),
254                         [
255                                 'name' => 'post_translation_typography',
256                                 'selector' => '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-statics-post_translations',
257                         ]
258                 );
259
260                 $this->widget->add_control(
261                         'post_translation_color',
262                         [
263                                 'label'     => __( 'Text Color', 'sitepress' ),
264                                 'type'      => Controls_Manager::COLOR,
265                                 'scheme'    => [
266                                         'type'  => SchemeColor::get_type(),
267                                         'value' => SchemeColor::COLOR_3,
268                                 ],
269                                 'default'   => '',
270                                 'selectors' => [
271                                         '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-statics-post_translations' => 'color: {{VALUE}}',
272                                 ],
273                         ]
274                 );
275
276                 $this->widget->add_control(
277                         'post_translation_bg_color',
278                         [
279                                 'label'     => __( 'Background Color', 'sitepress' ),
280                                 'type'      => Controls_Manager::COLOR,
281                                 'default'   => '',
282                                 'selectors' => [
283                                         '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-statics-post_translations' => 'background-color: {{VALUE}}',
284                                 ],
285                         ]
286                 );
287
288                 $this->widget->add_control(
289                         'post_translation_padding',
290                         [
291                                 'label'      => __( 'Padding', 'sitepress' ),
292                                 'type'       => Controls_Manager::DIMENSIONS,
293                                 'size_units' => [ 'px', '%', 'em' ],
294                                 'selectors'  => [
295                                         '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-statics-post_translations' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
296                                 ],
297                         ]
298                 );
299
300                 $this->widget->add_control(
301                         'post_translation_margin',
302                         [
303                                 'label'      => __( 'Margin', 'sitepress' ),
304                                 'type'       => Controls_Manager::DIMENSIONS,
305                                 'size_units' => [ 'px', '%', 'em' ],
306                                 'selectors'  => [
307                                         '{{WRAPPER}} .wpml-elementor-ls .wpml-ls-statics-post_translations' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
308                                 ],
309                         ]
310                 );
311
312                 $this->widget->end_controls_section();
313
314         }
315
316         /**
317          * Render element.
318          *
319          * Generates the final HTML on the frontend.
320          */
321         public function render() {
322                 $settings = $this->widget->get_settings_for_display();
323
324                 $this->widget->add_render_attribute('wpml-elementor-ls', 'class', [
325                         'wpml-elementor-ls',
326                 ]);
327
328                 $args = array(
329                         'display_link_for_current_lang' => $settings['link_current'],
330                         'flags'                         => $settings['display_flag'],
331                         'native'                        => $settings['native_language_name'],
332                         'translated'                    => $settings['language_name_current_language'],
333                         'type'                          => $settings['style'],
334                 );
335
336                 if ( 'custom' === $settings['style'] ) {
337                         //forcing in dropdown case
338                         $args['display_link_for_current_lang'] = 1;
339                 }
340
341                 echo "<div " . $this->widget->get_render_attribute_string('wpml-elementor-ls') . ">";
342                 do_action('wpml_language_switcher', $args);
343                 echo "</div>";
344         }
345 }