class ViewsForm implements FormInterface, ContainerInjectionInterface (View source)

Provides a base class for single- or multistep view forms.

This class only dispatches logic to the form for the current step. The form is always assumed to be multistep, even if it has only one step (which by default is \Drupal\views\Form\ViewsFormMainForm). That way it is actually possible for modules to have a multistep form if they need to.

Traits

Provides dependency injection friendly methods for serialization.

Properties

protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected ClassResolverInterface $classResolver

The class resolver to get the subform form objects.

protected RequestStack $requestStack

The request stack.

protected UrlGeneratorInterface $urlGenerator

The url generator to generate the form action.

protected string $viewId

The ID of the view.

protected string $viewDisplayId

The ID of the active view's display.

protected string[] $viewArguments

The arguments passed to the active view.

Methods

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(ClassResolverInterface $class_resolver, UrlGeneratorInterface $url_generator, RequestStack $requestStack, string $view_id, string $view_display_id, array $view_args)

Constructs a ViewsForm object.

static 
create(ContainerInterface $container, $view_id = NULL, $view_display_id = NULL, array $view_args = NULL)

Instantiates a new instance of this class.

string
getBaseFormId()

Returns a string for the form's base ID.

string
getFormId()

Returns a unique string identifying the form.

array
buildForm(array $form, FormStateInterface $form_state, ViewExecutable $view = NULL, $output = [])

Form constructor.

validateForm(array $form, FormStateInterface $form_state)

Form validation handler.

submitForm(array $form, FormStateInterface $form_state)

Form submission handler.

getFormObject(FormStateInterface $form_state)

Returns the object used to build the step form.

Details

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(ClassResolverInterface $class_resolver, UrlGeneratorInterface $url_generator, RequestStack $requestStack, string $view_id, string $view_display_id, array $view_args)

Constructs a ViewsForm object.

Parameters

ClassResolverInterface $class_resolver

The class resolver to get the subform form objects.

UrlGeneratorInterface $url_generator

The url generator to generate the form action.

RequestStack $requestStack

The request stack.

string $view_id

The ID of the view.

string $view_display_id

The ID of the active view's display.

array $view_args

The arguments passed to the active view.

static create(ContainerInterface $container, $view_id = NULL, $view_display_id = NULL, array $view_args = NULL)

Instantiates a new instance of this class.

This is a factory method that returns a new instance of this class. The factory should pass any needed dependencies into the constructor of this class, but not the container itself. Every call to this method must return a new instance of this class; that is, it may not implement a singleton.

Parameters

ContainerInterface $container

The service container this instance should use.

$view_id
$view_display_id
array $view_args

string getBaseFormId()

Returns a string for the form's base ID.

Return Value

string

The string identifying the form's base ID.

string getFormId()

Returns a unique string identifying the form.

The returned ID should be a unique string that can be a valid PHP function name, since it's used in hook implementation names such as hook_form_FORM_ID_alter().

Return Value

string

The unique string identifying the form.

array buildForm(array $form, FormStateInterface $form_state, ViewExecutable $view = NULL, $output = [])

Form constructor.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

ViewExecutable $view
$output

Return Value

array

The form structure.

validateForm(array $form, FormStateInterface $form_state)

Form validation handler.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

submitForm(array $form, FormStateInterface $form_state)

Form submission handler.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

protected FormInterface getFormObject(FormStateInterface $form_state)

Returns the object used to build the step form.

Parameters

FormStateInterface $form_state

The form_state of the current form.

Return Value

FormInterface

The form object to use.