class ActionEditForm extends ActionFormBase (View source)

internal  
 

Provides a form for action edit forms.

Traits

Provides dependency injection friendly methods for serialization.

Wrapper methods for the logger factory service.

Provides a trait for the messenger service.

Wrapper methods for the Redirect Destination.

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

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 LoggerChannelFactoryInterface $loggerFactory

The logger channel factory service.

from  LoggerChannelTrait
protected MessengerInterface $messenger

The messenger.

from  MessengerTrait
protected RedirectDestinationInterface $redirectDestination

The redirect destination service.

from  RedirectDestinationTrait
protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected RequestStack $requestStack

The request stack.

from  FormBase
protected ConfigFactoryInterface $configFactory

The config factory.

from  FormBase
protected RouteMatchInterface $routeMatch

The route match.

from  FormBase
protected string $operation

The name of the current operation.

from  EntityForm
protected ModuleHandlerInterface $moduleHandler

The module handler service.

from  EntityForm
protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

from  EntityForm
protected ActionConfigEntityInterface $entity

The action entity.

from  ActionFormBase
protected EntityStorageInterface $storage

The action storage.

from  ActionFormBase

Methods

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

LoggerInterface
getLogger(string $channel)

Gets the logger for a specific channel.

$this
setLoggerFactory(LoggerChannelFactoryInterface $logger_factory)

Injects the logger channel factory.

setMessenger(MessengerInterface $messenger)

Sets the messenger.

messenger()

Gets the messenger.

array
getDestinationArray()

Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.

getRedirectDestination()

Returns the redirect destination service.

$this
setRedirectDestination(RedirectDestinationInterface $redirect_destination)

Sets the redirect destination service.

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

static 
create(ContainerInterface $container)

Instantiates a new instance of this class.

validateForm(array $form, FormStateInterface $form_state)

Form validation handler.

config(string $name)

Retrieves a configuration object.

from  FormBase
configFactory()

Gets the config factory for this form.

from  FormBase
$this
setConfigFactory(ConfigFactoryInterface $config_factory)

Sets the config factory for this form.

from  FormBase
resetConfigFactory()

Resets the configuration factory.

from  FormBase
Request
getRequest()

Gets the request object.

from  FormBase
getRouteMatch()

Gets the route match.

from  FormBase
$this
setRequestStack(RequestStack $request_stack)

Sets the request stack object to use.

from  FormBase
currentUser()

Gets the current user.

from  FormBase
RedirectResponse
redirect(string $route_name, array $route_parameters = [], array $options = [], int $status = 302)

Returns a redirect response object for the specified route.

from  FormBase
LoggerInterface
logger(string $channel)

Gets the logger for a specific channel.

from  FormBase
$this
setOperation(string $operation)

Sets the operation for this form.

string|null
getBaseFormId()

Returns a string identifying the base form.

string
getFormId()

Returns a unique string identifying the form.

array
buildForm(array $form, FormStateInterface $form_state)

Form constructor.

init(FormStateInterface $form_state)

Initialize the form state and the entity before the first form build.

form(array $form, FormStateInterface $form_state)

Gets the actual form array to be built.

processForm($element, FormStateInterface $form_state, $form)

Process callback: assigns weights and hides extra fields.

afterBuild(array $element, FormStateInterface $form_state)

Form element #after_build callback: Updates the entity with submitted data.

actionsElement(array $form, FormStateInterface $form_state)

Returns the action form element for the current entity form.

array
actions(array $form, FormStateInterface $form_state)

Returns an array of supported actions for the current entity form.

submitForm(array $form, FormStateInterface $form_state)

Form submission handler.

int
save(array $form, FormStateInterface $form_state)

Form submission handler for the 'save' action.

buildEntity(array $form, FormStateInterface $form_state)

Builds an updated entity object based upon the submitted form values.

copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state)

Copies top-level form values to entity properties.

getEntity()

Gets the form entity.

$this
setEntity(EntityInterface $entity)

Sets the form entity.

getEntityFromRouteMatch(RouteMatchInterface $route_match, string $entity_type_id)

Determines which entity will be used by this form from a RouteMatch object.

prepareEntity()

Prepares the entity object before the form is built first.

prepareInvokeAll(string $hook, FormStateInterface $form_state)

Invokes the specified prepare hook variant.

string
getOperation()

Gets the operation identifying the form.

$this
setModuleHandler(ModuleHandlerInterface $module_handler)

Sets the module handler for this form.

$this
setEntityTypeManager(EntityTypeManagerInterface $entity_type_manager)

Sets the entity type manager for this form.

__construct(EntityStorageInterface $storage)

Constructs a new action form.

bool
exists(string $id)

Determines if the action already exists.

getPlugin()

Gets the action plugin while ensuring it implements configuration form.

Details

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

protected LoggerInterface getLogger(string $channel)

Gets the logger for a specific channel.

Require the use of injected services: https://www.drupal.org/node/2733703

Parameters

string $channel

The name of the channel. Can be any string, but the general practice is to use the name of the subsystem calling this.

Return Value

LoggerInterface

The logger for the given channel.

$this setLoggerFactory(LoggerChannelFactoryInterface $logger_factory)

Injects the logger channel factory.

Parameters

LoggerChannelFactoryInterface $logger_factory

The logger channel factory service.

Return Value

$this

setMessenger(MessengerInterface $messenger)

Sets the messenger.

Parameters

MessengerInterface $messenger

The messenger.

MessengerInterface messenger()

Gets the messenger.

Return Value

MessengerInterface

The messenger.

protected array getDestinationArray()

Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.

Return Value

array

An associative array containing the key:

  • destination: The value of the current request's 'destination' query parameter, if present. This can be either a relative or absolute URL. However, for security, redirection to external URLs is not performed. If the query parameter isn't present, then the URL of the current request is returned.

See also

RedirectDestinationInterface::getAsArray

protected RedirectDestinationInterface getRedirectDestination()

Returns the redirect destination service.

Return Value

RedirectDestinationInterface

The redirect destination helper.

$this setRedirectDestination(RedirectDestinationInterface $redirect_destination)

Sets the redirect destination service.

Parameters

RedirectDestinationInterface $redirect_destination

The redirect destination service.

Return Value

$this

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

static create(ContainerInterface $container)

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.

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.

protected ImmutableConfig config(string $name)

Retrieves a configuration object.

This is the main entry point to the configuration API. Calling

Parameters

string $name

The name of the configuration object to retrieve. The name corresponds to a configuration file. For @code \Drupal::config('book.admin') @endcode, the config object returned will contain the contents of book.admin configuration file.

Return Value

ImmutableConfig

A configuration object.

protected ConfigFactoryInterface configFactory()

Gets the config factory for this form.

When accessing configuration values, use $this->config(). Only use this when the config factory needs to be manipulated directly.

Return Value

ConfigFactoryInterface

$this setConfigFactory(ConfigFactoryInterface $config_factory)

Sets the config factory for this form.

Parameters

ConfigFactoryInterface $config_factory

The config factory.

Return Value

$this

resetConfigFactory()

Resets the configuration factory.

protected Request getRequest()

Gets the request object.

Return Value

Request

The request object.

protected RouteMatchInterface getRouteMatch()

Gets the route match.

Return Value

RouteMatchInterface

$this setRequestStack(RequestStack $request_stack)

Sets the request stack object to use.

Parameters

RequestStack $request_stack

The request stack object.

Return Value

$this

protected AccountInterface currentUser()

Gets the current user.

Return Value

AccountInterface

The current user.

protected RedirectResponse redirect(string $route_name, array $route_parameters = [], array $options = [], int $status = 302)

Returns a redirect response object for the specified route.

Parameters

string $route_name

The name of the route to which to redirect.

array $route_parameters

(optional) Parameters for the route.

array $options

(optional) An associative array of additional options.

int $status

(optional) The HTTP redirect status code for the redirect. The default is 302 Found.

Return Value

RedirectResponse

A redirect response object that may be returned by the controller.

protected LoggerInterface logger(string $channel)

Gets the logger for a specific channel.

This method exists for backward-compatibility between FormBase and LoggerChannelTrait. Use LoggerChannelTrait::getLogger() instead.

Parameters

string $channel

The name of the channel. Can be any string, but the general practice is to use the name of the subsystem calling this.

Return Value

LoggerInterface

The logger for the given channel.

$this setOperation(string $operation)

Sets the operation for this form.

Parameters

string $operation

The name of the current operation.

Return Value

$this

string|null getBaseFormId()

