Add an option to manually define paths on which the manifest.json should be attached to (white / blacklist)

Created on 10 August 2023, 11 months ago
Updated 13 September 2023, 10 months ago

Problem/Motivation

Currently, we attach the manifest.json on every page of a website. Though this doesn't make sense for instances, where our web app is under a different sub-path like "mywebsite/app". We can define the start-url to "mywebsite/app" and the scope to "mywebsite/app". But we can not 'scope' the manifest.json to "mywebsite/app".

Steps to reproduce

Proposed resolution

Add an option to manually define paths on which the manifest.json should be attached to.

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

🇩🇪Germany Grevil

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

Comments & Activities

  • Issue created by @Grevil
  • 🇩🇪Germany Anybody Porta Westfalica

    Yes I think that's a nice and helpful feature for cases where the app isn't the same as the project itself, but just part of the site, like /app or even /app/my-abc-app

  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Anybody Porta Westfalica

    I think the exclusion by path is the better and flexible enough approach? Exclude by content type Active

  • Assigned to Grevil
  • 🇩🇪Germany Grevil

    I only really see one benefit in this. So that the "install app x" notification doesn't show up on "/mywebsite", but instead only on "/mywebsite/app".

    We currently do not support multiple manifest.json's, which would be another benefit of this, as we could scope app1 in "/mywebsite/app1" and app2 in "/mywebsite/app2". And the rest of the scoping is done through "scope" and "start-url", should we postpone this issue in the future? Or is it really that important @Anybody?

  • Status changed to Needs work 10 months ago
  • 🇩🇪Germany Grevil

    Just discussed this with @Anybody internally. This should be implemented!

  • 🇩🇪Germany Grevil

    I'll continue with this tommorow.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    1 pass, 2 fail
  • @grevil opened merge request.
  • 🇩🇪Germany Anybody Porta Westfalica

    Should be similar to the implementation of block visibility settings or here in etracker:

        $form['tracking']['pages']['etracker_track_path_mode'] = [
          '#type' => 'radios',
          '#title' => $this->t('Add tracking to specific pages'),
          '#options' => [
            Constants::ETRACKER_TRACK_PATHS_MODE_ALL => $this->t('Every page except the listed pages'),
            Constants::ETRACKER_TRACK_PATHS_MODE_LISTED => $this->t('The listed pages only'),
          ],
          '#default_value' => $config->get('etracker_track_path_mode'),
        ];
        $form['tracking']['pages']['etracker_track_paths'] = [
          '#type' => 'textarea',
          '#title' => $this->t('Pages'),
          '#title_display' => 'invisible',
          '#default_value' => $config->get('etracker_track_paths'),
          '#description' => $this->t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.",
            [
              '%blog' => '/blog',
              '%blog-wildcard' => '/blog/*',
              '%front' => '<front>',
            ]),
          '#rows' => 10,
        ];
    
    
    
    /**
     * Tracking visibility check for pages.
     *
     * Based on visibility setting this function returns TRUE if JS code should
     * be added to the current page and otherwise FALSE.
     *
     * @param \Drupal\Core\Config\ImmutableConfig $config
     *   A config object.
     *
     * @return bool
     *   Returns TRUE if JS code should be added to the current page.
     */
    function _etracker_path_should_be_tracked(ImmutableConfig $config) {
      $path_should_be_tracked = &drupal_static(__FUNCTION__);
    
      // Cache tracking result if function is called more than once.
      if (!isset($path_should_be_tracked)) {
    
        $visible_path_mode = $config->get('etracker_track_path_mode');
        $visible_path_pages = $config->get('etracker_track_paths');
    
        // Match path if necessary.
        if (!empty($visible_path_pages)) {
          // Convert path to lowercase. This allows comparison of the same path
          // with different case. Ex: /Page, /page, /PAGE.
          $pages = mb_strtolower($visible_path_pages);
    
          $path = Drupal::service('path.current')->getPath();
          $path_alias = \Drupal::service('path_alias.manager')->getAliasByPath($path);
          if (empty($path_alias)) {
            $path_alias = mb_strtolower($path);
          }
          else {
            $path_alias = mb_strtolower($path_alias);
          }
          $page_match = \Drupal::service('path.matcher')->matchPath($path_alias, $pages) || (($path != $path_alias) && \Drupal::service('path.matcher')->matchPath($path, $pages));
          // When $visible_path_mode has a value of 'all_pages', the tracking
          // code is displayed on all pages except those listed in $pages. When set
          // to 'all_listed', it is displayed only on those pages listed in $pages.
          $track_all_paths = ($visible_path_mode == Constants::ETRACKER_TRACK_PATHS_MODE_ALL);
          $path_should_be_tracked = ($track_all_paths xor $page_match);
        }
        else {
          $path_should_be_tracked = TRUE;
        }
      }
      return $path_should_be_tracked;
    }
    
    
  • 🇩🇪Germany Grevil

    Yep, already implemented the form based on the etracker implementation yesterday.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    1 pass, 2 fail
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    9 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    11 pass
  • Issue was unassigned.
  • Status changed to Needs review 10 months ago
  • 🇩🇪Germany Grevil

    Done, works great! 🙂👍

    Also added tests to verify its functionality. Please review!

  • Status changed to Needs work 10 months ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Nice work! As just discussed!

  • Status changed to Needs review 10 months ago
  • 🇩🇪Germany Grevil

    Please rereview!

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    11 pass
  • Status changed to RTBC 10 months ago
  • 🇩🇪Germany Anybody Porta Westfalica
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    11 pass
  • Status changed to Fixed 10 months ago
  • 🇩🇪Germany Anybody Porta Westfalica
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024