vendor/symfony/form/FormInterface.php line 57

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Form;
  11. use Symfony\Component\PropertyAccess\PropertyPathInterface;
  12. /**
  13.  * A form group bundling multiple forms in a hierarchical structure.
  14.  *
  15.  * @author Bernhard Schussek <bschussek@gmail.com>
  16.  *
  17.  * @extends \ArrayAccess<string, FormInterface>
  18.  * @extends \Traversable<string, FormInterface>
  19.  */
  20. interface FormInterface extends \ArrayAccess\Traversable\Countable
  21. {
  22.     /**
  23.      * Sets the parent form.
  24.      *
  25.      * @param FormInterface|null $parent The parent form or null if it's the root
  26.      *
  27.      * @return $this
  28.      *
  29.      * @throws Exception\AlreadySubmittedException if the form has already been submitted
  30.      * @throws Exception\LogicException            when trying to set a parent for a form with
  31.      *                                             an empty name
  32.      */
  33.     public function setParent(self $parent null): static;
  34.     /**
  35.      * Returns the parent form.
  36.      */
  37.     public function getParent(): ?self;
  38.     /**
  39.      * Adds or replaces a child to the form.
  40.      *
  41.      * @param FormInterface|string $child   The FormInterface instance or the name of the child
  42.      * @param string|null          $type    The child's type, if a name was passed
  43.      * @param array                $options The child's options, if a name was passed
  44.      *
  45.      * @return $this
  46.      *
  47.      * @throws Exception\AlreadySubmittedException if the form has already been submitted
  48.      * @throws Exception\LogicException            when trying to add a child to a non-compound form
  49.      * @throws Exception\UnexpectedTypeException   if $child or $type has an unexpected type
  50.      */
  51.     public function add(self|string $childstring $type null, array $options = []): static;
  52.     /**
  53.      * Returns the child with the given name.
  54.      *
  55.      * @throws Exception\OutOfBoundsException if the named child does not exist
  56.      */
  57.     public function get(string $name): self;
  58.     /**
  59.      * Returns whether a child with the given name exists.
  60.      */
  61.     public function has(string $name): bool;
  62.     /**
  63.      * Removes a child from the form.
  64.      *
  65.      * @return $this
  66.      *
  67.      * @throws Exception\AlreadySubmittedException if the form has already been submitted
  68.      */
  69.     public function remove(string $name): static;
  70.     /**
  71.      * Returns all children in this group.
  72.      *
  73.      * @return self[]
  74.      */
  75.     public function all(): array;
  76.     /**
  77.      * Returns the errors of this form.
  78.      *
  79.      * @param bool $deep    Whether to include errors of child forms as well
  80.      * @param bool $flatten Whether to flatten the list of errors in case
  81.      *                      $deep is set to true
  82.      */
  83.     public function getErrors(bool $deep falsebool $flatten true): FormErrorIterator;
  84.     /**
  85.      * Updates the form with default model data.
  86.      *
  87.      * @param mixed $modelData The data formatted as expected for the underlying object
  88.      *
  89.      * @return $this
  90.      *
  91.      * @throws Exception\AlreadySubmittedException     If the form has already been submitted
  92.      * @throws Exception\LogicException                if the view data does not match the expected type
  93.      *                                                 according to {@link FormConfigInterface::getDataClass}
  94.      * @throws Exception\RuntimeException              If listeners try to call setData in a cycle or if
  95.      *                                                 the form inherits data from its parent
  96.      * @throws Exception\TransformationFailedException if the synchronization failed
  97.      */
  98.     public function setData(mixed $modelData): static;
  99.     /**
  100.      * Returns the model data in the format needed for the underlying object.
  101.      *
  102.      * @return mixed When the field is not submitted, the default data is returned.
  103.      *               When the field is submitted, the default data has been bound
  104.      *               to the submitted view data.
  105.      *
  106.      * @throws Exception\RuntimeException If the form inherits data but has no parent
  107.      */
  108.     public function getData(): mixed;
  109.     /**
  110.      * Returns the normalized data of the field, used as internal bridge
  111.      * between model data and view data.
  112.      *
  113.      * @return mixed When the field is not submitted, the default data is returned.
  114.      *               When the field is submitted, the normalized submitted data
  115.      *               is returned if the field is synchronized with the view data,
  116.      *               null otherwise.
  117.      *
  118.      * @throws Exception\RuntimeException If the form inherits data but has no parent
  119.      */
  120.     public function getNormData(): mixed;
  121.     /**
  122.      * Returns the view data of the field.
  123.      *
  124.      * It may be defined by {@link FormConfigInterface::getDataClass}.
  125.      *
  126.      * There are two cases:
  127.      *
  128.      * - When the form is compound the view data is mapped to the children.
  129.      *   Each child will use its mapped data as model data.
  130.      *   It can be an array, an object or null.
  131.      *
  132.      * - When the form is simple its view data is used to be bound
  133.      *   to the submitted data.
  134.      *   It can be a string or an array.
  135.      *
  136.      * In both cases the view data is the actual altered data on submission.
  137.      *
  138.      * @throws Exception\RuntimeException If the form inherits data but has no parent
  139.      */
  140.     public function getViewData(): mixed;
  141.     /**
  142.      * Returns the extra submitted data.
  143.      *
  144.      * @return array The submitted data which do not belong to a child
  145.      */
  146.     public function getExtraData(): array;
  147.     /**
  148.      * Returns the form's configuration.
  149.      */
  150.     public function getConfig(): FormConfigInterface;
  151.     /**
  152.      * Returns whether the form is submitted.
  153.      */
  154.     public function isSubmitted(): bool;
  155.     /**
  156.      * Returns the name by which the form is identified in forms.
  157.      *
  158.      * Only root forms are allowed to have an empty name.
  159.      */
  160.     public function getName(): string;
  161.     /**
  162.      * Returns the property path that the form is mapped to.
  163.      */
  164.     public function getPropertyPath(): ?PropertyPathInterface;
  165.     /**
  166.      * Adds an error to this form.
  167.      *
  168.      * @return $this
  169.      */
  170.     public function addError(FormError $error): static;
  171.     /**
  172.      * Returns whether the form and all children are valid.
  173.      *
  174.      * @throws Exception\LogicException if the form is not submitted
  175.      */
  176.     public function isValid(): bool;
  177.     /**
  178.      * Returns whether the form is required to be filled out.
  179.      *
  180.      * If the form has a parent and the parent is not required, this method
  181.      * will always return false. Otherwise the value set with setRequired()
  182.      * is returned.
  183.      */
  184.     public function isRequired(): bool;
  185.     /**
  186.      * Returns whether this form is disabled.
  187.      *
  188.      * The content of a disabled form is displayed, but not allowed to be
  189.      * modified. The validation of modified disabled forms should fail.
  190.      *
  191.      * Forms whose parents are disabled are considered disabled regardless of
  192.      * their own state.
  193.      */
  194.     public function isDisabled(): bool;
  195.     /**
  196.      * Returns whether the form is empty.
  197.      */
  198.     public function isEmpty(): bool;
  199.     /**
  200.      * Returns whether the data in the different formats is synchronized.
  201.      *
  202.      * If the data is not synchronized, you can get the transformation failure
  203.      * by calling {@link getTransformationFailure()}.
  204.      *
  205.      * If the form is not submitted, this method always returns true.
  206.      */
  207.     public function isSynchronized(): bool;
  208.     /**
  209.      * Returns the data transformation failure, if any, during submission.
  210.      */
  211.     public function getTransformationFailure(): ?Exception\TransformationFailedException;
  212.     /**
  213.      * Initializes the form tree.
  214.      *
  215.      * Should be called on the root form after constructing the tree.
  216.      *
  217.      * @return $this
  218.      *
  219.      * @throws Exception\RuntimeException If the form is not the root
  220.      */
  221.     public function initialize(): static;
  222.     /**
  223.      * Inspects the given request and calls {@link submit()} if the form was
  224.      * submitted.
  225.      *
  226.      * Internally, the request is forwarded to the configured
  227.      * {@link RequestHandlerInterface} instance, which determines whether to
  228.      * submit the form or not.
  229.      *
  230.      * @return $this
  231.      */
  232.     public function handleRequest(mixed $request null): static;
  233.     /**
  234.      * Submits data to the form.
  235.      *
  236.      * @param string|array|null $submittedData The submitted data
  237.      * @param bool              $clearMissing  Whether to set fields to NULL
  238.      *                                         when they are missing in the
  239.      *                                         submitted data. This argument
  240.      *                                         is only used in compound form
  241.      *
  242.      * @return $this
  243.      *
  244.      * @throws Exception\AlreadySubmittedException if the form has already been submitted
  245.      */
  246.     public function submit(string|array|null $submittedDatabool $clearMissing true): static;
  247.     /**
  248.      * Returns the root of the form tree.
  249.      */
  250.     public function getRoot(): self;
  251.     /**
  252.      * Returns whether the field is the root of the form tree.
  253.      */
  254.     public function isRoot(): bool;
  255.     public function createView(FormView $parent null): FormView;
  256. }