Media source plugin

Created on 29 October 2024, 2 months ago

Problem/Motivation

For editorial reasons, it can be nice to have icons handled as media:

  • An administrator can created predefined media icons and content editor can only pick in this curated list.
  • Mixing icons with other medias without having to have a new field in case of wanting to render an icon.

Proposed resolution

Provide a media source plugin which would make available as extracted data the icon ID, group ID, icon pack ID. And would be linked to an icon field.

Remaining tasks

- create a ui_icons_media sub module
- create a media source plugin
- tests

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇫🇷France Grimreaper France 🇫🇷

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

Merge Requests

Comments & Activities

  • Issue created by @Grimreaper
  • 🇫🇷France Grimreaper France 🇫🇷
  • Pipeline finished with Failed
    2 months ago
    Total: 168s
    #325111
  • Pipeline finished with Failed
    2 months ago
    Total: 188s
    #325113
  • Pipeline finished with Failed
    2 months ago
    Total: 193s
    #325161
  • Pipeline finished with Failed
    2 months ago
    Total: 174s
    #325216
  • Pipeline finished with Failed
    2 months ago
    Total: 174s
    #325227
  • 🇫🇷France Grimreaper France 🇫🇷
  • Pipeline finished with Failed
    2 months ago
    Total: 174s
    #325231
  • 🇫🇷France Grimreaper France 🇫🇷

    I just thought of something about thumbnail.

    As it creates a file entity which points to the SVG file in the library, if the file entity is deleted (for any reason: media deleted, so usage drops to 0, manual deletion, etc.), will it delete the SVG file in the icon library?

    I need to check that and also test if Fontawesome does not have the same problem.

  • 🇫🇷France Grimreaper France 🇫🇷
    MariaDB [drupal]> SELECT * FROM file_managed;
    +-----+--------------------------------------+----------+------+-------------------+------------------------------------------------------+---------------+----------+--------+------------+------------+
    | fid | uuid                                 | langcode | uid  | filename          | uri                                                  | filemime      | filesize | status | created    | changed    |
    +-----+--------------------------------------+----------+------+-------------------+------------------------------------------------------+---------------+----------+--------+------------+------------+|   5 | 5f75ac1d-3c39-45ed-9217-49e9a63fcc4a | en       |    1 | square-gitlab.svg | /libraries/fontawesome/svgs/brands/square-gitlab.svg | image/svg+xml |     NULL |      1 | 1730297429 | 1730297429 |
    |  10 | acf3c1fc-d063-4bd9-a989-2193e4984dc1 | en       |    1 | gitlab.svg        | libraries/fontawesome/svgs/brands/gitlab.svg         | image/svg+xml |     1055 |      1 | 1730713012 | 1730713012 |
    +-----+--------------------------------------+----------+------+-------------------+------------------------------------------------------+---------------+----------+--------+------------+------------+
    

    So I have tested with the plugin from the issue.

    Has the URI is something like "/libraries/fontawesome/svgs/brands/square-gitlab.svg" with a slash at the beginning, Drupal does not detect its size.

    And when I delete the media the file is not deleted but if I trigger manually the file entity deletion, then:
    - app/core/lib/Drupal/Core/File/FileSystem.php::delete:

    ...
        // Return TRUE for non-existent file as the current state is the intended
        // result.
        if (!file_exists($path)) {
          return TRUE;
        }
    ...
    

    Does not detect the file so it is not deleted.

    I tried with the fontawesome module media source plugin. And with it, the thumbnail URI is like "libraries/fontawesome/svgs/brands/gitlab.svg" without slash at the beginning so Drupal detect the file size, and same when I delete the media, the URI is not deleted automatically.

    And if I manually delete the file entity then I got:

    Warning: unlink(libraries/fontawesome/svgs/brands/github.svg): Permission denied in Drupal\Core\File\FileSystem->unlink() (line 118 of core/lib/Drupal/Core/File/FileSystem.php).

    So, Drupal really tried to delete the file and it was only system file permissions which prevented the deletion.

    So, I guess for the thumbnail, I think we should copy the file into the public stream wrapper and then use this copy.

  • 🇫🇷France Grimreaper France 🇫🇷
  • Pipeline finished with Failed
    about 2 months ago
    Total: 239s
    #330197
  • Pipeline finished with Canceled
    about 2 months ago
    Total: 76s
    #330881
  • 🇫🇷France Grimreaper France 🇫🇷
  • Pipeline finished with Failed
    about 2 months ago
    Total: 401s
    #330882
  • First commit to issue fork.
  • 🇫🇷France Grimreaper France 🇫🇷
  • Pipeline finished with Failed
    about 2 months ago
    Total: 196s
    #338926
  • 🇫🇷France Grimreaper France 🇫🇷

    MR updated.

    Please tell me if this method to get thumbnail is ok. I didn't find a way to get it simpler.

    I left 2 todos to open discussion.

    When feedbacks will be ok I will update tests.

  • Pipeline finished with Failed
    about 2 months ago
    Total: 153s
    #339585
  • 🇫🇷France Grimreaper France 🇫🇷
  • Pipeline finished with Failed
    about 1 month ago
    Total: 176s
    #343430
  • Pipeline finished with Failed
    about 1 month ago
    Total: 245s
    #343451
  • Pipeline finished with Failed
    about 1 month ago
    Total: 205s
    #343475
  • 🇫🇷France Grimreaper France 🇫🇷

    CI jobs in failure are not related to the changes in the MR.

    Back to needs review.

  • 🇫🇷France mogtofu33

    Thanks for the work!

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

Production build 0.71.5 2024