| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace Atk4\Ui; |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | class Message extends View |
| 15: | { |
| 16: | |
| 17: | public $type; |
| 18: | |
| 19: | |
| 20: | public $text; |
| 21: | |
| 22: | |
| 23: | public $icon; |
| 24: | |
| 25: | public $ui = 'message'; |
| 26: | |
| 27: | public $defaultTemplate = 'message.html'; |
| 28: | |
| 29: | #[\Override] |
| 30: | protected function init(): void |
| 31: | { |
| 32: | parent::init(); |
| 33: | |
| 34: | if ($this->text !== false) { |
| 35: | if ($this->text) { |
| 36: | $this->text = Text::addTo($this, [$this->text]); |
| 37: | } else { |
| 38: | $this->text = Text::addTo($this); |
| 39: | } |
| 40: | } |
| 41: | } |
| 42: | |
| 43: | #[\Override] |
| 44: | protected function renderView(): void |
| 45: | { |
| 46: | if ($this->type) { |
| 47: | $this->addClass($this->type); |
| 48: | } |
| 49: | |
| 50: | if ($this->icon) { |
| 51: | if (!is_object($this->icon)) { |
| 52: | $this->icon = new Icon($this->icon); |
| 53: | } |
| 54: | $this->add($this->icon, 'Icon'); |
| 55: | $this->addClass('icon'); |
| 56: | } |
| 57: | |
| 58: | if ($this->content) { |
| 59: | $this->template->set('header', $this->content); |
| 60: | $this->content = null; |
| 61: | } |
| 62: | |
| 63: | parent::renderView(); |
| 64: | } |
| 65: | } |
| 66: | |