FormStateInterface.php 32 KB

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