Introduce the ability to render the PWA App Icon through the private file system

Created on 4 October 2022, over 1 year ago
Updated 21 September 2023, 9 months ago

Problem/Motivation

Currently, when having your file 'default_scheme' set to 'private', the following error will appear, when submitting the form:

The website encountered an unexpected error. Please try again later.
Error: Call to a member function basePath() on bool in Drupal\pwa\Form\ConfigurationForm->submitForm() (line 405 of modules/pwa/src/Form/ConfigurationForm.php).
Drupal\pwa\Form\ConfigurationForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 114)

This is caused, because the settings to save the app icon is based on your default_scheme setting and the App Image can only be served through the public file system.

Steps to reproduce

Proposed resolution

Add the ability to serve the image through the private file system. This is a follow-up issue on 🐛 Defined App Image Icon isn't used Fixed , which should be solved first.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Closed: won't fix

Version

2.0

Component

Code

Created by

🇺🇸United States SocialNicheGuru

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany Anybody Porta Westfalica

    @SocialNicheGuru could you perhaps reroll this as MR and add a test with public and private file system (2nd would fail without your fix) to ensure this is fixed now and in the future?

  • 🇮🇳India jincy_k

    @ SocialNicheGuru Issue persist even after choosing private/public file system.
    I'm getting this warning while deleting the image
    (Warning: unlink(/app/web/sites/default/files/pwa/pwa_sample_1.png): No such file or directory in Drupal\pwa\Manifest->deleteImage() (line 158 of /app/web/modules/contrib/pwa/src/Manifest.php) in drupal dblog

    Solution : check if the file exist in the path before unlink. I've tested this code locally and got this warning fixed
    if (file_exists($path)) {
    unlink($path);
    }

    Through a simple workaround in the code, I am able to fix all issues including below error while choosing private file system
    TypeError: imagecopyresampled(): Argument #2 ($src_image) must be of type GdImage, bool given in imagecopyresampled() (line 424 of /home/***/public_html/***.com/web/modules/contrib/pwa/src/Form/ManifestConfigurationForm.php).

    see below :

    In pwa/src/Form/ManifestConfigurationForm.php
    $files_path = \Drupal::service('file_url_generator')->generateString("public://pwa") . '/';
    $file_uri = $files_path . $file->getFilename();
    $file_path = '/app'.$files_path . $file->getFilename();
    $config->set('image', $file_uri)->save();

    I've committed my code changes to fix the issue, https://www.drupal.org/project/pwa/issues/3371404#comment-15179814 🐛 Defined App Image Icon isn't used Fixed
    Please see my merge request, https://www.drupal.org/project/pwa/issues/3371404#comment-15179814 🐛 Defined App Image Icon isn't used Fixed
    Please review and merge.

  • 🇩🇪Germany Anybody Porta Westfalica

    Further work in 2.x

  • Status changed to Active 11 months ago
  • 🇩🇪Germany Grevil

    Further work on this should be done in 🐛 Defined App Image Icon isn't used Fixed . Let's use this issue to reintroduce the ability to use the private file system once again in the future.

  • 🇩🇪Germany Anybody Porta Westfalica

    Should be fixed, but is not a priority for our team. We're happy to review MR's, preferrably with tests. Until we need this ourselves or someone sponsors it, this isn't a priority for us.

  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Anybody Porta Westfalica
  • Status changed to Postponed 11 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update 11 months ago
    1 pass
  • @grevil opened merge request.
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update 11 months ago
    1 pass
  • 🇩🇪Germany Grevil

    Note, that the current implementation, how the icon preview is rendered is incorrect instead we should use the approach similiar to https://www.drupal.org/node/2940031 .

    $uri = 'public:://test.img';
    \Drupal::service('file_url_generator')->generateAbsoluteString($uri)
    

    $uri can be both a private or public file path.

  • 🇩🇪Germany Grevil

    Internally discussed this with @Anybody, and there are no plans to support providing icons through the private file system. Through 🐛 Defined App Image Icon isn't used Fixed , the image is now always uploaded inside the public file system, no matter the stream wrapper's default scheme.

  • Status changed to Closed: won't fix 9 months ago
Production build 0.69.0 2024