<?php
declare(strict_types=1);
namespace MeinWeimar\Elementor;
use MeinWeimar\ContentTypes;
use MeinWeimar\DetailRenderer;
final class DetailWidget extends \Elementor\Widget_Base
{
public function get_name(): string { return 'meinweimar_detail'; }
public function get_title(): string { return __('MeinWeimar Detail', 'meinweimar-core'); }
public function get_icon(): string { return 'eicon-single-post'; }
public function get_categories(): array { return ['meinweimar']; }
protected function register_controls(): void
{
$this->start_controls_section('content', ['label' => __('Detail', 'meinweimar-core')]);
$type_options = ['current' => __('Aktuellen Inhalt verwenden', 'meinweimar-core')];
foreach (ContentTypes::definitions() as $route => $definition) {
$type_options[$route] = $definition['singular'];
}
$this->add_control('type', [
'label' => __('Detailtyp', 'meinweimar-core'),
'type' => \Elementor\Controls_Manager::SELECT,
'options' => $type_options,
'default' => 'current',
]);
$this->add_control('post_id', [
'label' => __('Inhalt-ID', 'meinweimar-core'),
'type' => \Elementor\Controls_Manager::NUMBER,
'min' => 0,
'default' => 0,
'description' => __('Leer bzw. 0 verwendet den aktuellen Inhalt.', 'meinweimar-core'),
]);
$this->end_controls_section();
}
protected function render(): void
{
$settings = $this->get_settings_for_display();
$post_id = absint($settings['post_id'] ?? 0);
$type = $settings['type'] ?? 'current';
if ('current' === $type) {
$post = get_post($post_id ?: get_the_ID());
$type = $post ? ContentTypes::route_for_post_type($post->post_type) : 'places';
}
echo DetailRenderer::resource_markup($post_id, 'place' === $type ? 'places' : ('event' === $type ? 'events' : $type));
}
}
