b2pweb /
bdf-form
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Bdf\Form; |
||
| 4 | |||
| 5 | use Bdf\Form\Button\ButtonInterface; |
||
| 6 | use Symfony\Component\PropertyAccess\PropertyAccessorInterface; |
||
| 7 | use Symfony\Component\Validator\Validator\ValidatorInterface; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Element which represents the root form |
||
| 11 | * This element contains all the HTTP fields |
||
| 12 | * |
||
| 13 | * @see ElementInterface::root() To get the root instance |
||
| 14 | */ |
||
| 15 | interface RootElementInterface extends ElementInterface |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Get a button by its name |
||
| 19 | * |
||
| 20 | * <code> |
||
| 21 | * $root = $form->root(); |
||
| 22 | * $root->submit($request->post()); |
||
| 23 | * |
||
| 24 | * if ($root->button('continue')->clicked()) { |
||
| 25 | * return $this->redirectTo($this->nextPage()); |
||
| 26 | * } |
||
| 27 | * </code> |
||
| 28 | * |
||
| 29 | * @param non-empty-string $name The button name |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 30 | * |
||
| 31 | * @throws \OutOfBoundsException When the button is not found |
||
| 32 | * |
||
| 33 | * @see RootElementInterface::submitButton() To only get the clicked button |
||
| 34 | */ |
||
| 35 | public function button(string $name): ButtonInterface; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * The button used to submit the form |
||
| 39 | * |
||
| 40 | * <code> |
||
| 41 | * $root = $form->root(); |
||
| 42 | * $root->submit($request->post()); |
||
| 43 | * |
||
| 44 | * if ($btn = $root->submitButton()) { |
||
| 45 | * switch ($btn->name()) { |
||
| 46 | * case self::BTN_SAVE: |
||
| 47 | * return $this->doSave($form->value()); |
||
| 48 | * |
||
| 49 | * case self::BTN_DELETE: |
||
| 50 | * return $this->doDelete($form->value()); |
||
| 51 | * } |
||
| 52 | * } |
||
| 53 | * </code> |
||
| 54 | * |
||
| 55 | * @return ButtonInterface|null The button, or null if not defined |
||
| 56 | * |
||
| 57 | * @see RootElementInterface::button() To get a button by its name |
||
| 58 | */ |
||
| 59 | public function submitButton(): ?ButtonInterface; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Get the Symfony validator |
||
| 63 | * |
||
| 64 | * @return ValidatorInterface |
||
| 65 | * @internal |
||
| 66 | */ |
||
| 67 | public function getValidator(): ValidatorInterface; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Get the Symfony property accessor |
||
| 71 | * |
||
| 72 | * @return PropertyAccessorInterface |
||
| 73 | * @internal |
||
| 74 | */ |
||
| 75 | public function getPropertyAccessor(): PropertyAccessorInterface; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Get the constraint groups related the the button |
||
| 79 | * |
||
| 80 | * @return string[] |
||
| 81 | */ |
||
| 82 | public function constraintGroups(): array; |
||
| 83 | } |
||
| 84 |