| 1 |
<?php |
| 2 |
|
| 3 |
// SPDX-FileCopyrightText: 2026 Icinga GmbH <https://icinga.com> |
| 4 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
|
| 6 |
namespace ipl\Web\Compat; |
| 7 |
|
| 8 |
use ipl\Html\Attributes; |
| 9 |
use ipl\Html\BaseHtmlElement; |
| 10 |
use ipl\Html\HtmlElement; |
| 11 |
use ipl\Html\Text; |
| 12 |
use ipl\Html\ValidHtml; |
| 13 |
use ipl\Web\Widget\Icon; |
| 14 |
|
| 15 |
/** |
| 16 |
* This is an element that integrates {@see ValidHtml} into an IPL Web {@see CompatForm}. |
| 17 |
* |
| 18 |
* The html will be rendered as follows: |
| 19 |
* <pre> |
| 20 |
* <div class='control-group'> |
| 21 |
* <div class='control-label-group'> |
| 22 |
* <!-- if label is set --> |
| 23 |
* <label>$this->label</label> |
| 24 |
* </div> |
| 25 |
* <div class='display-form-element'> |
| 26 |
* $this->content |
| 27 |
* </div> |
| 28 |
* <!-- if description is set --> |
| 29 |
* <i class="icon fa-info-circle control-info fa" role="image" title="$this->description"></i> |
| 30 |
* </div> |
| 31 |
* </pre> |
| 32 |
*/ |
| 33 |
class DisplayFormElement extends BaseHtmlElement |
| 34 |
{ |
| 35 |
protected $tag = 'div'; |
| 36 |
|
| 37 |
protected $defaultAttributes = ['class' => 'control-group']; |
| 38 |
|
| 39 |
/** |
| 40 |
* @param ValidHtml $content The element to add to the form |
| 41 |
* @param ?string $label The label to render in the control-label-group element |
| 42 |
* @param ?string $description The description to show for the element |
| 43 |
*/ |
| 44 |
public function __construct( |
| 45 |
protected ValidHtml $content, |
| 46 |
protected ?string $label = null, |
| 47 |
protected ?string $description = null |
| 48 |
) { |
| 49 |
} |
| 50 |
|
| 51 |
protected function assemble(): void |
| 52 |
{ |
| 53 |
$this->addHtml( |
| 54 |
HtmlElement::create( |
| 55 |
'div', |
| 56 |
Attributes::create(['class' => 'control-label-group']), |
| 57 |
$this->label !== null ? HtmlElement::create('label', null, Text::create($this->label)) : null |
| 58 |
) |
| 59 |
); |
| 60 |
$this->addHtml( |
| 61 |
HtmlElement::create('div', Attributes::create(['class' => 'display-form-element']), $this->content) |
| 62 |
); |
| 63 |
if ($this->description !== null) { |
| 64 |
$this->addHtml( |
| 65 |
new Icon('info-circle', Attributes::create(['class' => 'control-info', 'title' => $this->description])) |
| 66 |
); |
| 67 |
} |
| 68 |
} |
| 69 |
} |