Host entity type / bundle may not be "media/video" hard-coded

Created on 24 April 2025, 4 days ago

Problem/Motivation

The host entity type and bundle may not be hard-coded as it's currently the case in:
https://git.drupalcode.org/project/vidstack_player/-/blob/1.x/src/Plugin...

Instead the field ($this) needs to be asked for the host entity, I think? Or am I missing something here?

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

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

Comments & Activities

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

    I guess something like

      // Get the field definition.
      $field_definition = $this->getFieldDefinition();
    
      // Retrieve the entity type ID and bundle.
      $entity_type = $field_definition->getTargetEntityTypeId();
      $bundle = $field_definition->getTargetBundle();
    

    might be needed?

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

    I'm also unsure why this hard-coded implementation exists:

      /**
       * {@inheritdoc}
       */
      public static function getMediaType() {
        return 'video';
      }
    

    but didn't check it deeper, yet. Please do that. Maybe because by FileMediaFormatterBase this is more than just a file formatter... mhm. Anyway, if a custom "myvideo" media type exists with a video field, it should also work, but hard-coding would break it, right?

  • First commit to issue fork.
  • 🇩🇪Germany Grevil

    Also, I am a bit unsure, when the Remote Formatter should be applicable:

      public static function isApplicable(FieldDefinitionInterface $field_definition) {
        if ($field_definition->getTargetEntityTypeId() !== 'media') {
          return FALSE;
        }
    
        if (parent::isApplicable($field_definition)) {
          $media_type = $field_definition->getTargetBundle();
    
          if ($media_type) {
            $media_type = MediaType::load($media_type);
            return $media_type && $media_type->getSource() instanceof OEmbedInterface;
          }
        }
        return FALSE;
      }
    

    Especially the "OEmbedInterface" part makes this very restricted to use.

  • @grevil opened merge request.
  • 🇩🇪Germany Anybody Porta Westfalica

    @grevil re #6 LGTM so far... let's keep this for now.

  • 🇩🇪Germany Grevil

    Ok, please review then!

  • 🇩🇪Germany Anybody Porta Westfalica

    Nice!

  • 🇩🇪Germany Anybody Porta Westfalica
Production build 0.71.5 2024