diff --git a/src/Controller/ChooseComponentController.php b/src/Controller/ChooseComponentController.php index fc3136f6c41e215ecdb37c2b096481b3dfaaa70b..ac173e4855e3c4328e6b5adee8ede8c2d5b40425 100644 --- a/src/Controller/ChooseComponentController.php +++ b/src/Controller/ChooseComponentController.php @@ -3,16 +3,19 @@ namespace Drupal\layout_paragraphs\Controller; use Drupal\Core\Url; +use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Template\Attribute; use Drupal\Core\Ajax\AjaxHelperTrait; +use Drupal\Core\Ajax\OpenDialogCommand; use Drupal\Core\Controller\ControllerBase; -use Drupal\Core\Entity\EntityTypeBundleInfoInterface; -use Drupal\layout_paragraphs\LayoutParagraphsLayout; -use Drupal\layout_paragraphs\LayoutParagraphsLayoutRefreshTrait; -use Drupal\layout_paragraphs\Event\LayoutParagraphsAllowedTypesEvent; +use Drupal\layout_paragraphs\Utility\Dialog; use Symfony\Component\HttpFoundation\Request; +use Drupal\layout_paragraphs\LayoutParagraphsLayout; +use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Drupal\layout_paragraphs\LayoutParagraphsLayoutRefreshTrait; +use Drupal\layout_paragraphs\Event\LayoutParagraphsAllowedTypesEvent; /** * ChooseComponentController controller class. @@ -91,7 +94,7 @@ class ChooseComponentController extends ControllerBase { if (count($types) === 1) { $type_name = key($types); $type = $this->entityTypeManager()->getStorage('paragraphs_type')->load($type_name); - $response = $this->formBuilder()->getForm( + $form = $this->formBuilder()->getForm( '\Drupal\layout_paragraphs\Form\InsertComponentForm', $layout_paragraphs_layout, $type, @@ -100,7 +103,13 @@ class ChooseComponentController extends ControllerBase { $query_params['sibling_uuid'], $query_params['placement'] ); - return $response; + if ($this->isAjax()) { + $response = new AjaxResponse(); + $selector = Dialog::dialogSelector($layout_paragraphs_layout); + $response->addCommand(new OpenDialogCommand($selector, $form['#title'], $form, Dialog::dialogSettings())); + return $response; + } + return $form; } foreach ($types as &$type) { diff --git a/tests/src/FunctionalJavascript/BuilderTestBase.php b/tests/src/FunctionalJavascript/BuilderTestBase.php index f3fa73b7539b9b2b67a8cd73c463ce453e0f3179..2a9034ef100976bfacabb0a08be785b4f201e6d6 100644 --- a/tests/src/FunctionalJavascript/BuilderTestBase.php +++ b/tests/src/FunctionalJavascript/BuilderTestBase.php @@ -123,6 +123,12 @@ abstract class BuilderTestBase extends WebDriverTestBase { $this->assertSession()->assertWaitOnAjaxRequest(); } + $dialog = $page->find('css', '.lpb-dialog'); + $style = $dialog->getAttribute('style'); + if (strpos($style, 'width: 90%;') === FALSE || strpos($style, 'height: auto;') === FALSE) { + throw new ExpectationException('Incorrect dialog width or height settings', $this->getSession()->getDriver()); + } + $this->assertSession()->pageTextContains('field_text'); $page->fillField('field_text[0][value]', $text);