Skip to content
Snippets Groups Projects
Commit 53edee3d authored by Justin Toupin's avatar Justin Toupin
Browse files

Fire JS events builder:open, builder:close, and builder:save when opening,...

Fire JS events builder:open, builder:close, and builder:save when opening, closing, and saving content using the experimental frontend widget.
parent d5fe7678
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@ use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\layout_paragraphs\LayoutParagraphsLayout;
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\layout_paragraphs\Ajax\LayoutParagraphsEventCommand;
use Drupal\layout_paragraphs\LayoutParagraphsLayoutTempstoreRepository;
/**
......@@ -89,8 +90,10 @@ class LayoutParagraphsBuilderController extends ControllerBase {
);
if ($this->isAjax()) {
$lpb_classname = $request->query->get('lpb-classname', NULL);
$layout = $form['layout_paragraphs_builder_ui']['#layout_paragraphs_layout'];
$response = new AjaxResponse();
$response->addCommand(new ReplaceCommand('.' . $lpb_classname, $form));
$response->addCommand(new LayoutParagraphsEventCommand($layout, '', 'builder:open'));
return $response;
}
return $form;
......
......@@ -15,6 +15,7 @@ use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\layout_paragraphs\Ajax\LayoutParagraphsEventCommand;
use Drupal\layout_paragraphs\LayoutParagraphsLayout;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\layout_paragraphs\LayoutParagraphsLayoutTempstoreRepository;
......@@ -169,6 +170,7 @@ class LayoutParagraphsBuilderForm extends FormBase {
$view_mode = $this->layoutParagraphsLayout->getSetting('reference_field_view_mode', 'default');
$rendered_layout = $this->layoutParagraphsLayout->getParagraphsReferenceField()->view($view_mode);
$response = new AjaxResponse();
$response->addCommand(new LayoutParagraphsEventCommand($this->layoutParagraphsLayout, '', 'builder:close'));
$response->addCommand(new ReplaceCommand('[data-lpb-form-id="' . $form['#attributes']['data-lpb-form-id'] . '"]', $rendered_layout));
return $response;
}
......@@ -195,6 +197,7 @@ class LayoutParagraphsBuilderForm extends FormBase {
'%title' => $entity->label(),
];
$response->addCommand(new MessageCommand($this->t('@type %title has been updated.', $t_args)));
$response->addCommand(new LayoutParagraphsEventCommand($this->layoutParagraphsLayout, '', 'builder:save'));
$response->addCommand(new ReplaceCommand('[data-lpb-form-id="' . $form['#attributes']['data-lpb-form-id'] . '"]', $form));
return $response;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment