| 1 |
<?php |
| 2 |
|
| 3 |
namespace ipl\Html\Contract; |
| 4 |
|
| 5 |
/** |
| 6 |
* Representation of form element decorator |
| 7 |
*/ |
| 8 |
interface FormElementDecoration |
| 9 |
{ |
| 10 |
/** |
| 11 |
* Decorate the given form element |
| 12 |
* |
| 13 |
* A decorator can create HTML elements and apply attributes to the given $formElement element. |
| 14 |
* Only the elements added to {@see DecorationResult} are rendered in the end. |
| 15 |
* |
| 16 |
* The element can be added to the {@see DecorationResult} using the following three methods: |
| 17 |
* - {@see DecorationResult::append()} will add the given HTML to the end of the result |
| 18 |
* - {@see DecorationResult::prepend()} will prepend the given HTML to the beginning of the result |
| 19 |
* - {@see DecorationResult::wrap()} will set the given HTML as the container of the result |
| 20 |
* |
| 21 |
* **Reference implementation:** |
| 22 |
* |
| 23 |
*``` |
| 24 |
* |
| 25 |
* public function decorateFormElement(DecorationResult $result, FormElement $formElement): void |
| 26 |
* { |
| 27 |
* $description = $formElement->getDescription(); |
| 28 |
* |
| 29 |
* if ($description === null) { |
| 30 |
* return; |
| 31 |
* } |
| 32 |
* |
| 33 |
* $result->append(new HtmlElement('p', null, new Text($description))); |
| 34 |
* } |
| 35 |
* ``` |
| 36 |
* |
| 37 |
* @param DecorationResult $result |
| 38 |
* @param FormElement $formElement |
| 39 |
* |
| 40 |
* @return void |
| 41 |
*/ |
| 42 |
public function decorateFormElement(DecorationResult $result, FormElement $formElement): void; |
| 43 |
} |