Allow for extending supported asset types

Created on 13 February 2025, about 2 months ago

Problem/Motivation

Asset types are currently hard-coded to support a 1:1 mapping with how Widen defines assets. This means the only supported sources & media types are:
* Audio
* Documents
* Generic
* Image
* PDF
* Spinset
* Video

This is hard coded, and also not extendable as class definitions for Asset, AssetDeriver, and MediaTypeResolver all have the 'final' keyword.

This prevents organizations using Acquia DAM from being able to further segment assets and their mapping to Drupal. As a use case, our client has the need to store "Icon" assets in Acquia DAM. While these Icons are considered Images in Widen's terms, additional metadata was added to be able to segment images into "Photograph" and "Icon". If AssetDeriver & MediaTypeResolver were extensible through custom modules, we could add Icon as a supported asset type in Drupal and route assets from Widen correctly between image & icon types based on this additional metadata.

Proposed resolution

Update AssetDeriver, Asset, & MediaTypeResolver classes to be extensible by custom modules through class overrides or by allowing logic to be altered before returning results.

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Active

Version

1.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jerdavis Minneapolis, MN

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

Comments & Activities

  • Issue created by @jerdavis
  • πŸ‡ΊπŸ‡ΈUnited States jerdavis Minneapolis, MN

    This is causing issues with integration with Acquia DAM for our client. I can look to provide patches, but I need to understand from the maintainers the reasoning behind the use of "final" on these classes, and what the correct path to allow for extending is in the minds of the maintainers.

  • πŸ‡ΊπŸ‡ΈUnited States japerry KVUO

    I need to understand from the maintainers the reasoning behind the use of "final" on these classes, and what the correct path to allow for extending is in the minds of the maintainers.

    Over time, we've found that customers will override classes throughout modules, if they can, which causes headache in the future when even simple changes are made. This requires new major versions to be created, which has a knock-on effect to downstream modules, making upgrading more difficult, especially custom code on customer sites.

    That is why, except where we explicitly want to expose the API at a class level, we mark classes as Final. That way, when a customer request, like this one, comes in, we can make informed architectural decisions.

    Luckily, as part of our download/sync work, we noticed that the hard coded derivatives were not sufficient. Instead of expanding their use within a single, non extensible class, a new plugin framework was introduced that allows us (and the original author of this post!) to add functionality without needing to change the signature of the underlying Asset and AssetDeriver classes.

    Asset Media Source Plugins

    Under Drupal\acquia_dam\Plugin\media\acquia_dam you'll find that all of our Asset types are separated into new plugins.
    You can create a new Annotation like the following:

     * @AssetMediaSource(
     *   id = "audio",
     *   label = @Translation("Acquia DAM: Audio"),
     *   default_thumbnail_filename = "generic.png",
     *   asset_search_key = "ft",
     *   asset_search_value = "audio",
     * )
    

    The plugins we use extend MediaSourceTypeBase -- which is public for customers to extend as well. In it are 3 variables:

    • $embedCodeAssetField -> This is the default embedcode that goes in all Asset types, and required even for Download/Sync as the Media Library uses this field for thumbnail display.
    • $localFileAssetField -> Used for local file assets. There is an example in the image plugin where the default managed file field is replaced with the imagefield.
    • $assetFieldFormatterConfiguration -> An array of the field formatter configuration keyed by the field names for a particular Asset type. Each plugin can override this configuration for their own format. Even though the image plugin adds a new field, it'll get called as the active one because $localFileAssetField is overridden

    The two main MediaSourceTypeBase class methods you'll be interested in is getActiveFieldName and getFormatter.
    getActiveFieldName: This method gets the active field based on whether 'download assets' is checked or not. If you have a different workflow for your plugin, you could override this method to return a field regardless of the Asset configuration.
    getFormatter: Gets the specific formatter settings from the assetFieldFormatterConfiguration dataset.

    Hopefully this achieves what you're looking for here. Marking 'needs review' to get validation what we've built here meets your needs.

  • πŸ‡ΊπŸ‡ΈUnited States japerry KVUO

    Marking fixed since this is in 1.1 now.

Production build 0.71.5 2024