Request Support for Custom Media Types

Created on 24 May 2023, over 1 year ago
Updated 9 June 2023, over 1 year ago

Problem/Motivation

I ran through the documentation to test this module out. Very cool module, BTW. In order to not interfere with the core "Remote video" media type, I set up a custom media type based on the core "Remote video" type.

Steps to reproduce

The MicroModal functionality didn't manifest on the content page, of course. After running Xdebug I discovered the module file MicromodalFieldFormatter.php is hard coded to key in on the default `field_media_oembed_video` field. I hacked the module code and was able to get it working for my demo as shown:

      // Load the media item.
      $media_id = $item->getEntity()->id();
      $media = $this->entityTypeManager->getStorage('media')->load($media_id);

      // If the media loaded successfully, continue with the formatting.
      if (!empty($media) && !empty($formatter_type)) {

        // if (array_key_exists('field_media_oembed_video', $media->getFields())) {
        if (array_key_exists('field_media_oembed_video_2', $media->getFields())) {

          // Grab the remote video URL.
          // $video_url = $media->getFields()['field_media_oembed_video']->getValue()[0]['value'];
          $video_url = $media->getFields()['field_media_oembed_video_2']->getValue()[0]['value'];

Proposed resolution

Extend the module to include an admin UI for selecting additional media types, or possibly to specify which media_oembed fields to parse. There may be an even smarter way to do this, since I'm just superficially familiar with the module code at this point.

Remaining tasks

[ ] Chat about the options and if its worthwhile

User interface changes

* Possible admin UI page addition

API changes

None

Data model changes

Unknown

✨ Feature request
Status

Needs work

Version

1.0

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States axb

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

Comments & Activities

  • Issue created by @axb
  • πŸ‡ΊπŸ‡ΈUnited States axb

    Switching to minor. This is no big deal.

  • Assigned to scott_earnest
  • πŸ‡ΊπŸ‡ΈUnited States scott_earnest
  • πŸ‡ΊπŸ‡ΈUnited States axb

    Let me know if I can help at all. I could try to write some tests or something.

  • πŸ‡ΊπŸ‡ΈUnited States scott_earnest

    Thank you @alexb7217 - i have time set aside to work on this next week and appreciate your help.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States scott_earnest

    Hi there @alexb7217 -

    I think this is a good suggestion. I will continue work on this at a later date, but my idea was the formatter would be able to get the fieldname from it's definition. I was thinking something like:

          // If the media loaded successfully, continue with the formatting.
          if (!empty($media) && !empty($formatter_type)) {
    
            $fieldname = $this->fieldDefinition->getName();
    
            if (array_key_exists($fieldname, $media->getFields())) {
    
              // Grab the remote video URL.
              $video_url = $media->getFields()[$fieldname]->getValue()[0]['value'];
    
              // Use these to generate the URL for local oembed iframe.
              $request = new RequestContext($video_url);
    

    needs some work as that introduces deprecations to other field types (like image etc)

    I will keep this open and hope to get back to it soon. thank you for the suggestion!

Production build 0.71.5 2024