ComponentFormController.php in Layout Paragraphs 2.0.x
File
src/Controller/ComponentFormController.php
View source
<?php
namespace Drupal\layout_paragraphs\Controller;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\AjaxHelperTrait;
use Drupal\Core\Ajax\OpenDialogCommand;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
use Drupal\paragraphs\ParagraphsTypeInterface;
use Drupal\layout_paragraphs\LayoutParagraphsLayout;
use Drupal\layout_paragraphs\DialogHelperTrait;
class ComponentFormController extends ControllerBase {
use AjaxHelperTrait;
use DialogHelperTrait;
public function insertForm(Request $request, LayoutParagraphsLayout $layout_paragraphs_layout, ParagraphsTypeInterface $paragraph_type) {
$parent_uuid = $request->query
->get('parent_uuid');
$region = $request->query
->get('region');
$sibling_uuid = $request->query
->get('sibling_uuid');
$placement = $request->query
->get('placement');
$form = $this
->formBuilder()
->getForm('\\Drupal\\layout_paragraphs\\Form\\InsertComponentForm', $layout_paragraphs_layout, $paragraph_type, $parent_uuid, $region, $sibling_uuid, $placement);
return $this
->openForm($form, $layout_paragraphs_layout);
}
protected function openForm(array $form, LayoutParagraphsLayout $layout_paragraphs_layout) {
if ($this
->isAjax()) {
$response = new AjaxResponse();
$selector = $this
->dialogSelector($layout_paragraphs_layout);
$response
->addCommand(new OpenDialogCommand($selector, $form['#title'], $form, $this
->dialogSettings()));
return $response;
}
return $form;
}
}