vendor/symfony/form/FormInterface.php line 37

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);
  34.     /**
  35.      * Returns the parent form.
  36.      *
  37.      * @return self|null
  38.      */
  39.     public function getParent();
  40.     /**
  41.      * Adds or replaces a child to the form.
  42.      *
  43.      * @param FormInterface|string $child   The FormInterface instance or the name of the child
  44.      * @param string|null          $type    The child's type, if a name was passed
  45.      * @param array                $options The child's options, if a name was passed
  46.      *
  47.      * @return $this
  48.      *
  49.      * @throws Exception\AlreadySubmittedException if the form has already been submitted
  50.      * @throws Exception\LogicException            when trying to add a child to a non-compound form
  51.      * @throws Exception\UnexpectedTypeException   if $child or $type has an unexpected type
  52.      */
  53.     public function add($childstring $type null, array $options = []);
  54.     /**
  55.      * Returns the child with the given name.
  56.      *
  57.      * @return self
  58.      *
  59.      * @throws Exception\OutOfBoundsException if the named child does not exist
  60.      */
  61.     public function get(string $name);
  62.     /**
  63.      * Returns whether a child with the given name exists.
  64.      *
  65.      * @return bool
  66.      */
  67.     public function has(string $name);
  68.     /**
  69.      * Removes a child from the form.
  70.      *
  71.      * @return $this
  72.      *
  73.      * @throws Exception\AlreadySubmittedException if the form has already been submitted
  74.      */
  75.     public function remove(string $name);
  76.     /**
  77.      * Returns all children in this group.
  78.      *
  79.      * @return self[]
  80.      */
  81.     public function all();
  82.     /**
  83.      * Returns the errors of this form.
  84.      *
  85.      * @param bool $deep    Whether to include errors of child forms as well
  86.      * @param bool $flatten Whether to flatten the list of errors in case
  87.      *                      $deep is set to true
  88.      *
  89.      * @return FormErrorIterator
  90.      */
  91.     public function getErrors(bool $deep falsebool $flatten true);
  92.     /**
  93.      * Updates the form with default model data.
  94.      *
  95.      * @param mixed $modelData The data formatted as expected for the underlying object
  96.      *
  97.      * @return $this
  98.      *
  99.      * @throws Exception\AlreadySubmittedException     If the form has already been submitted
  100.      * @throws Exception\LogicException                if the view data does not match the expected type
  101.      *                                                 according to {@link FormConfigInterface::getDataClass}
  102.      * @throws Exception\RuntimeException              If listeners try to call setData in a cycle or if
  103.      *                                                 the form inherits data from its parent
  104.      * @throws Exception\TransformationFailedException if the synchronization failed
  105.      */
  106.     public function setData($modelData);
  107.     /**
  108.      * Returns the model data in the format needed for the underlying object.
  109.      *
  110.      * @return mixed When the field is not submitted, the default data is returned.
  111.      *               When the field is submitted, the default data has been bound
  112.      *               to the submitted view data.
  113.      *
  114.      * @throws Exception\RuntimeException If the form inherits data but has no parent
  115.      */
  116.     public function getData();
  117.     /**
  118.      * Returns the normalized data of the field, used as internal bridge
  119.      * between model data and view data.
  120.      *
  121.      * @return mixed When the field is not submitted, the default data is returned.
  122.      *               When the field is submitted, the normalized submitted data
  123.      *               is returned if the field is synchronized with the view data,
  124.      *               null otherwise.
  125.      *
  126.      * @throws Exception\RuntimeException If the form inherits data but has no parent
  127.      */
  128.     public function getNormData();
  129.     /**
  130.      * Returns the view data of the field.
  131.      *
  132.      * It may be defined by {@link FormConfigInterface::getDataClass}.
  133.      *
  134.      * There are two cases:
  135.      *
  136.      * - When the form is compound the view data is mapped to the children.
  137.      *   Each child will use its mapped data as model data.
  138.      *   It can be an array, an object or null.
  139.      *
  140.      * - When the form is simple its view data is used to be bound
  141.      *   to the submitted data.
  142.      *   It can be a string or an array.
  143.      *
  144.      * In both cases the view data is the actual altered data on submission.
  145.      *
  146.      * @return mixed
  147.      *
  148.      * @throws Exception\RuntimeException If the form inherits data but has no parent
  149.      */
  150.     public function getViewData();
  151.     /**
  152.      * Returns the extra submitted data.
  153.      *
  154.      * @return array The submitted data which do not belong to a child
  155.      */
  156.     public function getExtraData();
  157.     /**
  158.      * Returns the form's configuration.
  159.      *
  160.      * @return FormConfigInterface
  161.      */
  162.     public function getConfig();
  163.     /**
  164.      * Returns whether the form is submitted.
  165.      *
  166.      * @return bool
  167.      */
  168.     public function isSubmitted();
  169.     /**
  170.      * Returns the name by which the form is identified in forms.
  171.      *
  172.      * Only root forms are allowed to have an empty name.
  173.      *
  174.      * @return string
  175.      */
  176.     public function getName();
  177.     /**
  178.      * Returns the property path that the form is mapped to.
  179.      *
  180.      * @return PropertyPathInterface|null
  181.      */
  182.     public function getPropertyPath();
  183.     /**
  184.      * Adds an error to this form.
  185.      *
  186.      * @return $this
  187.      */
  188.     public function addError(FormError $error);
  189.     /**
  190.      * Returns whether the form and all children are valid.
  191.      *
  192.      * @throws Exception\LogicException if the form is not submitted
  193.      *
  194.      * @return bool
  195.      */
  196.     public function isValid();
  197.     /**
  198.      * Returns whether the form is required to be filled out.
  199.      *
  200.      * If the form has a parent and the parent is not required, this method
  201.      * will always return false. Otherwise the value set with setRequired()
  202.      * is returned.
  203.      *
  204.      * @return bool
  205.      */
  206.     public function isRequired();
  207.     /**
  208.      * Returns whether this form is disabled.
  209.      *
  210.      * The content of a disabled form is displayed, but not allowed to be
  211.      * modified. The validation of modified disabled forms should fail.
  212.      *
  213.      * Forms whose parents are disabled are considered disabled regardless of
  214.      * their own state.
  215.      *
  216.      * @return bool
  217.      */
  218.     public function isDisabled();
  219.     /**
  220.      * Returns whether the form is empty.
  221.      *
  222.      * @return bool
  223.      */
  224.     public function isEmpty();
  225.     /**
  226.      * Returns whether the data in the different formats is synchronized.
  227.      *
  228.      * If the data is not synchronized, you can get the transformation failure
  229.      * by calling {@link getTransformationFailure()}.
  230.      *
  231.      * If the form is not submitted, this method always returns true.
  232.      *
  233.      * @return bool
  234.      */
  235.     public function isSynchronized();
  236.     /**
  237.      * Returns the data transformation failure, if any, during submission.
  238.      *
  239.      * @return Exception\TransformationFailedException|null
  240.      */
  241.     public function getTransformationFailure();
  242.     /**
  243.      * Initializes the form tree.
  244.      *
  245.      * Should be called on the root form after constructing the tree.
  246.      *
  247.      * @return $this
  248.      *
  249.      * @throws Exception\RuntimeException If the form is not the root
  250.      */
  251.     public function initialize();
  252.     /**
  253.      * Inspects the given request and calls {@link submit()} if the form was
  254.      * submitted.
  255.      *
  256.      * Internally, the request is forwarded to the configured
  257.      * {@link RequestHandlerInterface} instance, which determines whether to
  258.      * submit the form or not.
  259.      *
  260.      * @param mixed $request The request to handle
  261.      *
  262.      * @return $this
  263.      */
  264.     public function handleRequest($request null);
  265.     /**
  266.      * Submits data to the form.
  267.      *
  268.      * @param string|array|null $submittedData The submitted data
  269.      * @param bool              $clearMissing  Whether to set fields to NULL
  270.      *                                         when they are missing in the
  271.      *                                         submitted data. This argument
  272.      *                                         is only used in compound form
  273.      *
  274.      * @return $this
  275.      *
  276.      * @throws Exception\AlreadySubmittedException if the form has already been submitted
  277.      */
  278.     public function submit($submittedDatabool $clearMissing true);
  279.     /**
  280.      * Returns the root of the form tree.
  281.      *
  282.      * @return self
  283.      */
  284.     public function getRoot();
  285.     /**
  286.      * Returns whether the field is the root of the form tree.
  287.      *
  288.      * @return bool
  289.      */
  290.     public function isRoot();
  291.     /**
  292.      * @return FormView
  293.      */
  294.     public function createView(FormView $parent null);
  295. }