Commit d4e7e78a authored by paul121's avatar paul121
Browse files

Issue #3243922 by paul121, Symbioquine, m.stenta: farmOS-map chunks fail to...

Issue #3243922 by paul121, Symbioquine, m.stenta: farmOS-map chunks fail to load when map is rendered via AJAX
parent 17bbeef9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Fix [warning] Invalid argument supplied for foreach() EntityViewsDataTaxonomyFilterTrait.php:26 #575](https://github.com/farmOS/farmOS/pull/575)
- [Set reduce_duplicates: true in Views exposed filters for multivalue fields #571](https://github.com/farmOS/farmOS/pull/571)
- [Update core map behaviors to properly depend on core/drupalSettings #578](https://github.com/farmOS/farmOS/pull/578)
- [Issue #3243922 by paul121, Symbioquine, m.stenta: farmOS-map chunks fail to load when map is rendered via AJAX](https://www.drupal.org/project/farm/issues/3243922)

## [2.0.0-beta6] 2022-07-30

+7 −0
Original line number Diff line number Diff line
farm_map_public_path:
  js:
    js/farm_map_public_path.js: { }
  dependencies:
    - core/drupalSettings

farmOS-map:
  remote: https://github.com/farmOS/farmOS-map
  license:
@@ -15,6 +21,7 @@ farmOS-map:
      /libraries/farmOS-map/farmOS-map.css: { }
  dependencies:
    - core/drupalSettings
    - farm_map/farm_map_public_path

farm_map:
  css:
+6 −0
Original line number Diff line number Diff line
(function (drupalSettings) {
  // Set window.farmosMapPublicPath to tell farmOS-map where to load chunks from.
  if (!!drupalSettings.farm_map_public_path) {
    window.farmosMapPublicPath = drupalSettings.farm_map_public_path;
  }
}(drupalSettings));
+17 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Drupal\farm_map\Element;

use Drupal\Component\Utility\Html;
use Drupal\Core\Render\Element\RenderElement;
use Drupal\Core\Url;
use Drupal\farm_map\Event\MapRenderEvent;

/**
@@ -73,6 +74,22 @@ class FarmMap extends RenderElement {
    $element['#attached']['library'][] = 'farm_map/farmOS-map';
    $element['#attached']['library'][] = 'farm_map/farm_map';

    // Determine the public path for the farmOS-map library.
    // Get the farm_map/farmOS-map library.
    /** @var \Drupal\Core\Asset\LibraryDiscovery $library_discovery */
    $library_discovery = \Drupal::service('library.discovery');
    $library_info = $library_discovery->getLibraryByName('farm_map', 'farmOS-map');

    // Build an absolute server path to the farmOS-map library that includes the Drupal base path.
    $js_path = $library_info['js'][0]['data'];
    $absolute_js_path = Url::fromUri("base:$js_path")->setAbsolute(FALSE)->toString();

    // Remove 13 characters of farmOS-map.js from the path.
    $public_path = substr($absolute_js_path, 0, -13);

    // Add public base path as settings for farm_map_public_path.
    $element['#attached']['drupalSettings']['farm_map_public_path'] = $public_path;

    // If #behaviors are included, attach each one.
    foreach ($element['#behaviors'] as $behavior_name) {
      /** @var \Drupal\farm_map\Entity\MapBehaviorInterface $behavior */