Drupal 8 | Views with exposed filter and ajax enabled inside modal window










0














Bonjour,



I followed this procedure to create a custom modal window:
https://befused.com/drupal/modal-module.
It works very well!



My objective is to display in this modal window, a view with exposed filters. The "use AJAX" option is enabled on the view.



The view display in the modal window works well, however, when I use context filters, the page is refreshed instead of using AJAX.



If I position the block with the link to the modal window in the administration theme (seven) everything works perfectly (ajax is used), but it doesn't work on the main theme of the site.



I use a custom theme, based on bootstrap_barrio.



Here are the different elements:



File mymodule.routing.yml



mymodule.search.modal:
path: '/mymodule/search/modal'
defaults:
_controller: 'DrupalmymoduleControllerSearchController::modal'
_title: 'Search'
requirements:
_permission: 'access content'


File SearchController.php



public function modal() 

$view = Views::getView('mysearch_view');
$view->preview('page_1');

$options = [
'dialogClass' => 'popup-dialog-class',
'width' => '50%',
];
$response = new AjaxResponse();
$response->addCommand(new OpenModalDialogCommand(
t('Search'),
$view->render(),
$options
));

return $response;



File ModalSearchBlock



class ModalSearchBlock extends BlockBase 
/**
* @inheritdoc
*/
public function build()

$link_url = Url::fromRoute('mymodule.search.modal');
$link_url->setOptions([
'attributes' => [
'class' => ['use-ajax', 'button', 'button--small'],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode(['width' => 400]),
]
]);

return array(
'#type' => 'markup',
'#markup' => Link::fromTextAndUrl(t('Search'), $link_url)->toString(),
'#attached' => ['library' => [
'core/drupal.dialog.ajax',
'core/views.ajax',
]]
);




I hope my explanation is clear enough.
Thank you in advance for your help.










