class MoveBlockForm in Layout Builder Restrictions 8.2
Provides a form for moving a block.
@internal Form classes are internal.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\layout_builder\Form\MoveBlockForm uses AjaxFormHelperTrait, LayoutRebuildTrait, LayoutBuilderHighlightTrait
- class \Drupal\layout_builder_restrictions\Form\MoveBlockForm
- class \Drupal\layout_builder\Form\MoveBlockForm uses AjaxFormHelperTrait, LayoutRebuildTrait, LayoutBuilderHighlightTrait
Expanded class hierarchy of MoveBlockForm
File
- src/
Form/ MoveBlockForm.php, line 17
Namespace
Drupal\layout_builder_restrictions\FormView source
class MoveBlockForm extends MoveBlockFormCore {
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$to_region = $this
->getSelectedRegion($form_state);
$to_delta = $this
->getSelectedDelta($form_state);
$from_delta = $this->delta;
// $original_section = $this->sectionStorage->getSection($from_delta);
// $component = $original_section->getComponent($this->uuid);
// Retrieve defined Layout Builder Restrictions plugins.
$layout_builder_restrictions_manager = \Drupal::service('plugin.manager.layout_builder_restriction');
$restriction_definitions = $layout_builder_restrictions_manager
->getDefinitions();
foreach ($restriction_definitions as $restriction_definition) {
// @todo: respect ordering of plugins (see #3045266)
$plugin_instance = $layout_builder_restrictions_manager
->createInstancE($restriction_definition['id']);
$block_status = $plugin_instance
->blockAllowedinContext($this->sectionStorage, $from_delta, $to_delta, $to_region, $this->uuid, NULL);
if ($block_status !== TRUE) {
$form_state
->setErrorByName('region', $block_status);
}
}
}
/**
* Submit form dialog #ajax callback.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* An AJAX response that display validation error messages or represents a
* successful submission.
*/
public function ajaxSubmit(array &$form, FormStateInterface $form_state) {
if ($form_state
->hasAnyErrors()) {
$build_info = $form_state
->getBuildInfo();
$response = new AjaxResponse();
$content = "";
foreach ($form_state
->getErrors() as $error) {
$content .= '<p>' . $error . '</p>';
}
$build['error'] = [
'#markup' => $content,
];
$build['back_button'] = [
'#type' => 'link',
'#url' => Url::fromRoute('layout_builder.move_block_form', [
'section_storage_type' => $build_info['args'][0]
->getPluginId(),
'section_storage' => $build_info['args'][0]
->getStorageId(),
'delta' => $build_info['args'][1],
'region' => $build_info['args'][2],
'uuid' => $build_info['args'][3],
]),
'#title' => $this
->t('Back'),
'#attributes' => [
'class' => [
'use-ajax',
],
'data-dialog-type' => 'dialog',
'data-dialog-renderer' => 'off_canvas',
],
];
$response
->addCommand(new OpenOffCanvasDialogCommand("Content cannot be placed.", $build));
}
else {
$response = $this
->successfulAjaxSubmit($form, $form_state);
}
return $response;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AjaxHelperTrait:: |
protected | function | Gets the wrapper format of the current request. | |
AjaxHelperTrait:: |
protected | function | Determines if the current request is via AJAX. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LayoutBuilderHighlightTrait:: |
protected | function | Provides the ID used to highlight the active Layout Builder UI element. | |
LayoutBuilderHighlightTrait:: |
protected | function | Provides the ID used to highlight the active Layout Builder UI element. | |
LayoutBuilderHighlightTrait:: |
protected | function | Provides the ID used to highlight the active Layout Builder UI element. | |
LayoutBuilderHighlightTrait:: |
protected | function | Provides the ID used to highlight the active Layout Builder UI element. | |
LayoutRebuildTrait:: |
protected | function | Rebuilds the layout. | |
LayoutRebuildTrait:: |
protected | function | Rebuilds the layout. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
MoveBlockForm:: |
protected | property | The section delta. | |
MoveBlockForm:: |
protected | property | The Layout Tempstore. | |
MoveBlockForm:: |
protected | property | The region name. | |
MoveBlockForm:: |
protected | property | The section storage. | |
MoveBlockForm:: |
protected | property | The component uuid. | |
MoveBlockForm:: |
public | function |
Submit form dialog #ajax callback. Overrides AjaxFormHelperTrait:: |
|
MoveBlockForm:: |
public | function |
Builds the move block form. Overrides FormInterface:: |
|
MoveBlockForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
MoveBlockForm:: |
public | function | Ajax callback for the region select element. | |
MoveBlockForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
MoveBlockForm:: |
protected | function | Gets the selected delta. | |
MoveBlockForm:: |
protected | function | Gets the selected region. | |
MoveBlockForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
MoveBlockForm:: |
protected | function |
Allows the form to respond to a successful AJAX submission. Overrides AjaxFormHelperTrait:: |
|
MoveBlockForm:: |
public | function | Provides a title callback. | |
MoveBlockForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
MoveBlockForm:: |
public | function | Constructs a new MoveBlockForm. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |