restrict modal by domain

Created on 12 November 2024, 5 months ago

I try to restrict modal by domaine (and not by page)
I use HOOK_modal_alter

function custommodule_modal_alter(&$modal, $modalId)
{
  //I started the name of the modalId by "mydomain_" 
  if( !preg_match('/^mydomain/', $modalId) )
  {
    $modal = false;
  }
}

but if I got an error in the rest of the code of the module.

In the function ModalPageService::loadModalsToShow(), is it possible to make a change ?
Change

$modalsToShow[] = $modalToShow;   

by

if($modalToShow)
$modalsToShow[] = $modalToShow;   
Feature request
Status

Active

Version

5.1

Component

Code

Created by

🇧🇪Belgium philalawst

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @philalawst
  • 🇧🇷Brazil renatog Campinas

    Interesting

    You can have 1 modal on CMS that appears for 2 domains?

    Like:

    • mydomain_modal1
    • mydomain_modal2
    • mydomain_modal3

    And others

    • mydifferentdomain_modal1
    • mydifferentdomain_modal2
    • mydifferentdomain_modal3

    And you have 2 sites using the same CMS?

    Like

    1. www.mydomain.com
    2. www.mydifferentdomain.com

    Is that?

    How it works? Like multisites or using platform that has one module for 2 sites?

    Asking just as a curiosity. Maybe we can think about a feature to allow this natively instead of hook, you know?

  • 🇧🇷Brazil renatog Campinas

    In the function ModalPageService::loadModalsToShow(), is it possible to make a change ?
    Change:

    $modalsToShow[] = $modalToShow;
    by

    if($modalToShow)
    $modalsToShow[] = $modalToShow;

    Yes, it's possible

    I'd suggest making this change in your local
    If it works feel free to post a patch or Merge Request
    We can test for other scenarios
    If it works we can merge that into 5.x and 6.x

  • 🇧🇪Belgium philalawst

    @renatog thanks for your answer.

    Yes I'm using the module "Domain" (one drupal for many sites)
    and with the suggest change, i could use this module

    Or maybe to handle domain in the field "Page"
    https://mydomain.com/
    https://mydomain.com/event
    https://mydomain.com/event/*

    in verifyModalShouldAppearOnThisPath.

      public function verifyModalShouldAppearOnThisPath($path, $currentPath) {
        $host = \Drupal::request()->getSchemeAndHttpHost();
        $path = preg_quote($path, '/');
        $path = str_replace('\*', '.*', $path);
        return preg_match('/^' . preg_quote($path, '/') . '$/i', $currentPath) || preg_match('/^' . preg_quote($path, '/') . '$/i', $host.$currentPath);
      }
    
  • 🇧🇷Brazil renatog Campinas

    Yes, I think it makes sense for me

Production build 0.71.5 2024