Problem/Motivation

If site can be accessed from different domains with different base path then you can not set a path for "Lazysizes library path, or URL" that will work for both instances.

Steps to reproduce

let's say that the same Drupal instance can be access from 2 places: www.domain1.com and www.domain2.com/site
you want that the library path to be loaded under the same domain, so setting it as absolute URL is not an option (by ex. http://www.domain1.com/libraries/lazysizes )
If I set it as /libraries/lazysizes it will not work on the second domain where the base path is "/site"

Proposed resolution

Add base path to the library path when it is set as root-relative URL .

Comments

aalin created an issue. See original summary.

aalin’s picture

StatusFileSize
new620 bytes

Patch added.
Note that this patch will break existing sites with a non empty base URL and with library path set as root-relative URL

osman’s picture

Category: Bug report » Feature request
StatusFileSize
new2.65 KB

Hey aalin,

The case you describe is quite unique, I think it could be better resolved by a more flexible option.

With this little change, the Lazy module settings can be altered in your module by the rules your sites require:

   /**
    * {@inheritdoc}
    */
   public function getSettings(): array {
+    $this->moduleHandler->alter('lazy_settings', $this->lazySettings);
     return $this->lazySettings ?? [];
   }
/**
 * Alter Lazy module settings.
 *
 * The module settings can be overridden completely, or partially for any given
 * condition.
 *
 * @param array $settings
 *   The Lazy module settings.
 */
function hook_lazy_settings_alter(&$settings) {
  switch ($_SERVER['HTTP_HOST']) {
    case 'example.com':
      $settings['libraryPath'] = 'https://cdn.example.com/libraries/lazysizes';
      break;

    case 'demo1.example.com':
      $settings['libraryPath'] = '/demo-assets/lazysizes';
      break;
  }
}
osman’s picture

Title: libraryPath value when the site can be accessed from different domains with different base path » Override libraryPath value for multi-sites with different base path

  • osman committed 72d5e0e on 8.x-3.x
    Issue #3218199 by aalin, osman: Override libraryPath value for multi-...
osman’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.