1<?php
2
3
4namespace ComboStrap;
5
6
7class Display
8{
9
10    public const DISPLAY = "display";
11    public const DISPLAY_NONE_VALUE = "none";
12    public const DISPLAY_NONE_IF_EMPTY_VALUE = "none-if-empty";
13
14    public static function processDisplay(TagAttributes &$tagAttributes)
15    {
16
17        $display = $tagAttributes->getValueAndRemove(self::DISPLAY);
18        if ($display !== null) {
19            $value = strtolower($display);
20            switch ($value) {
21                case self::DISPLAY_NONE_VALUE:
22                    $tagAttributes->addStyleDeclarationIfNotSet("display", "none");
23                    return;
24                case self::DISPLAY_NONE_IF_EMPTY_VALUE:
25                    try {
26                        $id = $tagAttributes->getId();
27                    } catch (ExceptionNotFound $e) {
28                        $id = $tagAttributes->getDefaultGeneratedId();
29                        $tagAttributes->setId($id);
30                    }
31                    $css = "#$id:empty {  display: none; }";
32                    ExecutionContext::getActualOrCreateFromEnv()
33                        ->getSnippetSystem()
34                        ->attachCssInternalStyleSheet("display-none-if-empty-$id", $css);
35                    return;
36
37            }
38        }
39    }
40
41}
42