1
<?php
2
defined('ABSPATH') || exit;
3
require_once __DIR__ . '/elementor-widget-base.php';
4
if (!class_exists('FRESH_OO_Field_Widget') && class_exists('FRESH_OO_Widget_Base')) {
5
class FRESH_OO_Field_Widget extends FRESH_OO_Widget_Base {
6
public function get_name(): string { return 'fresh-oo-field'; }
7
public function get_title(): string { return 'onOffice Feld'; }
8
public function get_icon(): string { return 'eicon-dynamic-tags'; }
9
public function get_keywords(): array { return ['onoffice','immobilie','feld','meta','dynamic']; }
10
protected function register_controls(): void {
11
$this->start_controls_section('content',['label'=>'Feld']);
12
$this->add_control('field',['label'=>'onOffice-Feld','type'=>\Elementor\Controls_Manager::SELECT2,'options'=>$this->field_options(true),'label_block'=>true]);
13
$this->add_control('label',['label'=>'Eigenes Label','type'=>\Elementor\Controls_Manager::TEXT,'placeholder'=>'Automatisch']);
14
$this->add_control('show_label',['label'=>'Label anzeigen','type'=>\Elementor\Controls_Manager::SWITCHER,'default'=>'yes']);
15
$this->add_control('format',['label'=>'Formatierung','type'=>\Elementor\Controls_Manager::SELECT,'default'=>'auto','options'=>['auto'=>'Automatisch','text'=>'Text','integer'=>'Ganzzahl','number'=>'Zahl','year'=>'Jahr','date'=>'Datum','price'=>'Preis (€)','area'=>'Fläche (m²)','energy'=>'Energie kWh/(m²·a)','boolean'=>'Ja / Nein','array'=>'Liste']]);
16
$this->add_control('prefix',['label'=>'Präfix','type'=>\Elementor\Controls_Manager::TEXT]);
17
$this->add_control('suffix',['label'=>'Suffix','type'=>\Elementor\Controls_Manager::TEXT]);
18
$this->add_control('hide_empty',['label'=>'Bei leerem Wert ausblenden','type'=>\Elementor\Controls_Manager::SWITCHER,'default'=>'yes']);
19
$this->add_control('icon',['label'=>'Icon','type'=>\Elementor\Controls_Manager::ICONS]);
20
$this->add_responsive_control('layout',['label'=>'Layout','type'=>\Elementor\Controls_Manager::CHOOSE,'default'=>'row','options'=>['row'=>['title'=>'Nebeneinander','icon'=>'eicon-h-align-left'],'column'=>['title'=>'Untereinander','icon'=>'eicon-v-align-top']],'selectors'=>['{{WRAPPER}} .fresh-oo-field'=>'flex-direction: {{VALUE}};']]);
21
$this->end_controls_section();
22
$this->start_controls_section('style_card',['label'=>'Box','tab'=>\Elementor\Controls_Manager::TAB_STYLE]);
23
$this->add_common_card_style_controls('card','{{WRAPPER}} .fresh-oo-field');
24
$this->add_responsive_control('gap',['label'=>'Abstand','type'=>\Elementor\Controls_Manager::SLIDER,'range'=>['px'=>['min'=>0,'max'=>60]],'selectors'=>['{{WRAPPER}} .fresh-oo-field'=>'gap: {{SIZE}}{{UNIT}};']]);
25
$this->add_control('icon_color',['label'=>'Icon-Farbe','type'=>\Elementor\Controls_Manager::COLOR,'selectors'=>['{{WRAPPER}} .fresh-oo-field__icon'=>'color: {{VALUE}};']]);
26
$this->add_responsive_control('icon_size',['label'=>'Icon-Größe','type'=>\Elementor\Controls_Manager::SLIDER,'range'=>['px'=>['min'=>8,'max'=>80]],'selectors'=>['{{WRAPPER}} .fresh-oo-field__icon svg'=>'width: {{SIZE}}{{UNIT}};height: {{SIZE}}{{UNIT}};']]);
27
$this->end_controls_section();
28
$this->start_controls_section('style_text',['label'=>'Text','tab'=>\Elementor\Controls_Manager::TAB_STYLE]);
29
$this->add_control('label_color',['label'=>'Label-Farbe','type'=>\Elementor\Controls_Manager::COLOR,'selectors'=>['{{WRAPPER}} .fresh-oo-field__label'=>'color: {{VALUE}};']]);
30
$this->add_group_control(\Elementor\Group_Control_Typography::get_type(),['name'=>'label_typo','selector'=>'{{WRAPPER}} .fresh-oo-field__label']);
31
$this->add_control('value_color',['label'=>'Wert-Farbe','type'=>\Elementor\Controls_Manager::COLOR,'selectors'=>['{{WRAPPER}} .fresh-oo-field__value'=>'color: {{VALUE}};']]);
32
$this->add_group_control(\Elementor\Group_Control_Typography::get_type(),['name'=>'value_typo','selector'=>'{{WRAPPER}} .fresh-oo-field__value']);
33
$this->end_controls_section();
34
}
35
protected function render(): void {
36
$s=$this->get_settings_for_display(); $key=(string)($s['field']??''); $value=$this->meta($key);
37
if ($key==='' || (!$this->meaningful_value($value,$key,true) && ($s['hide_empty']??'yes')==='yes')) { $this->editor_empty('Wähle ein onOffice-Feld mit Inhalt.'); return; }
38
$defs=$this->field_definitions(); $label=trim((string)($s['label']??'')) ?: ($defs[$key][0]??$key);
39
$format=($s['format']??'auto')==='auto' ? $this->inferred_format($key) : $s['format'];
40
$display=$this->pretty_value($value,$key,$format); if ($display==='') return;
41
echo '<div class="fresh-oo-field">'; $this->render_selected_icon($s['icon']??[],'fresh-oo-field__icon'); echo '<div class="fresh-oo-field__body">';
42
if (($s['show_label']??'yes')==='yes') echo '<span class="fresh-oo-field__label">'.esc_html($label).'</span>';
43
echo '<span class="fresh-oo-field__value">'.esc_html((string)($s['prefix']??'')).esc_html($display).esc_html((string)($s['suffix']??'')).'</span></div></div>';
44
}
45
}
46
}
47