- rewrite schemas for posts, tab_posts, oneline_posts, hot_posts, term_cards, term_aggregation, media_cards, combo_info, partners, recent_comments, posts_toc and slider_media_combo to mirror the modern reference modules field by field (options, defaults, dependencies, min/max/step, subheadings) - port reference renderers: hot ranking with TOP badges, category aggregation card, graphic cover cards, partners CSS marquee, combo info cards with auto band palette, recent comment list - rename 分类与标签聚合卡片 to 分类聚合卡片 and restrict it to categories (no tags/topics branch in this project) - drop topics filter fields and the topics query branch; align orderby value domain with supported post meta - add searchable sortable terms admin field type and spinner unit suffix rendering - unify widget pagination and lazy loading on the REST client with the runtime-owned ias reveal trigger; remove the legacy post_ajax_trigger dual path - align section-navs TOC with the reference contract (wznav ids, 3-heading minimum, zib-widget box)
104 lines
2.5 KiB
PHP
104 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace AKSRT\WidgetSystem;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
/**
|
|
* Immutable description of one schema-driven widget.
|
|
*/
|
|
final class WidgetDefinition {
|
|
private string $slug;
|
|
private string $name;
|
|
private string $description;
|
|
private string $group;
|
|
private string $renderer;
|
|
private string $size;
|
|
private array $fields;
|
|
private array $common;
|
|
private array $assets;
|
|
|
|
public function __construct(array $definition) {
|
|
$slug = (string) ($definition['slug'] ?? '');
|
|
if (!preg_match('/^[a-z][a-z0-9_]*$/', $slug)) {
|
|
throw new \InvalidArgumentException('Invalid widget slug: ' . $slug);
|
|
}
|
|
|
|
$name = trim((string) ($definition['name'] ?? ''));
|
|
if ($name === '') {
|
|
throw new \InvalidArgumentException('Widget name is required for ' . $slug);
|
|
}
|
|
|
|
$this->slug = $slug;
|
|
$this->name = $name;
|
|
$this->description = trim((string) ($definition['description'] ?? ''));
|
|
$this->group = (string) ($definition['group'] ?? 'general');
|
|
$this->renderer = (string) ($definition['renderer'] ?? $slug);
|
|
$size = (string) ($definition['size'] ?? 'any');
|
|
$this->size = in_array($size, ['any', 'wide', 'sidebar'], true)
|
|
? $size
|
|
: 'any';
|
|
$this->fields = array_values((array) ($definition['fields'] ?? []));
|
|
$this->common = array_merge(
|
|
[
|
|
'title' => true,
|
|
'affix' => false,
|
|
'visibility' => true,
|
|
'animation' => true,
|
|
'layout' => true,
|
|
],
|
|
(array) ($definition['common'] ?? [])
|
|
);
|
|
$this->assets = array_values(array_unique(array_map('strval', (array) ($definition['assets'] ?? []))));
|
|
}
|
|
|
|
public function slug(): string {
|
|
return $this->slug;
|
|
}
|
|
|
|
public function id_base(): string {
|
|
return 'aksrt_widget_' . $this->slug;
|
|
}
|
|
|
|
public function name(): string {
|
|
return $this->name;
|
|
}
|
|
|
|
public function description(): string {
|
|
return $this->description;
|
|
}
|
|
|
|
public function group(): string {
|
|
return $this->group;
|
|
}
|
|
|
|
public function renderer(): string {
|
|
return $this->renderer;
|
|
}
|
|
|
|
public function size(): string {
|
|
return $this->size;
|
|
}
|
|
|
|
public function common(): array {
|
|
return $this->common;
|
|
}
|
|
|
|
public function assets(): array {
|
|
return $this->assets;
|
|
}
|
|
|
|
public function fields(): array {
|
|
return array_merge(CommonFields::for_definition($this->common), $this->fields);
|
|
}
|
|
|
|
public function defaults(): array {
|
|
return FieldSchema::defaults($this->fields());
|
|
}
|
|
|
|
public function normalize(array $input): array {
|
|
return FieldSchema::normalize($this->fields(), $input);
|
|
}
|
|
}
|
|
|