From ac69fdf113f68a2a445246a3e67a268110af7713 Mon Sep 17 00:00:00 2001 From: Jan-Niclas Loosen Date: Sun, 27 Sep 2026 15:55:44 +0200 Subject: [PATCH] feat: Theme Builder conditions only from Divi's list, objects readable Co-Authored-By: Claude Opus 5.5 (1M context) --- .../Divi/ThemeBuilder/TemplateConditions.php | 193 +++++++++++++++ .../ThemeBuilder/TemplateConditionsTest.php | 231 ++++++++++++++++++ 2 files changed, 424 insertions(+) create mode 100644 src/Integrations/Divi/ThemeBuilder/TemplateConditions.php create mode 100644 tests/Unit/Integrations/Divi/ThemeBuilder/TemplateConditionsTest.php diff --git a/src/Integrations/Divi/ThemeBuilder/TemplateConditions.php b/src/Integrations/Divi/ThemeBuilder/TemplateConditions.php new file mode 100644 index 0000000..7e32d6f --- /dev/null +++ b/src/Integrations/Divi/ThemeBuilder/TemplateConditions.php @@ -0,0 +1,193 @@ +|null */ + private ?array $flat = null; + + public function __construct(private DiviThemeBuilder $store) + { + } + + /** + * Checks a client's condition list for field $field: null = no conditions; errors are keyed "" + * (the list itself) or ".". Duplicates are dropped. + * + * @return array{ids: list, errors: array} + */ + public function check(mixed $conditions, string $field): array + { + if ($conditions === null) { + return ['ids' => [], 'errors' => []]; + } + + if (! is_array($conditions) || ! array_is_list($conditions)) { + return ['ids' => [], 'errors' => [$field => 'Liste von Bedingungs-IDs erwartet']]; + } + + if (count($conditions) > self::MAX) { + return ['ids' => [], 'errors' => [$field => sprintf('höchstens %d Bedingungen', self::MAX)]]; + } + + $ids = []; + $errors = []; + foreach ($conditions as $index => $condition) { + $problem = is_string($condition) ? $this->problem($condition) : 'Bedingungs-ID als Text erwartet'; + if ($problem === null) { + $ids[] = (string) $condition; + } else { + $errors[$field . '.' . $index] = $problem; + } + } + + return ['ids' => array_values(array_unique($ids)), 'errors' => $errors]; + } + + /** Divi's label, for an ID with object "