SubformState
class SubformState extends FormStateDecoratorBase implements SubformStateInterface (View source)
Stores information about the state of a subform.
Traits
Provides methods to manage form state values.
Properties
| protected FormStateInterface | $decoratedFormState | The decorated form state. |
from FormStateDecoratorBase |
| protected array | $parentForm | The parent form. |
|
| protected array | $subform | The subform. |
Methods
Sets the value of the form state.
Sets this form to always be processed.
Determines if this form should always be processed.
Stores the submit and button elements for the form.
Sets that the form was submitted and has been processed and executed.
Determines if the form was submitted and has been processed and executed.
Sets references to details elements to render them within vertical tabs.
Returns references to details elements to render them within vertical tabs.
Sets that this form has a file element.
Sets the limited validation error sections.
Retrieves the limited validation error sections.
Sets the HTTP method to use for the form's submission.
Sets the HTTP method used by the request that is building the form.
Enforces that validation is run.
Prevents the form from redirecting.
Sets that the form should process input.
Determines if the form input will be processed.
Sets that this form was submitted programmatically.
Returns if this form was submitted programmatically.
Sets if this form submission should bypass #access.
Determines if this form submission should bypass #access.
Adds a value to the rebuild info.
Sets the submit handlers.
Gets an arbitrary value from temporary storage.
Sets an arbitrary value in temporary storage.
Determines if a temporary value is present.
Sets the form element that triggered submission.
Gets the form element that triggered submission.
Sets the validate handlers.
Sets that validation has been completed.
Determines if validation has been completed.
Ensures an include file is loaded whenever the form is processed.
Returns an array representation of the cacheable portion of the form state.
Stores the complete form array.
Sets a value to an arbitrary property.
Determines if an arbitrary property is present.
Adds a value to the build info.
Returns the form values as they were submitted by the user.
Sets the form values as though they were submitted by a user.
Returns the submitted and sanitized form values.
Implements \Drupal\Core\Form\FormStateInterface::getValue()
Implements \Drupal\Core\Form\FormStateInterface::setValues()
Implements \Drupal\Core\Form\FormStateInterface::setValue()
Implements \Drupal\Core\Form\FormStateInterface::unsetValue()
Implements \Drupal\Core\Form\FormStateInterface::hasValue()
Implements \Drupal\Core\Form\FormStateInterface::isValueEmpty()
Implements \Drupal\Core\Form\FormStateInterface::setValueForElement()
Sets the redirect for the form.
Gets the value to use for redirecting after the form has been executed.
Files an error against a form element.
Flags an element as having an error.
Clears all errors against all form elements made by self::setErrorByName().
Returns the error message filed against the given form element.
Sets the form to be rebuilt after processing.
Determines if the form should be rebuilt after processing.
Flags the form state as having or not an invalid token.
Converts support notations for a form callback to a valid callable.
Sets the form object that is responsible for building this form.
Returns the form object that is responsible for building this form.
Gets the keys of the form values that will be cleaned.
Sets the keys of the form values that will be cleaned.
Adds a key to the array of form values that will be cleaned.
Removes internal Form API elements and buttons from submitted form values.
Constructs a new instance.
Creates a new instance for a subform.
Gets the subform's parents relative to its parent form.
Gets the complete form state.
Details
$this
setFormState(array $form_state_additions)
Sets the value of the form state.
$this
setAlwaysProcess(bool $always_process = TRUE)
Sets this form to always be processed.
This should only be used on RESTful GET forms that do NOT write data, as this could lead to security issues. It is useful so that searches do not need to have a form_id in their query arguments to trigger the search.
bool
getAlwaysProcess()
Determines if this form should always be processed.
$this
setButtons(array $buttons)
Stores the submit and button elements for the form.
array
getButtons()
Returns the submit and button elements for the form.
$this
setCached(bool $cache = TRUE)
Sets this form to be cached.
bool
isCached()
Determines if the form should be cached.
$this
disableCache()
Prevents the form from being cached.
$this
setExecuted()
Sets that the form was submitted and has been processed and executed.
bool
isExecuted()
Determines if the form was submitted and has been processed and executed.
$this
setGroups(array $groups)
Sets references to details elements to render them within vertical tabs.
array
getGroups()
Returns references to details elements to render them within vertical tabs.
$this
setHasFileElement(bool $has_file_element = TRUE)
Sets that this form has a file element.
bool
hasFileElement()
Returns whether this form has a file element.
$this
setLimitValidationErrors(array|null $limit_validation_errors)
Sets the limited validation error sections.
array|null
getLimitValidationErrors()
Retrieves the limited validation error sections.
$this
setMethod(string $method)
Sets the HTTP method to use for the form's submission.
This is what the form's "method" attribute should be, not necessarily what the current request's HTTP method is. For example, a form can have a method attribute of POST, but the request that initially builds it uses GET.
bool
isMethodType(string $method_type)
Returns the HTTP form method.
$this
setRequestMethod(string $method)
Sets the HTTP method used by the request that is building the form.
$this
setValidationEnforced(bool $must_validate = TRUE)
Enforces that validation is run.
bool
isValidationEnforced()
Checks if validation is enforced.
$this
disableRedirect(bool $no_redirect = TRUE)
Prevents the form from redirecting.
bool
isRedirectDisabled()
Determines if redirecting has been prevented.
$this
setProcessInput(bool $process_input = TRUE)
Sets that the form should process input.
bool
isProcessingInput()
Determines if the form input will be processed.
$this
setProgrammed(bool $programmed = TRUE)
Sets that this form was submitted programmatically.
bool
isProgrammed()
Returns if this form was submitted programmatically.
$this
setProgrammedBypassAccessCheck(bool $programmed_bypass_access_check = TRUE)
Sets if this form submission should bypass #access.
bool
isBypassingProgrammedAccessChecks()
Determines if this form submission should bypass #access.
$this
setRebuildInfo(array $rebuild_info)
Sets the rebuild info.
array
getRebuildInfo()
Gets the rebuild info.
$this
addRebuildInfo(string $property, mixed $value)
Adds a value to the rebuild info.
$this
setStorage(array $storage)
Sets the entire set of arbitrary data.
array
getStorage()
Returns the entire set of arbitrary data.
$this
setSubmitHandlers(array $submit_handlers)
Sets the submit handlers.
array
getSubmitHandlers()
Gets the submit handlers.
$this
setSubmitted()
Sets that the form has been submitted.
bool
isSubmitted()
Determines if the form has been submitted.
$this
setTemporary(array $temporary)
Sets temporary data.
array
getTemporary()
Gets temporary data.
mixed
getTemporaryValue(string|array $key)
Gets an arbitrary value from temporary storage.
$this
setTemporaryValue(string|array $key, mixed $value)
Sets an arbitrary value in temporary storage.
hasTemporaryValue(string $key)
Determines if a temporary value is present.
$this
setTriggeringElement(array|null $triggering_element)
Sets the form element that triggered submission.
array|null
getTriggeringElement()
Gets the form element that triggered submission.
$this
setValidateHandlers(array $validate_handlers)
Sets the validate handlers.
array
getValidateHandlers()
Gets the validate handlers.
$this
setValidationComplete(bool $validation_complete = TRUE)
Sets that validation has been completed.
bool
isValidationComplete()
Determines if validation has been completed.
string|false
loadInclude(string $module, string $type, string|null $name = NULL)
Ensures an include file is loaded whenever the form is processed.
Example:
array
getCacheableArray()
Returns an array representation of the cacheable portion of the form state.
$this
setCompleteForm(array $complete_form)
Stores the complete form array.
array
getCompleteForm()
Returns a reference to the complete form array.
mixed
get(string|array $property)
Gets any arbitrary property.
$this
set(string|array $property, mixed $value)
Sets a value to an arbitrary property.
has(string|array $property)
Determines if an arbitrary property is present.
$this
setBuildInfo(array $build_info)
Sets the build info for the form.
array
getBuildInfo()
Returns the build info for the form.
$this
addBuildInfo(string $property, mixed $value)
Adds a value to the build info.
array
getUserInput()
Returns the form values as they were submitted by the user.
These are raw and unvalidated, so should not be used without a thorough understanding of security implications. In almost all cases, code should use self::getValues() and self::getValue() exclusively.
$this
setUserInput(array $user_input)
Sets the form values as though they were submitted by a user.
array
getValues()
Returns the submitted and sanitized form values.
getValue($key, $default = NULL)
Implements \Drupal\Core\Form\FormStateInterface::getValue()
setValues(array $values)
Implements \Drupal\Core\Form\FormStateInterface::setValues()
setValue($key, $value)
Implements \Drupal\Core\Form\FormStateInterface::setValue()
unsetValue($key)
Implements \Drupal\Core\Form\FormStateInterface::unsetValue()
hasValue($key)
Implements \Drupal\Core\Form\FormStateInterface::hasValue()
isValueEmpty($key)
Implements \Drupal\Core\Form\FormStateInterface::isValueEmpty()
setValueForElement(array $element, $value)
Implements \Drupal\Core\Form\FormStateInterface::setValueForElement()
$this
setResponse(Response $response)
Sets a response for this form.
If a response is set, it will be used during processing and returned directly. The form will not be rebuilt or redirected.
Response|null
getResponse()
Gets a response for this form.
If a response is set, it will be used during processing and returned directly. The form will not be rebuilt or redirected.
$this
setRedirect(string $route_name, array $route_parameters = [], array $options = [])
Sets the redirect for the form.
$this
setRedirectUrl(Url $url)
Sets the redirect URL for the form.
mixed
getRedirect()
Gets the value to use for redirecting after the form has been executed.
static bool
hasAnyErrors()
Determines if any forms have any errors.
$this
setErrorByName(string $name, string $message = '')
Files an error against a form element.
When a validation error is detected, the validator calls this method to indicate which element needs to be changed and provide an error message. This causes the Form API to not execute the form submit handlers, and instead to re-display the form to the user with the corresponding elements rendered with an 'error' CSS class (shown as red by default).
The standard behavior of this method can be changed if a button provides the #limit_validation_errors property. Multistep forms not wanting to validate the whole form can set #limit_validation_errors on buttons to limit validation errors to only certain elements. For example, pressing the "Previous" button in a multistep form should not fire validation errors just because the current step has invalid values. If
limit_validation_errors is set on a clicked button, the button must also
define a #submit property (may be set to an empty array). Any #submit handlers will be executed even if there is invalid input, so extreme care should be taken with respect to any actions taken by them. This is typically not a problem with buttons like "Previous" or "Add more" that do not invoke persistent storage of the submitted form values. Do not use the
limit_validation_errors property on buttons that trigger saving of form
values to the database.
The #limit_validation_errors property is a list of "sections" within $form_state->getValues() that must contain valid values. Each "section" is an array with the ordered set of keys needed to reach that part of $form_state->getValues() (i.e., the #parents property of the element).
Example 1: Allow the "Previous" button to function, regardless of whether any user input is valid.
$this
setError(array $element, string $message = '')
Flags an element as having an error.
clearErrors()
Clears all errors against all form elements made by self::setErrorByName().
string|null
getError(array $element)
Returns the error message filed against the given form element.
Form errors higher up in the form structure override deeper errors as well as errors on the element itself.
array
getErrors()
Returns an associative array of all errors.
$this
setRebuild(bool $rebuild = TRUE)
Sets the form to be rebuilt after processing.
bool
isRebuilding()
Determines if the form should be rebuilt after processing.
$this
setInvalidToken(bool $invalid_token)
Flags the form state as having or not an invalid token.
bool
hasInvalidToken()
Determines if the form has an invalid token.
array|string
prepareCallback(string|array $callback)
Converts support notations for a form callback to a valid callable.
Specifically, supports methods on the form/callback object as strings when they start with ::, for example "::submitForm()".
$this
setFormObject(FormInterface $form_object)
Sets the form object that is responsible for building this form.
FormInterface
getFormObject()
Returns the form object that is responsible for building this form.
array
getCleanValueKeys()
Gets the keys of the form values that will be cleaned.
$this
setCleanValueKeys(array $cleanValueKeys)
Sets the keys of the form values that will be cleaned.
$this
addCleanValueKey($cleanValueKey)
Adds a key to the array of form values that will be cleaned.
$this
cleanValues()
Removes internal Form API elements and buttons from submitted form values.
This function can be used when a module wants to store all submitted form values, for example, by serializing them into a single database column. In such cases, all internal Form API values and all form button elements should not be contained, and this function allows their removal before the module proceeds to storage. Next to button elements, the following internal values are removed by default.
- form_id
- form_token
- form_build_id
- op
protected
__construct(array $subform, array $parent_form, FormStateInterface $parent_form_state)
Constructs a new instance.
static SubformState
createForSubform(array $subform, array $parent_form, FormStateInterface $parent_form_state)
Creates a new instance for a subform.
protected mixed
getParents(string $property)
Gets the subform's parents relative to its parent form.
FormStateInterface
getCompleteFormState()
Gets the complete form state.