class DeleteStyles in Block Style Plugins 8.2
Provides a form to delete a block style.
@internal
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
- class \Drupal\block_style_plugins\Form\DeleteStyles uses AjaxFormHelperTrait, LayoutRebuildTrait, LayoutBuilderHighlightTrait
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
Expanded class hierarchy of DeleteStyles
1 string reference to 'DeleteStyles'
File
- src/
Form/ DeleteStyles.php, line 23
Namespace
Drupal\block_style_plugins\FormView source
class DeleteStyles extends ConfirmFormBase {
use AjaxFormHelperTrait;
use LayoutBuilderHighlightTrait;
use LayoutRebuildTrait;
/**
* The layout tempstore repository.
*
* @var \Drupal\layout_builder\LayoutTempstoreRepositoryInterface
*/
protected $layoutTempstoreRepository;
/**
* The form builder.
*
* @var \Drupal\Core\Form\FormBuilderInterface
*/
protected $formBuilder;
/**
* The section storage.
*
* @var \Drupal\layout_builder\SectionStorageInterface
*/
protected $sectionStorage;
/**
* The layout section delta.
*
* @var int
*/
protected $delta;
/**
* The uuid of the block component.
*
* @var string
*/
protected $uuid;
/**
* The plugin id of the style to be removed.
*
* @var string
*/
protected $pluginId;
/**
* Constructs a DeleteStyles object.
*
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder.
* @param \Drupal\layout_builder\LayoutTempstoreRepositoryInterface $layout_tempstore_repository
* The layout tempstore repository.
*/
public function __construct(FormBuilderInterface $form_builder, LayoutTempstoreRepositoryInterface $layout_tempstore_repository) {
$this->formBuilder = $form_builder;
$this->layoutTempstoreRepository = $layout_tempstore_repository;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('form_builder'), $container
->get('layout_builder.tempstore_repository'));
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL, $uuid = NULL, $plugin_id = NULL) {
$this->sectionStorage = $section_storage;
$this->delta = $delta;
$this->uuid = $uuid;
$this->pluginId = $plugin_id;
$form = parent::buildForm($form, $form_state);
$form['actions']['cancel'] = $this
->buildCancelLink();
$form['#attributes']['data-layout-builder-target-highlight-id'] = $this
->blockUpdateHighlightId($this->uuid);
if ($this
->isAjax()) {
$form['actions']['submit']['#ajax']['callback'] = '::ajaxSubmit';
}
return $form;
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this
->t('Are you sure you want to delete this style?');
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
$parameters = $this
->getParameters();
return new Url('block_style_plugins.layout_builder.styles', $parameters);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'block_style_plugins_layout_builder_delete_styles';
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$component = $this->sectionStorage
->getSection($this->delta)
->getComponent($this->uuid);
$component
->unsetThirdPartySetting('block_style_plugins', $this->pluginId);
$this->layoutTempstoreRepository
->set($this->sectionStorage);
$form_state
->setRedirectUrl($this->sectionStorage
->getLayoutBuilderUrl());
}
/**
* {@inheritdoc}
*/
protected function successfulAjaxSubmit(array $form, FormStateInterface $form_state) {
return $this
->rebuildAndClose($this->sectionStorage);
}
/**
* Build a cancel button for the confirm form.
*/
protected function buildCancelLink() {
return [
'#type' => 'button',
'#value' => $this
->getCancelText(),
'#ajax' => [
'callback' => '::ajaxCancel',
],
];
}
/**
* Provides an ajax callback for the cancel button.
*/
public function ajaxCancel(array &$form, FormStateInterface $form_state) {
$parameters = $this
->getParameters();
$new_form = $this->formBuilder
->getForm(BlockStyleForm::class, $this->sectionStorage, $parameters['delta'], $parameters['uuid']);
$new_form['#action'] = $this
->getCancelUrl()
->toString();
$response = new AjaxResponse();
$response
->addCommand(new OpenOffCanvasDialogCommand($this
->t('Configure Styles'), $new_form));
return $response;
}
/**
* Gets the parameters needed for the various Url() and form invocations.
*
* @return array
* List of Url parameters.
*/
protected function getParameters() {
return [
'section_storage_type' => $this->sectionStorage
->getStorageType(),
'section_storage' => $this->sectionStorage
->getStorageId(),
'delta' => $this->delta,
'uuid' => $this->uuid,
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AjaxFormHelperTrait:: |
public | function | Submit form dialog #ajax callback. | |
AjaxHelperTrait:: |
protected | function | Gets the wrapper format of the current request. | |
AjaxHelperTrait:: |
protected | function | Determines if the current request is via AJAX. | |
ConfirmFormBase:: |
public | function |
Returns a caption for the link which cancels the action. Overrides ConfirmFormInterface:: |
1 |
ConfirmFormBase:: |
public | function |
Returns a caption for the button that confirms the action. Overrides ConfirmFormInterface:: |
20 |
ConfirmFormBase:: |
public | function |
Returns additional text to display as a description. Overrides ConfirmFormInterface:: |
11 |
ConfirmFormBase:: |
public | function |
Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface:: |
|
DeleteStyles:: |
protected | property | The layout section delta. | |
DeleteStyles:: |
protected | property | The form builder. | |
DeleteStyles:: |
protected | property | The layout tempstore repository. | |
DeleteStyles:: |
protected | property | The plugin id of the style to be removed. | |
DeleteStyles:: |
protected | property | The section storage. | |
DeleteStyles:: |
protected | property | The uuid of the block component. | |
DeleteStyles:: |
public | function | Provides an ajax callback for the cancel button. | |
DeleteStyles:: |
protected | function | Build a cancel button for the confirm form. | |
DeleteStyles:: |
public | function |
Form constructor. Overrides ConfirmFormBase:: |
|
DeleteStyles:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
DeleteStyles:: |
public | function |
Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface:: |
|
DeleteStyles:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
DeleteStyles:: |
protected | function | Gets the parameters needed for the various Url() and form invocations. | |
DeleteStyles:: |
public | function |
Returns the question to ask the user. Overrides ConfirmFormInterface:: |
|
DeleteStyles:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
DeleteStyles:: |
protected | function |
Allows the form to respond to a successful AJAX submission. Overrides AjaxFormHelperTrait:: |
|
DeleteStyles:: |
public | function | Constructs a DeleteStyles object. | |
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. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
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. | |
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. |