Returns a string identifying the base form.

Return Value

string|null

The string identifying the base form or NULL if this is not a base form.

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)

Form constructor.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

Return Value

array

The form structure.

protected init(FormStateInterface $form_state)

Initialize the form state and the entity before the first form build.

Parameters

FormStateInterface $form_state

form(array $form, FormStateInterface $form_state)

Gets the actual form array to be built.

Parameters

array $form
FormStateInterface $form_state

processForm($element, FormStateInterface $form_state, $form)

Process callback: assigns weights and hides extra fields.

Parameters

$element
FormStateInterface $form_state
$form

See also

EntityForm::form

afterBuild(array $element, FormStateInterface $form_state)

Form element #after_build callback: Updates the entity with submitted data.

Updates the internal $this->entity object with submitted values when the form is being rebuilt (e.g. submitted via AJAX), so that subsequent processing (e.g. AJAX callbacks) can rely on it.

Parameters

array $element
FormStateInterface $form_state

protected actionsElement(array $form, FormStateInterface $form_state)

Returns the action form element for the current entity form.

Parameters

array $form
FormStateInterface $form_state

protected array actions(array $form, FormStateInterface $form_state)

Returns an array of supported actions for the current entity form.

This function generates a list of Form API elements which represent actions supported by the current entity form.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

Return Value

array

An array of supported Form API action elements keyed by name.

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.

int save(array $form, FormStateInterface $form_state)

Form submission handler for the 'save' action.

Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

Return Value

int

Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

EntityInterface buildEntity(array $form, FormStateInterface $form_state)

Builds an updated entity object based upon the submitted form values.

For building the updated entity object the form's entity is cloned and the submitted form values are copied to entity properties. The form's entity remains unchanged.

Parameters

array $form

A nested array form elements comprising the form.

FormStateInterface $form_state

The current state of the form.

Return Value

EntityInterface

An updated copy of the form's entity object.

protected copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state)

Copies top-level form values to entity properties.

This should not change existing entity properties that are not being edited by this form.

Parameters

EntityInterface $entity

The entity the current form should operate upon.

array $form

A nested array of form elements comprising the form.

FormStateInterface $form_state

The current state of the form.

EntityInterface getEntity()

Gets the form entity.

The form entity which has been used for populating form element defaults.

Return Value

EntityInterface

The current form entity.

$this setEntity(EntityInterface $entity)

Sets the form entity.

Sets the form entity which will be used for populating form element defaults. Usually, the form entity gets updated by \Drupal\Core\Entity\EntityFormInterface::submit(), however this may be used to completely exchange the form entity, e.g. when preparing the rebuild of a multi-step form.

Parameters

EntityInterface $entity

The entity the current form should operate upon.

Return Value

$this

EntityInterface getEntityFromRouteMatch(RouteMatchInterface $route_match, string $entity_type_id)

Determines which entity will be used by this form from a RouteMatch object.

Parameters

RouteMatchInterface $route_match

The route match.

string $entity_type_id

The entity type identifier.

Return Value

EntityInterface

The entity object as determined from the passed-in route match.

protected prepareEntity()

Prepares the entity object before the form is built first.

protected prepareInvokeAll(string $hook, FormStateInterface $form_state)

Invokes the specified prepare hook variant.

Parameters

string $hook

The hook variant name.

FormStateInterface $form_state

The current state of the form.

string getOperation()

Gets the operation identifying the form.

Return Value

string

The name of the operation.

$this setModuleHandler(ModuleHandlerInterface $module_handler)

Sets the module handler for this form.

Parameters

ModuleHandlerInterface $module_handler

The module handler.

Return Value

$this

$this setEntityTypeManager(EntityTypeManagerInterface $entity_type_manager)

Sets the entity type manager for this form.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

Return Value

$this

__construct(EntityStorageInterface $storage)

Constructs a new action form.

Parameters

EntityStorageInterface $storage

The action storage.

bool exists(string $id)

Determines if the action already exists.

Parameters

string $id

The action ID.

Return Value

bool

TRUE if the action exists, FALSE otherwise.

protected ActionInterface|PluginFormInterface|null getPlugin()

Gets the action plugin while ensuring it implements configuration form.

Return Value

ActionInterface|PluginFormInterface|null

The action plugin, or NULL if it does not implement configuration forms.