public function LayoutParagraphsWidget::removeForm in Layout Paragraphs 1.0.x
Builds the remove item confirmation form.
Parameters
array $element: The form element.
\Drupal\Core\Form\FormStateInterface $form_state: The form_state object.
array $form: The form array.
1 call to LayoutParagraphsWidget::removeForm()
- LayoutParagraphsWidget::formMultipleElements in src/
Plugin/ Field/ FieldWidget/ LayoutParagraphsWidget.php - Builds the main widget form array container/wrapper.
File
- src/
Plugin/ Field/ FieldWidget/ LayoutParagraphsWidget.php, line 1276
Class
- LayoutParagraphsWidget
- Entity Reference with Layout field widget.
Namespace
Drupal\layout_paragraphs\Plugin\Field\FieldWidgetCode
public function removeForm(array &$element, FormStateInterface $form_state, array &$form) {
$parents = $element['#parents'];
$widget_state = static::getWidgetState($parents, $this->fieldName, $form_state);
$delta = $widget_state['remove_item'];
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph_entity */
$entity = $widget_state['items'][$delta]['entity'];
$element['remove_form'] = [
'#prefix' => '<div class="layout-paragraphs-form">',
'#suffix' => '</div>',
'#type' => 'container',
'#entity' => $entity,
'#attributes' => [
'data-dialog-title' => [
$this
->t('Confirm removal'),
],
],
'message' => [
'#type' => 'markup',
'#markup' => $this
->t('Are you sure you want to permanently remove this <b>@type?</b><br />This action cannot be undone.', [
'@type' => $entity->type->entity
->label(),
]),
],
'actions' => [
'#type' => 'actions',
'#attributes' => [
'class' => [
'layout-paragraphs-item-form-actions',
],
],
'confirm' => [
'#type' => 'submit',
'#value' => $this
->t('Remove'),
'#delta' => $delta,
'#uuid' => $entity
->uuid(),
'#submit' => [
[
$this,
'removeItemConfirmSubmit',
],
],
'#ajax' => [
'callback' => [
$this,
'removeItemConfirmAjax',
],
'progress' => 'none',
],
'#limit_validation_errors' => [
array_merge($parents, [
$this->fieldName,
'remove_form',
]),
],
'#element_parents' => $parents,
],
'cancel' => [
'#type' => 'submit',
'#value' => $this
->t('Cancel'),
'#delta' => $delta,
'#submit' => [
[
$this,
'removeItemCancelSubmit',
],
],
'#attributes' => [
'class' => [
'layout-paragraphs-cancel',
'button--danger',
],
],
'#ajax' => [
'callback' => [
$this,
'closeDialogAjax',
],
'progress' => 'none',
],
'#element_parents' => $parents,
'#limit_validation_errors' => [],
],
],
'#delta' => $delta,
];
if ($this
->hasChildren($entity, $widget_state['items'])) {
$element['remove_form']['nested_items'] = [
'#type' => 'radios',
'#title' => $this
->t('This layout has nested items.'),
'#options' => [
'disable' => $this
->t('Disable nested items'),
'remove' => $this
->t('Permanently remove nested items'),
],
'disable' => [
'#description' => $this
->t('Nested items will be moved to the <b>Disabled Items</b> section and can be editied or restored.'),
],
'remove' => [
'#description' => $this
->t('Nested items will be permanenty removed.'),
],
'#default_value' => 'disable',
];
}
}