FormStateInterface.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  1. <?php
  2. namespace Drupal\Core\Form;
  3. use Drupal\Core\Url;
  4. use Symfony\Component\HttpFoundation\Response;
  5. /**
  6. * Provides an interface for an object containing the current state of a form.
  7. *
  8. * This is passed to all form related code so that the caller can use it to
  9. * examine what in the form changed when the form submission process is
  10. * complete. Furthermore, it may be used to store information related to the
  11. * processed data in the form, which will persist across page requests when the
  12. * 'cache' or 'rebuild' flag is set. See
  13. * \Drupal\Core\Form\FormState::$internalStorage for documentation of the
  14. * available flags.
  15. *
  16. * @see \Drupal\Core\Form\FormBuilderInterface
  17. * @see \Drupal\Core\Form\FormValidatorInterface
  18. * @see \Drupal\Core\Form\FormSubmitterInterface
  19. * @ingroup form_api
  20. */
  21. interface FormStateInterface {
  22. /**
  23. * Returns a reference to the complete form array.
  24. *
  25. * @return array
  26. * The complete form array.
  27. */
  28. public function &getCompleteForm();
  29. /**
  30. * Stores the complete form array.
  31. *
  32. * @param array $complete_form
  33. * The complete form array.
  34. *
  35. * @return $this
  36. */
  37. public function setCompleteForm(array &$complete_form);
  38. /**
  39. * Ensures an include file is loaded whenever the form is processed.
  40. *
  41. * Example:
  42. * @code
  43. * // Load node.admin.inc from Node module.
  44. * $form_state->loadInclude('node', 'inc', 'node.admin');
  45. * @endcode
  46. *
  47. * Use this function instead of module_load_include() from inside a form
  48. * constructor or any form processing logic as it ensures that the include file
  49. * is loaded whenever the form is processed. In contrast to using
  50. * module_load_include() directly, this method makes sure the include file is
  51. * correctly loaded also if the form is cached.
  52. *
  53. * @param string $module
  54. * The module to which the include file belongs.
  55. * @param string $type
  56. * The include file's type (file extension).
  57. * @param string|null $name
  58. * (optional) The base file name (without the $type extension). If omitted,
  59. * $module is used; i.e., resulting in "$module.$type" by default.
  60. *
  61. * @return string|false
  62. * The filepath of the loaded include file, or FALSE if the include file was
  63. * not found or has been loaded already.
  64. *
  65. * @see module_load_include()
  66. */
  67. public function loadInclude($module, $type, $name = NULL);
  68. /**
  69. * Returns an array representation of the cacheable portion of the form state.
  70. *
  71. * @return array
  72. * The cacheable portion of the form state.
  73. */
  74. public function getCacheableArray();
  75. /**
  76. * Sets the value of the form state.
  77. *
  78. * @param array $form_state_additions
  79. * An array of values to add to the form state.
  80. *
  81. * @return $this
  82. */
  83. public function setFormState(array $form_state_additions);
  84. /**
  85. * Sets a response for this form.
  86. *
  87. * If a response is set, it will be used during processing and returned
  88. * directly. The form will not be rebuilt or redirected.
  89. *
  90. * @param \Symfony\Component\HttpFoundation\Response $response
  91. * The response to return.
  92. *
  93. * @return $this
  94. */
  95. public function setResponse(Response $response);
  96. /**
  97. * Gets a response for this form.
  98. *
  99. * If a response is set, it will be used during processing and returned
  100. * directly. The form will not be rebuilt or redirected.
  101. *
  102. * @return \Symfony\Component\HttpFoundation\Response|null
  103. * The response to return, or NULL.
  104. */
  105. public function getResponse();
  106. /**
  107. * Sets the redirect for the form.
  108. *
  109. * @param string $route_name
  110. * The name of the route
  111. * @param array $route_parameters
  112. * (optional) An associative array of parameter names and values.
  113. * @param array $options
  114. * (optional) An associative array of additional options. See
  115. * \Drupal\Core\Url for the available keys.
  116. *
  117. * @return $this
  118. *
  119. * @see \Drupal\Core\Form\FormSubmitterInterface::redirectForm()
  120. */
  121. public function setRedirect($route_name, array $route_parameters = [], array $options = []);
  122. /**
  123. * Sets the redirect URL for the form.
  124. *
  125. * @param \Drupal\Core\Url $url
  126. * The URL to redirect to.
  127. *
  128. * @return $this
  129. *
  130. * @see \Drupal\Core\Form\FormSubmitterInterface::redirectForm()
  131. */
  132. public function setRedirectUrl(Url $url);
  133. /**
  134. * Gets the value to use for redirecting after the form has been executed.
  135. *
  136. * @see \Drupal\Core\Form\FormSubmitterInterface::redirectForm()
  137. *
  138. * @return mixed
  139. * The value will be one of the following:
  140. * - A fully prepared \Symfony\Component\HttpFoundation\RedirectResponse.
  141. * - An instance of \Drupal\Core\Url to use for the redirect.
  142. * - NULL, to signify that no redirect was specified and that the current
  143. * path should be used for the redirect.
  144. * - FALSE, to signify that no redirect should take place.
  145. */
  146. public function getRedirect();
  147. /**
  148. * Sets the entire set of arbitrary data.
  149. *
  150. * @param array $storage
  151. * The entire set of arbitrary data to store for this form.
  152. *
  153. * @return $this
  154. */
  155. public function setStorage(array $storage);
  156. /**
  157. * Returns the entire set of arbitrary data.
  158. *
  159. * @return array
  160. * The entire set of arbitrary data to store for this form.
  161. */
  162. public function &getStorage();
  163. /**
  164. * Gets any arbitrary property.
  165. *
  166. * @param string|array $property
  167. * Properties are often stored as multi-dimensional associative arrays. If
  168. * $property is a string, it will return $storage[$property]. If $property
  169. * is an array, each element of the array will be used as a nested key. If
  170. * $property = ['foo', 'bar'] it will return $storage['foo']['bar'].
  171. *
  172. * @return mixed
  173. * A reference to the value for that property, or NULL if the property does
  174. * not exist.
  175. */
  176. public function &get($property);
  177. /**
  178. * Sets a value to an arbitrary property.
  179. *
  180. * @param string|array $property
  181. * Properties are often stored as multi-dimensional associative arrays. If
  182. * $property is a string, it will use $storage[$property] = $value. If
  183. * $property is an array, each element of the array will be used as a nested
  184. * key. If $property = ['foo', 'bar'] it will use
  185. * $storage['foo']['bar'] = $value.
  186. * @param mixed $value
  187. * The value to set.
  188. *
  189. * @return $this
  190. */
  191. public function set($property, $value);
  192. /**
  193. * Determines if an arbitrary property is present.
  194. *
  195. * @param string $property
  196. * Properties are often stored as multi-dimensional associative arrays. If
  197. * $property is a string, it will return isset($storage[$property]). If
  198. * $property is an array, each element of the array will be used as a nested
  199. * key. If $property = ['foo', 'bar'] it will return
  200. * isset($storage['foo']['bar']).
  201. */
  202. public function has($property);
  203. /**
  204. * Sets the build info for the form.
  205. *
  206. * @param array $build_info
  207. * An array of build info.
  208. *
  209. * @return $this
  210. *
  211. * @see \Drupal\Core\Form\FormState::$build_info
  212. */
  213. public function setBuildInfo(array $build_info);
  214. /**
  215. * Returns the build info for the form.
  216. *
  217. * @return array
  218. * An array of build info.
  219. *
  220. * @see \Drupal\Core\Form\FormState::$build_info
  221. */
  222. public function getBuildInfo();
  223. /**
  224. * Adds a value to the build info.
  225. *
  226. * @param string $property
  227. * The property to use for the value.
  228. * @param mixed $value
  229. * The value to set.
  230. *
  231. * @return $this
  232. */
  233. public function addBuildInfo($property, $value);
  234. /**
  235. * Returns the form values as they were submitted by the user.
  236. *
  237. * These are raw and unvalidated, so should not be used without a thorough
  238. * understanding of security implications. In almost all cases, code should
  239. * use self::getValues() and self::getValue() exclusively.
  240. *
  241. * @return array
  242. * An associative array of values submitted to the form.
  243. */
  244. public function &getUserInput();
  245. /**
  246. * Sets the form values as though they were submitted by a user.
  247. *
  248. * @param array $user_input
  249. * An associative array of raw and unvalidated values.
  250. *
  251. * @return $this
  252. */
  253. public function setUserInput(array $user_input);
  254. /**
  255. * Returns the submitted and sanitized form values.
  256. *
  257. * @return array
  258. * An associative array of values submitted to the form.
  259. */
  260. public function &getValues();
  261. /**
  262. * Returns the submitted form value for a specific key.
  263. *
  264. * @param string|array $key
  265. * Values are stored as a multi-dimensional associative array. If $key is a
  266. * string, it will return $values[$key]. If $key is an array, each element
  267. * of the array will be used as a nested key. If $key = array('foo', 'bar')
  268. * it will return $values['foo']['bar'].
  269. * @param mixed $default
  270. * (optional) The default value if the specified key does not exist.
  271. *
  272. * @return mixed
  273. * The value for the given key, or NULL.
  274. */
  275. public function &getValue($key, $default = NULL);
  276. /**
  277. * Sets the submitted form values.
  278. *
  279. * This should be avoided, since these values have been validated already. Use
  280. * self::setUserInput() instead.
  281. *
  282. * @param array $values
  283. * The multi-dimensional associative array of form values.
  284. *
  285. * @return $this
  286. */
  287. public function setValues(array $values);
  288. /**
  289. * Sets the submitted form value for a specific key.
  290. *
  291. * @param string|array $key
  292. * Values are stored as a multi-dimensional associative array. If $key is a
  293. * string, it will use $values[$key] = $value. If $key is an array, each
  294. * element of the array will be used as a nested key. If
  295. * $key = array('foo', 'bar') it will use $values['foo']['bar'] = $value.
  296. * @param mixed $value
  297. * The value to set.
  298. *
  299. * @return $this
  300. */
  301. public function setValue($key, $value);
  302. /**
  303. * Removes a specific key from the submitted form values.
  304. *
  305. * @param string|array $key
  306. * Values are stored as a multi-dimensional associative array. If $key is a
  307. * string, it will use unset($values[$key]). If $key is an array, each
  308. * element of the array will be used as a nested key. If
  309. * $key = array('foo', 'bar') it will use unset($values['foo']['bar']).
  310. *
  311. * @return $this
  312. */
  313. public function unsetValue($key);
  314. /**
  315. * Determines if a specific key is present in the submitted form values.
  316. *
  317. * @param string|array $key
  318. * Values are stored as a multi-dimensional associative array. If $key is a
  319. * string, it will return isset($values[$key]). If $key is an array, each
  320. * element of the array will be used as a nested key. If
  321. * $key = array('foo', 'bar') it will return isset($values['foo']['bar']).
  322. *
  323. * @return bool
  324. * TRUE if the $key is set, FALSE otherwise.
  325. */
  326. public function hasValue($key);
  327. /**
  328. * Determines if a specific key has a value in the submitted form values.
  329. *
  330. * @param string|array $key
  331. * Values are stored as a multi-dimensional associative array. If $key is a
  332. * string, it will return empty($values[$key]). If $key is an array, each
  333. * element of the array will be used as a nested key. If
  334. * $key = array('foo', 'bar') it will return empty($values['foo']['bar']).
  335. *
  336. * @return bool
  337. * TRUE if the $key has no value, FALSE otherwise.
  338. */
  339. public function isValueEmpty($key);
  340. /**
  341. * Changes submitted form values during form validation.
  342. *
  343. * Use this function to change the submitted value of a form element in a form
  344. * validation function, so that the changed value persists in $form_state
  345. * through to the submission handlers.
  346. *
  347. * Note that form validation functions are specified in the '#validate'
  348. * component of the form array (the value of $form['#validate'] is an array of
  349. * validation function names). If the form does not originate in your module,
  350. * you can implement hook_form_FORM_ID_alter() to add a validation function
  351. * to $form['#validate'].
  352. *
  353. * @param array $element
  354. * The form element that should have its value updated; in most cases you
  355. * can just pass in the element from the $form array, although the only
  356. * component that is actually used is '#parents'. If constructing yourself,
  357. * set $element['#parents'] to be an array giving the path through the form
  358. * array's keys to the element whose value you want to update. For instance,
  359. * if you want to update the value of $form['elem1']['elem2'], which should
  360. * be stored in $form_state->getValue(array('elem1', 'elem2')), you would
  361. * set $element['#parents'] = array('elem1','elem2').
  362. * @param mixed $value
  363. * The new value for the form element.
  364. *
  365. * @return $this
  366. */
  367. public function setValueForElement(array $element, $value);
  368. /**
  369. * Determines if any forms have any errors.
  370. *
  371. * @return bool
  372. * TRUE if any form has any errors, FALSE otherwise.
  373. */
  374. public static function hasAnyErrors();
  375. /**
  376. * Files an error against a form element.
  377. *
  378. * When a validation error is detected, the validator calls this method to
  379. * indicate which element needs to be changed and provide an error message.
  380. * This causes the Form API to not execute the form submit handlers, and
  381. * instead to re-display the form to the user with the corresponding elements
  382. * rendered with an 'error' CSS class (shown as red by default).
  383. *
  384. * The standard behavior of this method can be changed if a button provides
  385. * the #limit_validation_errors property. Multistep forms not wanting to
  386. * validate the whole form can set #limit_validation_errors on buttons to
  387. * limit validation errors to only certain elements. For example, pressing the
  388. * "Previous" button in a multistep form should not fire validation errors
  389. * just because the current step has invalid values. If
  390. * #limit_validation_errors is set on a clicked button, the button must also
  391. * define a #submit property (may be set to an empty array). Any #submit
  392. * handlers will be executed even if there is invalid input, so extreme care
  393. * should be taken with respect to any actions taken by them. This is
  394. * typically not a problem with buttons like "Previous" or "Add more" that do
  395. * not invoke persistent storage of the submitted form values. Do not use the
  396. * #limit_validation_errors property on buttons that trigger saving of form
  397. * values to the database.
  398. *
  399. * The #limit_validation_errors property is a list of "sections" within
  400. * $form_state->getValues() that must contain valid values. Each "section" is
  401. * an array with the ordered set of keys needed to reach that part of
  402. * $form_state->getValues() (i.e., the #parents property of the element).
  403. *
  404. * Example 1: Allow the "Previous" button to function, regardless of whether
  405. * any user input is valid.
  406. *
  407. * @code
  408. * $form['actions']['previous'] = array(
  409. * '#type' => 'submit',
  410. * '#value' => t('Previous'),
  411. * '#limit_validation_errors' => array(), // No validation.
  412. * '#submit' => array('some_submit_function'), // #submit required.
  413. * );
  414. * @endcode
  415. *
  416. * Example 2: Require some, but not all, user input to be valid to process the
  417. * submission of a "Previous" button.
  418. *
  419. * @code
  420. * $form['actions']['previous'] = array(
  421. * '#type' => 'submit',
  422. * '#value' => t('Previous'),
  423. * '#limit_validation_errors' => array(
  424. * // Validate $form_state->getValue('step1').
  425. * array('step1'),
  426. * // Validate $form_state->getValue(array('foo', 'bar')).
  427. * array('foo', 'bar'),
  428. * ),
  429. * '#submit' => array('some_submit_function'), // #submit required.
  430. * );
  431. * @endcode
  432. *
  433. * This will require $form_state->getValue('step1') and everything within it
  434. * (for example, $form_state->getValue(array('step1', 'choice'))) to be valid,
  435. * so calls to self::setErrorByName('step1', $message) or
  436. * self::setErrorByName('step1][choice', $message) will prevent the submit
  437. * handlers from running, and result in the error message being displayed to
  438. * the user. However, calls to self::setErrorByName('step2', $message) and
  439. * self::setErrorByName('step2][groupX][choiceY', $message) will be
  440. * suppressed, resulting in the message not being displayed to the user, and
  441. * the submit handlers will run despite $form_state->getValue('step2') and
  442. * $form_state->getValue(array('step2', 'groupX', 'choiceY')) containing
  443. * invalid values. Errors for an invalid $form_state->getValue('foo') will be
  444. * suppressed, but errors flagging invalid values for
  445. * $form_state->getValue(array('foo', 'bar')) and everything within it will
  446. * be flagged and submission prevented.
  447. *
  448. * Partial form validation is implemented by suppressing errors rather than by
  449. * skipping the input processing and validation steps entirely, because some
  450. * forms have button-level submit handlers that call Drupal API functions that
  451. * assume that certain data exists within $form_state->getValues(), and while
  452. * not doing anything with that data that requires it to be valid, PHP errors
  453. * would be triggered if the input processing and validation steps were fully
  454. * skipped.
  455. *
  456. * @param string $name
  457. * The name of the form element. If the #parents property of your form
  458. * element is array('foo', 'bar', 'baz') then you may set an error on 'foo'
  459. * or 'foo][bar][baz'. Setting an error on 'foo' sets an error for every
  460. * element where the #parents array starts with 'foo'.
  461. * @param string $message
  462. * (optional) The error message to present to the user.
  463. *
  464. * @return $this
  465. */
  466. public function setErrorByName($name, $message = '');
  467. /**
  468. * Flags an element as having an error.
  469. *
  470. * @param array $element
  471. * The form element.
  472. * @param string $message
  473. * (optional) The error message to present to the user.
  474. *
  475. * @return $this
  476. */
  477. public function setError(array &$element, $message = '');
  478. /**
  479. * Clears all errors against all form elements made by self::setErrorByName().
  480. */
  481. public function clearErrors();
  482. /**
  483. * Returns an associative array of all errors.
  484. *
  485. * @return array
  486. * An array of all errors, keyed by the name of the form element.
  487. */
  488. public function getErrors();
  489. /**
  490. * Returns the error message filed against the given form element.
  491. *
  492. * Form errors higher up in the form structure override deeper errors as well
  493. * as errors on the element itself.
  494. *
  495. * @param array $element
  496. * The form element to check for errors.
  497. *
  498. * @return string|null
  499. * Either the error message for this element or NULL if there are no errors.
  500. */
  501. public function getError(array $element);
  502. /**
  503. * Sets the form to be rebuilt after processing.
  504. *
  505. * @param bool $rebuild
  506. * (optional) Whether the form should be rebuilt or not. Defaults to TRUE.
  507. *
  508. * @return $this
  509. */
  510. public function setRebuild($rebuild = TRUE);
  511. /**
  512. * Determines if the form should be rebuilt after processing.
  513. *
  514. * @return bool
  515. * TRUE if the form should be rebuilt, FALSE otherwise.
  516. */
  517. public function isRebuilding();
  518. /**
  519. * Flags the form state as having or not an invalid token.
  520. *
  521. * @param bool $invalid_token
  522. * Whether the form has an invalid token.
  523. *
  524. * @return $this
  525. */
  526. public function setInvalidToken($invalid_token);
  527. /**
  528. * Determines if the form has an invalid token.
  529. *
  530. * @return bool
  531. * TRUE if the form has an invalid token, FALSE otherwise.
  532. */
  533. public function hasInvalidToken();
  534. /**
  535. * Converts support notations for a form callback to a valid callable.
  536. *
  537. * Specifically, supports methods on the form/callback object as strings when
  538. * they start with ::, for example "::submitForm()".
  539. *
  540. * @param string|array $callback
  541. * The callback.
  542. *
  543. * @return array|string
  544. * A valid callable.
  545. */
  546. public function prepareCallback($callback);
  547. /**
  548. * Returns the form object that is responsible for building this form.
  549. *
  550. * @return \Drupal\Core\Form\FormInterface
  551. * The form object.
  552. */
  553. public function getFormObject();
  554. /**
  555. * Sets the form object that is responsible for building this form.
  556. *
  557. * @param \Drupal\Core\Form\FormInterface $form_object
  558. * The form object.
  559. *
  560. * @return $this
  561. */
  562. public function setFormObject(FormInterface $form_object);
  563. /**
  564. * Sets this form to always be processed.
  565. *
  566. * This should only be used on RESTful GET forms that do NOT write data, as
  567. * this could lead to security issues. It is useful so that searches do not
  568. * need to have a form_id in their query arguments to trigger the search.
  569. *
  570. * @param bool $always_process
  571. * TRUE if the form should always be processed, FALSE otherwise.
  572. *
  573. * @return $this
  574. */
  575. public function setAlwaysProcess($always_process = TRUE);
  576. /**
  577. * Determines if this form should always be processed.
  578. *
  579. * @return bool
  580. * TRUE if the form should always be processed, FALSE otherwise.
  581. */
  582. public function getAlwaysProcess();
  583. /**
  584. * Stores the submit and button elements for the form.
  585. *
  586. * @param array $buttons
  587. * The submit and button elements.
  588. *
  589. * @return $this
  590. */
  591. public function setButtons(array $buttons);
  592. /**
  593. * Returns the submit and button elements for the form.
  594. *
  595. * @return array
  596. * The submit and button elements.
  597. */
  598. public function getButtons();
  599. /**
  600. * Sets this form to be cached.
  601. *
  602. * @param bool $cache
  603. * TRUE if the form should be cached, FALSE otherwise.
  604. *
  605. * @return $this
  606. *
  607. * @throws \LogicException
  608. * If the current request is using an HTTP method that must not change
  609. * state (e.g., GET).
  610. */
  611. public function setCached($cache = TRUE);
  612. /**
  613. * Determines if the form should be cached.
  614. *
  615. * @return bool
  616. * TRUE if the form should be cached, FALSE otherwise.
  617. */
  618. public function isCached();
  619. /**
  620. * Prevents the form from being cached.
  621. *
  622. * @return $this
  623. */
  624. public function disableCache();
  625. /**
  626. * Sets that the form was submitted and has been processed and executed.
  627. *
  628. * @return $this
  629. */
  630. public function setExecuted();
  631. /**
  632. * Determines if the form was submitted and has been processed and executed.
  633. *
  634. * @return bool
  635. * TRUE if the form was submitted and has been processed and executed.
  636. */
  637. public function isExecuted();
  638. /**
  639. * Sets references to details elements to render them within vertical tabs.
  640. *
  641. * @param array $groups
  642. * References to details elements to render them within vertical tabs.
  643. *
  644. * @return $this
  645. */
  646. public function setGroups(array $groups);
  647. /**
  648. * Returns references to details elements to render them within vertical tabs.
  649. *
  650. * @return array
  651. */
  652. public function &getGroups();
  653. /**
  654. * Sets that this form has a file element.
  655. *
  656. * @param bool $has_file_element
  657. * Whether this form has a file element.
  658. *
  659. * @return $this
  660. */
  661. public function setHasFileElement($has_file_element = TRUE);
  662. /**
  663. * Returns whether this form has a file element.
  664. *
  665. * @return bool
  666. * Whether this form has a file element.
  667. */
  668. public function hasFileElement();
  669. /**
  670. * Sets the limited validation error sections.
  671. *
  672. * @param array|null $limit_validation_errors
  673. * The limited validation error sections.
  674. *
  675. * @return $this
  676. *
  677. * @see \Drupal\Core\Form\FormState::$limit_validation_errors
  678. */
  679. public function setLimitValidationErrors($limit_validation_errors);
  680. /**
  681. * Retrieves the limited validation error sections.
  682. *
  683. * @return array|null
  684. * The limited validation error sections.
  685. *
  686. * @see \Drupal\Core\Form\FormState::$limit_validation_errors
  687. */
  688. public function getLimitValidationErrors();
  689. /**
  690. * Sets the HTTP method to use for the form's submission.
  691. *
  692. * This is what the form's "method" attribute should be, not necessarily what
  693. * the current request's HTTP method is. For example, a form can have a
  694. * method attribute of POST, but the request that initially builds it uses
  695. * GET.
  696. *
  697. * @param string $method
  698. * Either "GET" or "POST". Other HTTP methods are not valid form submission
  699. * methods.
  700. *
  701. * @see \Drupal\Core\Form\FormState::$method
  702. * @see \Drupal\Core\Form\FormStateInterface::setRequestMethod()
  703. *
  704. * @return $this
  705. */
  706. public function setMethod($method);
  707. /**
  708. * Sets the HTTP method used by the request that is building the form.
  709. *
  710. * @param string $method
  711. * Can be any valid HTTP method, such as GET, POST, HEAD, etc.
  712. *
  713. * @return $this
  714. *
  715. * @see \Drupal\Core\Form\FormStateInterface::setMethod()
  716. */
  717. public function setRequestMethod($method);
  718. /**
  719. * Returns the HTTP form method.
  720. *
  721. * @param string $method_type
  722. * The HTTP form method.
  723. *
  724. * @return bool
  725. * TRUE if the HTTP form method matches.
  726. *
  727. * @see \Drupal\Core\Form\FormState::$method
  728. */
  729. public function isMethodType($method_type);
  730. /**
  731. * Enforces that validation is run.
  732. *
  733. * @param bool $must_validate
  734. * If TRUE, validation will always be run.
  735. *
  736. * @return $this
  737. */
  738. public function setValidationEnforced($must_validate = TRUE);
  739. /**
  740. * Checks if validation is enforced.
  741. *
  742. * @return bool
  743. * If TRUE, validation will always be run.
  744. */
  745. public function isValidationEnforced();
  746. /**
  747. * Prevents the form from redirecting.
  748. *
  749. * @param bool $no_redirect
  750. * If TRUE, the form will not redirect.
  751. *
  752. * @return $this
  753. */
  754. public function disableRedirect($no_redirect = TRUE);
  755. /**
  756. * Determines if redirecting has been prevented.
  757. *
  758. * @return bool
  759. * If TRUE, the form will not redirect.
  760. */
  761. public function isRedirectDisabled();
  762. /**
  763. * Sets that the form should process input.
  764. *
  765. * @param bool $process_input
  766. * If TRUE, the form input will be processed.
  767. *
  768. * @return $this
  769. */
  770. public function setProcessInput($process_input = TRUE);
  771. /**
  772. * Determines if the form input will be processed.
  773. *
  774. * @return bool
  775. * If TRUE, the form input will be processed.
  776. */
  777. public function isProcessingInput();
  778. /**
  779. * Sets that this form was submitted programmatically.
  780. *
  781. * @param bool $programmed
  782. * If TRUE, the form was submitted programmatically.
  783. *
  784. * @return $this
  785. */
  786. public function setProgrammed($programmed = TRUE);
  787. /**
  788. * Returns if this form was submitted programmatically.
  789. *
  790. * @return bool
  791. * If TRUE, the form was submitted programmatically.
  792. */
  793. public function isProgrammed();
  794. /**
  795. * Sets if this form submission should bypass #access.
  796. *
  797. * @param bool $programmed_bypass_access_check
  798. * If TRUE, programmatic form submissions are processed without taking
  799. * #access into account.
  800. *
  801. * @return $this
  802. *
  803. * @see \Drupal\Core\Form\FormState::$programmed_bypass_access_check
  804. */
  805. public function setProgrammedBypassAccessCheck($programmed_bypass_access_check = TRUE);
  806. /**
  807. * Determines if this form submission should bypass #access.
  808. *
  809. * @return bool
  810. *
  811. * @see \Drupal\Core\Form\FormState::$programmed_bypass_access_check
  812. */
  813. public function isBypassingProgrammedAccessChecks();
  814. /**
  815. * Sets the rebuild info.
  816. *
  817. * @param array $rebuild_info
  818. * The rebuild info.
  819. *
  820. * @return $this
  821. *
  822. * @see \Drupal\Core\Form\FormState::$rebuild_info
  823. */
  824. public function setRebuildInfo(array $rebuild_info);
  825. /**
  826. * Gets the rebuild info.
  827. *
  828. * @return array
  829. * The rebuild info.
  830. *
  831. * @see \Drupal\Core\Form\FormState::$rebuild_info
  832. */
  833. public function getRebuildInfo();
  834. /**
  835. * Adds a value to the rebuild info.
  836. *
  837. * @param string $property
  838. * The property to use for the value.
  839. * @param mixed $value
  840. * The value to set.
  841. *
  842. * @return $this
  843. */
  844. public function addRebuildInfo($property, $value);
  845. /**
  846. * Sets the submit handlers.
  847. *
  848. * @param array $submit_handlers
  849. * An array of submit handlers.
  850. *
  851. * @return $this
  852. */
  853. public function setSubmitHandlers(array $submit_handlers);
  854. /**
  855. * Gets the submit handlers.
  856. *
  857. * @return array
  858. * An array of submit handlers.
  859. */
  860. public function getSubmitHandlers();
  861. /**
  862. * Sets that the form has been submitted.
  863. *
  864. * @return $this
  865. */
  866. public function setSubmitted();
  867. /**
  868. * Determines if the form has been submitted.
  869. *
  870. * @return bool
  871. * TRUE if the form has been submitted, FALSE otherwise.
  872. */
  873. public function isSubmitted();
  874. /**
  875. * Sets temporary data.
  876. *
  877. * @param array $temporary
  878. * Temporary data accessible during the current page request only.
  879. *
  880. * @return $this
  881. */
  882. public function setTemporary(array $temporary);
  883. /**
  884. * Gets temporary data.
  885. *
  886. * @return array
  887. * Temporary data accessible during the current page request only.
  888. */
  889. public function getTemporary();
  890. /**
  891. * Gets an arbitrary value from temporary storage.
  892. *
  893. * @param string|array $key
  894. * Properties are often stored as multi-dimensional associative arrays. If
  895. * $key is a string, it will return $temporary[$key]. If $key is an array,
  896. * each element of the array will be used as a nested key. If
  897. * $key = ['foo', 'bar'] it will return $temporary['foo']['bar'].
  898. *
  899. * @return mixed
  900. * A reference to the value for that key, or NULL if the property does
  901. * not exist.
  902. */
  903. public function &getTemporaryValue($key);
  904. /**
  905. * Sets an arbitrary value in temporary storage.
  906. *
  907. * @param string|array $key
  908. * Properties are often stored as multi-dimensional associative arrays. If
  909. * $key is a string, it will use $temporary[$key] = $value. If $key is an
  910. * array, each element of the array will be used as a nested key. If
  911. * $key = ['foo', 'bar'] it will use $temporary['foo']['bar'] = $value.
  912. * @param mixed $value
  913. * The value to set.
  914. *
  915. * @return $this
  916. */
  917. public function setTemporaryValue($key, $value);
  918. /**
  919. * Determines if a temporary value is present.
  920. *
  921. * @param string $key
  922. * Properties are often stored as multi-dimensional associative arrays. If
  923. * $key is a string, it will return isset($temporary[$key]). If $key is an
  924. * array, each element of the array will be used as a nested key. If
  925. * $key = ['foo', 'bar'] it will return isset($temporary['foo']['bar']).
  926. */
  927. public function hasTemporaryValue($key);
  928. /**
  929. * Sets the form element that triggered submission.
  930. *
  931. * @param array|null $triggering_element
  932. * The form element that triggered submission, of NULL if there is none.
  933. *
  934. * @return $this
  935. */
  936. public function setTriggeringElement($triggering_element);
  937. /**
  938. * Gets the form element that triggered submission.
  939. *
  940. * @return array|null
  941. * The form element that triggered submission, of NULL if there is none.
  942. */
  943. public function &getTriggeringElement();
  944. /**
  945. * Sets the validate handlers.
  946. *
  947. * @param array $validate_handlers
  948. * An array of validate handlers.
  949. *
  950. * @return $this
  951. */
  952. public function setValidateHandlers(array $validate_handlers);
  953. /**
  954. * Gets the validate handlers.
  955. *
  956. * @return array
  957. * An array of validate handlers.
  958. */
  959. public function getValidateHandlers();
  960. /**
  961. * Sets that validation has been completed.
  962. *
  963. * @param bool $validation_complete
  964. * TRUE if validation is complete, FALSE otherwise.
  965. *
  966. * @return $this
  967. */
  968. public function setValidationComplete($validation_complete = TRUE);
  969. /**
  970. * Determines if validation has been completed.
  971. *
  972. * @return bool
  973. * TRUE if validation is complete, FALSE otherwise.
  974. */
  975. public function isValidationComplete();
  976. /**
  977. * Gets the keys of the form values that will be cleaned.
  978. *
  979. * @return array
  980. * An array of form value keys to be cleaned.
  981. */
  982. public function getCleanValueKeys();
  983. /**
  984. * Sets the keys of the form values that will be cleaned.
  985. *
  986. * @param array $keys
  987. * An array of form value keys to be cleaned.
  988. *
  989. * @return $this
  990. */
  991. public function setCleanValueKeys(array $keys);
  992. /**
  993. * Adds a key to the array of form values that will be cleaned.
  994. *
  995. * @param string $key
  996. * The form value key to be cleaned.
  997. *
  998. * @return $this
  999. */
  1000. public function addCleanValueKey($key);
  1001. /**
  1002. * Removes internal Form API elements and buttons from submitted form values.
  1003. *
  1004. * This function can be used when a module wants to store all submitted form
  1005. * values, for example, by serializing them into a single database column. In
  1006. * such cases, all internal Form API values and all form button elements
  1007. * should not be contained, and this function allows their removal before the
  1008. * module proceeds to storage. Next to button elements, the following internal
  1009. * values are removed by default.
  1010. * - form_id
  1011. * - form_token
  1012. * - form_build_id
  1013. * - op
  1014. *
  1015. * @return $this
  1016. */
  1017. public function cleanValues();
  1018. }