| 1 |
<?php |
| 2 |
|
| 3 |
namespace ipl\Html\Contract; |
| 4 |
|
| 5 |
/** |
| 6 |
* Representation of a form decorator |
| 7 |
*/ |
| 8 |
interface FormDecoration |
| 9 |
{ |
| 10 |
/** |
| 11 |
* Decorate the given form |
| 12 |
* |
| 13 |
* A decorator can create HTML elements and apply attributes to the given form. |
| 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 element to the end of the result. |
| 18 |
* - {@see DecorationResult::prepend()} will add the element to the beginning of the result. |
| 19 |
* - {@see DecorationResult::wrap()} will wrap the result with the given element. |
| 20 |
* |
| 21 |
* **Reference implementation:** |
| 22 |
* |
| 23 |
*``` |
| 24 |
* public function decorateForm(DecorationResult $result, Form $form): void |
| 25 |
* { |
| 26 |
* if (! $form->hasChanges()) { |
| 27 |
* return; |
| 28 |
* } |
| 29 |
* |
| 30 |
* $result->prepend(new HtmlElement('p', null, Text::create('You have unsaved changes.'))); |
| 31 |
* } |
| 32 |
* ``` |
| 33 |
* |
| 34 |
* @param DecorationResult $result |
| 35 |
* @param Form $form |
| 36 |
* |
| 37 |
* @return void |
| 38 |
*/ |
| 39 |
public function decorateForm(DecorationResult $result, Form $form): void; |
| 40 |
} |