abstract class ConfigureBlockFormBase extends FormBase implements BaseFormIdInterface (View source)

internal  Form classes are internal.
 

Provides a base form for configuring a block.

Traits

Provides a helper to for submitting an AJAX form.

Handles context assignments for context-aware plugins.

Provides a wrapper around getting contexts from a section storage object.

Provides AJAX responses to rebuild the Layout Builder.

Provides a helper to determine if the current request is via AJAX.

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 ContextRepositoryInterface $contextRepository

The context repository.

from  LayoutBuilderContextTrait
protected BlockPluginInterface $block

The plugin being configured.

protected LayoutTempstoreRepositoryInterface $layoutTempstoreRepository

The layout tempstore repository.

protected BlockManagerInterface $blockManager

The block manager.

protected UuidInterface $uuidGenerator

The UUID generator.

protected PluginFormFactoryInterface $pluginFormFactory

The plugin form manager.

protected int $delta

The field delta.

protected string $region

The current region.

protected string $uuid

The UUID of the component.

protected SectionStorageInterface $sectionStorage

The section storage.

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
bool
isAjax()

Determines if the current request is via AJAX.

string|null
getRequestWrapperFormat()

Gets the wrapper format of the current request.

ajaxSubmit(array $form, FormStateInterface $form_state)

Submit form dialog #ajax callback.

successfulAjaxSubmit(array $form, FormStateInterface $form_state)

{@inheritdoc}

array
addContextAssignmentElement(ContextAwarePluginInterface $plugin, array $contexts)

Builds a form element for assigning a context to a given slot.

contextRepository()

Gets the context repository service.

getAvailableContexts(SectionStorageInterface $section_storage) deprecated

Provides all available contexts, both global and section_storage-specific.

array
getPopulatedContexts(SectionStorageInterface $section_storage)

Returns all populated contexts, both global and section-storage-specific.

rebuildAndClose(SectionStorageInterface $section_storage)

Rebuilds the layout.

rebuildLayout(SectionStorageInterface $section_storage)

Rebuilds the layout.

__construct(LayoutTempstoreRepositoryInterface $layout_tempstore_repository, ContextRepositoryInterface $context_repository, BlockManagerInterface $block_manager, UuidInterface $uuid, PluginFormFactoryInterface $plugin_form_manager)

Constructs a new block form.

string|null
getBaseFormId()

Returns a string identifying the base form.

array
doBuildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, int $delta = NULL, SectionComponent $component = NULL)

Builds the form for the block.

string
submitLabel()

Returns the label for the submit button.

submitForm(array $form, FormStateInterface $form_state)

Form submission handler.

getPluginForm(BlockPluginInterface $block)

Retrieves the plugin form for a given block.

getSectionStorage()

Retrieves the section storage object.

getCurrentSection()

Retrieves the current layout section being edited by the form.

getCurrentComponent()

Retrieves the current component being edited by the 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.

protected bool isAjax()

Determines if the current request is via AJAX.

Return Value

bool

TRUE if the current request is via AJAX, FALSE otherwise.

protected string|null getRequestWrapperFormat()

Gets the wrapper format of the current request.

Return Value

string|null

The wrapper format. NULL if the wrapper format is not set.

AjaxResponse ajaxSubmit(array $form, FormStateInterface $form_state)

Submit form dialog #ajax callback.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

Return Value

AjaxResponse

An AJAX response that display validation error messages or represents a successful submission.

protected successfulAjaxSubmit(array $form, FormStateInterface $form_state)

{@inheritdoc}

Parameters

array $form
FormStateInterface $form_state

protected ContextHandlerInterface contextHandler()

Wraps the context handler.

protected array addContextAssignmentElement(ContextAwarePluginInterface $plugin, array $contexts)

Builds a form element for assigning a context to a given slot.

Parameters

ContextAwarePluginInterface $plugin

The context-aware plugin.

array $contexts

An array of contexts.

Return Value

array

A form element for assigning context.

protected ContextRepositoryInterface contextRepository()

Gets the context repository service.

Return Value

ContextRepositoryInterface

The context repository service.

protected ContextInterface[] getAvailableContexts(SectionStorageInterface $section_storage) deprecated

deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\layout_builder\Context\LayoutBuilderContextTrait::getPopulatedContexts() instead.

Provides all available contexts, both global and section_storage-specific.

Parameters

SectionStorageInterface $section_storage

The section storage.

Return Value

ContextInterface[]

The array of context objects.

See also

https://www.drupal.org/node/3195121

protected array getPopulatedContexts(SectionStorageInterface $section_storage)

Returns all populated contexts, both global and section-storage-specific.

Parameters

SectionStorageInterface $section_storage

The section storage.

Return Value

array

The array of context objects.

protected AjaxResponse rebuildAndClose(SectionStorageInterface $section_storage)

Rebuilds the layout.

Parameters

SectionStorageInterface $section_storage

The section storage.

Return Value

AjaxResponse

An AJAX response to either rebuild the layout and close the dialog, or reload the page.

protected AjaxResponse rebuildLayout(SectionStorageInterface $section_storage)

Rebuilds the layout.

Parameters

SectionStorageInterface $section_storage

The section storage.

Return Value

AjaxResponse

An AJAX response to either rebuild the layout and close the dialog, or reload the page.

__construct(LayoutTempstoreRepositoryInterface $layout_tempstore_repository, ContextRepositoryInterface $context_repository, BlockManagerInterface $block_manager, UuidInterface $uuid, PluginFormFactoryInterface $plugin_form_manager)

Constructs a new block form.

Parameters

LayoutTempstoreRepositoryInterface $layout_tempstore_repository

The layout tempstore repository.

ContextRepositoryInterface $context_repository

The context repository.

BlockManagerInterface $block_manager

The block manager.

UuidInterface $uuid

The UUID generator.

PluginFormFactoryInterface $plugin_form_manager

The plugin form manager.

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.

array doBuildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, int $delta = NULL, SectionComponent $component = NULL)

Builds the form for the block.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

SectionStorageInterface $section_storage

The section storage being configured.

int $delta

The delta of the section.

SectionComponent $component

The section component containing the block.

Return Value

array

The form array.

abstract protected string submitLabel()

Returns the label for the submit button.

Return Value

string

Submit label.

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 PluginFormInterface getPluginForm(BlockPluginInterface $block)

Retrieves the plugin form for a given block.

Parameters

BlockPluginInterface $block

The block plugin.

Return Value

PluginFormInterface

The plugin form for the block.

SectionStorageInterface getSectionStorage()

Retrieves the section storage object.

Return Value

SectionStorageInterface

The section storage for the current form.

Section getCurrentSection()

Retrieves the current layout section being edited by the form.

Return Value

Section

The current layout section.

SectionComponent getCurrentComponent()

Retrieves the current component being edited by the form.

Return Value

SectionComponent

The current section component.