class DeleteComponentForm in Layout Paragraphs 2.0.x
Class DeleteComponentForm.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\layout_paragraphs\Form\DeleteComponentForm uses DialogHelperTrait, LayoutParagraphsLayoutRefreshTrait
Expanded class hierarchy of DeleteComponentForm
1 string reference to 'DeleteComponentForm'
File
- src/
Form/ DeleteComponentForm.php, line 19
Namespace
Drupal\layout_paragraphs\FormView source
class DeleteComponentForm extends FormBase {
use LayoutParagraphsLayoutRefreshTrait;
use DialogHelperTrait;
/**
* The layout paragraphs layout tempstore.
*
* @var \Drupal\layout_paragraphs\LayoutParagraphsLayoutTempstoreRepository
*/
protected $tempstore;
/**
* The uuid of the component to delete.
*
* @var string
*/
protected $componentUuid;
/**
* {@inheritDoc}
*/
protected function __construct($tempstore) {
$this->tempstore = $tempstore;
}
/**
* {@inheritDoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('layout_paragraphs.tempstore_repository'));
}
/**
* {@inheritDoc}
*/
public function getFormId() {
return 'layout_paragraphs_delete_component_form';
}
/**
* {@inheritDoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, LayoutParagraphsLayout $layout_paragraphs_layout = NULL, string $component_uuid = NULL) {
$this
->setLayoutParagraphsLayout($layout_paragraphs_layout);
$this->componentUuid = $component_uuid;
$component = $this->layoutParagraphsLayout
->getComponentByUuid($this->componentUuid);
$type = $component
->getEntity()
->getParagraphType()
->label();
$form['#title'] = $this
->t('Delete @type', [
'@type' => $type,
]);
$form['confirm'] = [
'#markup' => $this
->t('Really delete this @type? There is no undo.', [
'@type' => $type,
]),
];
$form['actions'] = [
'#type' => 'actions',
'submit' => [
'#type' => 'submit',
'#value' => $this
->t('Delete'),
'#ajax' => [
'callback' => '::deleteComponent',
],
],
'cancel' => [
'#type' => 'button',
'#value' => $this
->t('Cancel'),
'#ajax' => [
'callback' => '::closeForm',
],
],
];
return $form;
}
/**
* {@inheritDoc}
*
* Deletes the component and saves the layout.
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->layoutParagraphsLayout
->deleteComponent($this->componentUuid, TRUE);
$this->tempstore
->set($this->layoutParagraphsLayout);
}
/**
* Ajax callback - deletes component and closes the form.
*
* @param array $form
* The form array.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state object.
*/
public function deleteComponent(array $form, FormStateInterface $form_state) {
$response = new AjaxResponse();
$response
->addCommand(new CloseDialogCommand($this
->dialogSelector($this->layoutParagraphsLayout)));
if ($this
->needsRefresh()) {
return $this
->refreshLayout($response);
}
$response
->addCommand(new RemoveCommand('[data-uuid="' . $this->componentUuid . '"]'));
$response
->addCommand(new LayoutParagraphsEventCommand($this->layoutParagraphsLayout, $this->componentUuid, 'component:delete'));
return $response;
}
/**
* Ajax callback - closes the form.
*
* @param array $form
* The form array.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state object.
*/
public function closeForm(array $form, FormStateInterface $form_state) {
$response = new AjaxResponse();
$response
->addCommand($this
->closeDialogCommand($this->layoutParagraphsLayout));
return $response;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeleteComponentForm:: |
protected | property | The uuid of the component to delete. | |
DeleteComponentForm:: |
protected | property | The layout paragraphs layout tempstore. | |
DeleteComponentForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
DeleteComponentForm:: |
public | function | Ajax callback - closes the form. | |
DeleteComponentForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
DeleteComponentForm:: |
public | function | Ajax callback - deletes component and closes the form. | |
DeleteComponentForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
DeleteComponentForm:: |
public | function |
Deletes the component and saves the layout. Overrides FormInterface:: |
|
DeleteComponentForm:: |
protected | function | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
DialogHelperTrait:: |
protected | function | Returns a CloseDialogComand with the correct selector. | |
DialogHelperTrait:: |
protected | function | Generates a dialog id for a given layout. | |
DialogHelperTrait:: |
protected | function | Generates a dialog selector for a given layout. | |
DialogHelperTrait:: |
protected | function | Returns an array of dialog settings for modal edit forms. | |
FormBase:: |
protected | property | The config factory. | 3 |
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. | 3 |
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. | |
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:: |
72 |
LayoutParagraphsLayoutRefreshTrait:: |
protected | property | The event dispatcher service. | 1 |
LayoutParagraphsLayoutRefreshTrait:: |
protected | property | The layout paragraphs layout object. | |
LayoutParagraphsLayoutRefreshTrait:: |
protected | property | The original paragraphs layout object. | |
LayoutParagraphsLayoutRefreshTrait:: |
protected | function | Returns the event dispatcher service. | 1 |
LayoutParagraphsLayoutRefreshTrait:: |
protected | function | Returns TRUE if the layout needs to be refreshed. | |
LayoutParagraphsLayoutRefreshTrait:: |
protected | function | Decorates an ajax response with a command to refresh an entire layout. | |
LayoutParagraphsLayoutRefreshTrait:: |
protected | function | Renders the layout builder UI render array. | |
LayoutParagraphsLayoutRefreshTrait:: |
protected | function | Setter for layoutParagraphsLayout property. | |
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. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
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. | 4 |
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. |