share|improve this question




























    0














    Bonjour,



    I followed this procedure to create a custom modal window:
    https://befused.com/drupal/modal-module.
    It works very well!



    My objective is to display in this modal window, a view with exposed filters. The "use AJAX" option is enabled on the view.



    The view display in the modal window works well, however, when I use context filters, the page is refreshed instead of using AJAX.



    If I position the block with the link to the modal window in the administration theme (seven) everything works perfectly (ajax is used), but it doesn't work on the main theme of the site.



    I use a custom theme, based on bootstrap_barrio.



    Here are the different elements:



    File mymodule.routing.yml



    mymodule.search.modal:
    path: '/mymodule/search/modal'
    defaults:
    _controller: 'DrupalmymoduleControllerSearchController::modal'
    _title: 'Search'
    requirements:
    _permission: 'access content'


    File SearchController.php



    public function modal() 

    $view = Views::getView('mysearch_view');
    $view->preview('page_1');

    $options = [
    'dialogClass' => 'popup-dialog-class',
    'width' => '50%',
    ];
    $response = new AjaxResponse();
    $response->addCommand(new OpenModalDialogCommand(
    t('Search'),
    $view->render(),
    $options
    ));

    return $response;



    File ModalSearchBlock



    class ModalSearchBlock extends BlockBase 
    /**
    * @inheritdoc
    */
    public function build()

    $link_url = Url::fromRoute('mymodule.search.modal');
    $link_url->setOptions([
    'attributes' => [
    'class' => ['use-ajax', 'button', 'button--small'],
    'data-dialog-type' => 'modal',
    'data-dialog-options' => Json::encode(['width' => 400]),
    ]
    ]);

    return array(
    '#type' => 'markup',
    '#markup' => Link::fromTextAndUrl(t('Search'), $link_url)->toString(),
    '#attached' => ['library' => [
    'core/drupal.dialog.ajax',
    'core/views.ajax',
    ]]
    );




    I hope my explanation is clear enough.
    Thank you in advance for your help.










    share|improve this question


























      0












      0








      0







      Bonjour,



      I followed this procedure to create a custom modal window:
      https://befused.com/drupal/modal-module.
      It works very well!



      My objective is to display in this modal window, a view with exposed filters. The "use AJAX" option is enabled on the view.



      The view display in the modal window works well, however, when I use context filters, the page is refreshed instead of using AJAX.



      If I position the block with the link to the modal window in the administration theme (seven) everything works perfectly (ajax is used), but it doesn't work on the main theme of the site.



      I use a custom theme, based on bootstrap_barrio.



      Here are the different elements:



      File mymodule.routing.yml



      mymodule.search.modal:
      path: '/mymodule/search/modal'
      defaults:
      _controller: 'DrupalmymoduleControllerSearchController::modal'
      _title: 'Search'
      requirements:
      _permission: 'access content'


      File SearchController.php



      public function modal() 

      $view = Views::getView('mysearch_view');
      $view->preview('page_1');

      $options = [
      'dialogClass' => 'popup-dialog-class',
      'width' => '50%',
      ];
      $response = new AjaxResponse();
      $response->addCommand(new OpenModalDialogCommand(
      t('Search'),
      $view->render(),
      $options
      ));

      return $response;



      File ModalSearchBlock



      class ModalSearchBlock extends BlockBase 
      /**
      * @inheritdoc
      */
      public function build()

      $link_url = Url::fromRoute('mymodule.search.modal');
      $link_url->setOptions([
      'attributes' => [
      'class' => ['use-ajax', 'button', 'button--small'],
      'data-dialog-type' => 'modal',
      'data-dialog-options' => Json::encode(['width' => 400]),
      ]
      ]);

      return array(
      '#type' => 'markup',
      '#markup' => Link::fromTextAndUrl(t('Search'), $link_url)->toString(),
      '#attached' => ['library' => [
      'core/drupal.dialog.ajax',
      'core/views.ajax',
      ]]
      );




      I hope my explanation is clear enough.
      Thank you in advance for your help.










      share|improve this question















      Bonjour,



      I followed this procedure to create a custom modal window:
      https://befused.com/drupal/modal-module.
      It works very well!



      My objective is to display in this modal window, a view with exposed filters. The "use AJAX" option is enabled on the view.



      The view display in the modal window works well, however, when I use context filters, the page is refreshed instead of using AJAX.



      If I position the block with the link to the modal window in the administration theme (seven) everything works perfectly (ajax is used), but it doesn't work on the main theme of the site.



      I use a custom theme, based on bootstrap_barrio.



      Here are the different elements:



      File mymodule.routing.yml



      mymodule.search.modal:
      path: '/mymodule/search/modal'
      defaults:
      _controller: 'DrupalmymoduleControllerSearchController::modal'
      _title: 'Search'
      requirements:
      _permission: 'access content'


      File SearchController.php



      public function modal() 

      $view = Views::getView('mysearch_view');
      $view->preview('page_1');

      $options = [
      'dialogClass' => 'popup-dialog-class',
      'width' => '50%',
      ];
      $response = new AjaxResponse();
      $response->addCommand(new OpenModalDialogCommand(
      t('Search'),
      $view->render(),
      $options
      ));

      return $response;



      File ModalSearchBlock



      class ModalSearchBlock extends BlockBase 
      /**
      * @inheritdoc
      */
      public function build()

      $link_url = Url::fromRoute('mymodule.search.modal');
      $link_url->setOptions([
      'attributes' => [
      'class' => ['use-ajax', 'button', 'button--small'],
      'data-dialog-type' => 'modal',
      'data-dialog-options' => Json::encode(['width' => 400]),
      ]
      ]);

      return array(
      '#type' => 'markup',
      '#markup' => Link::fromTextAndUrl(t('Search'), $link_url)->toString(),
      '#attached' => ['library' => [
      'core/drupal.dialog.ajax',
      'core/views.ajax',
      ]]
      );




      I hope my explanation is clear enough.
      Thank you in advance for your help.







      ajax drupal-8 drupal-views






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 15:25

























      asked Nov 12 at 14:16









      Germain

      134




      134



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264037%2fdrupal-8-views-with-exposed-filter-and-ajax-enabled-inside-modal-window%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264037%2fdrupal-8-views-with-exposed-filter-and-ajax-enabled-inside-modal-window%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3

          Museum of Modern and Contemporary Art of Trento and Rovereto