Commit 6301f20b authored by Florent Torregrosa's avatar Florent Torregrosa Committed by Florent Torregrosa
Browse files

Issue #3267827 by Grimreaper: Convert container ID into container URL. Fix cache tags.

parent 800f0158
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
container_location: ''
+2 −10
Original line number Diff line number Diff line
matomo_tagmanager.settings:
  type: config_object
  label: 'Matomo Tag Manager settings'
  mapping:
    container_location:
      type: string
      label: 'Container file location'

matomo_tagmanager.container.*:
  type: config_entity
  label: 'Container settings'
@@ -19,6 +11,6 @@ matomo_tagmanager.container.*:
    weight:
      type: integer
      label: 'Weight'
    container_id:
    container_url:
      type: string
      label: 'Container ID'
      label: 'Container URL'
+44 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Install, update and uninstall functions for the Matomo Tag Manager module.
 */

declare(strict_types = 1);

/**
 * Convert container ID into container URL. Remove settings.
 */
function matomo_tagmanager_update_8000(): void {
  $container_location = '';
  $tagmanager_config = \Drupal::configFactory()->getEditable('matomo_tagmanager.settings');
  // Delete no more needed config.
  if ($tagmanager_config != NULL) {
    $container_location = $tagmanager_config->get('container_location') ?? '';
    $tagmanager_config->delete();
  }

  /** @var Drupal\matomo_tagmanager\ContainerStorageInterface $container_storage */
  $container_storage = \Drupal::entityTypeManager()->getStorage('matomo_tagmanager_container');
  /** @var \Drupal\matomo_tagmanager\Entity\ContainerInterface[] $containers */
  $containers = $container_storage->loadMultiple();

  if (empty($containers)) {
    return;
  }

  // Convert container ID into container URL.
  $matomo_config = \Drupal::config('matomo.settings');
  $url_http = $matomo_config->get('url_http');
  $url_https = $matomo_config->get('url_https');
  $matomo_url = empty($url_https) ? $url_http : $url_https;
  $matomo_url = rtrim($matomo_url, '/');
  $container_location = ltrim($container_location, '/');
  foreach ($containers as $container) {
    $container_id = $container->get('container_id');
    $container_url = "${matomo_url}/${container_location}container_${container_id}.js";
    $container->set('container_url', $container_url);
    $container->save();
  }
}
+0 −5
Original line number Diff line number Diff line
matomo_tagmanager.settings_form:
  title: 'Matomo Tag Manager settings'
  route_name: matomo_tagmanager.settings_form
  parent: matomo.admin_settings_form

entity.matomo_tagmanager_container.collection:
  title: 'Matomo Tag Manager containers'
  description: 'Configure the website integration with Matomo Tag Manager.'
+0 −5
Original line number Diff line number Diff line
matomo_tagmanager.settings_tab:
  title: 'Tag Manager settings'
  route_name: matomo_tagmanager.settings_form
  base_route: matomo.admin_settings_form

matomo_tagmanager.container_list_tab:
  title: 'Tag Manager containers'
  route_name: entity.matomo_tagmanager_container.collection
Loading