Problem/Motivation

I can't see a reason why this shouldn't be done or would be a difficult feat. This is already the goal of media_entity_embeddable_video, but the only touch point for the integration is a single plugin, the rest is a whole duplicated system of plugins and field types. For the same reason we implemented WYSIWYG integration (to consolidate video embeds into a single ecosystem/feature set), I don't see why VEF wouldn't implement this plugin and bring the existing feature set to media.

Proposed resolution

Implement the plugin type in a sub-module called video_embed_media (not a seperate project, there already seems like way too many modules to install when using media).

Remaining tasks

Validate the assumptions, talk with slashrsm and patch.

User interface changes

TBD.

API changes

TBD.

Data model changes

TBD.

Comments

Sam152 created an issue. See original summary.

sam152’s picture

Status: Active » Needs review
StatusFileSize
new7.93 KB

Initial attempt.

Status: Needs review » Needs work

The last submitted patch, 2: 2688927-media-entity-integration-2.patch, failed testing.

The last submitted patch, 2: 2688927-media-entity-integration-2.patch, failed testing.

The last submitted patch, 2: 2688927-media-entity-integration-2.patch, failed testing.

The last submitted patch, 2: 2688927-media-entity-integration-2.patch, failed testing.

The last submitted patch, 2: 2688927-media-entity-integration-2.patch, failed testing.

  • Sam152 committed b083e5c on 8.x-1.x
    Issue #2688927 by Sam152: Commit test dependencies directly to HEAD.
    
sam152’s picture

Status: Needs work » Needs review
StatusFileSize
new7.89 KB

After test_dependencies was committed to head.

sam152’s picture

I've spoken with slashrsm on IRC. My thoughts at this stage are that for VEF to integrate into media to the same level as media_entity_embedded_video, all that was required was a <10kb patch, which includes tests and extra code to create fields for the user as a convenience.

With that in mind, with this patch included, I see VEF and MEEV as solving the same problem. Obviously having worked on and polished VEF + the associated contrib for the last 4 months, I'm interested in see how it can fit into the media picture while continuing to be a stand-alone field where required.

The media team is of course well within their rights to continue to build and support MEEV and build it in any direction required by media_entity, but I believe this falls into the bucket of duplicate effort at this stage. I'd be happy to work on any issues on an ongoing basis to keep VEF up to date with media_entity HEAD as well as work on any improvements required by the media team.

If this is a welcome contribution to reduce the amount of modules/code that the media guys are maintaining, then we should discuss bringing the integration up to snuff, otherwise, I'll probably merge this for the reasons described in #1 and exist alongside MEEV.

slashrsm’s picture

Status: Needs review » Needs work

Thank you for your work. This is very exciting!

  1. +++ b/modules/video_embed_media/src/Plugin/MediaEntity/Type/VideoEmbedField.php
    @@ -0,0 +1,146 @@
    +
    +  /**
    +   * The function that is invoked during the insert of media bundles.
    +   *
    +   * @param $media_bundle_id
    +   */
    +  public static function createVideoEmbedField($media_bundle_id) {
    +    if (!$storage = FieldStorageConfig::loadByName('media', static::VIDEO_EMBED_FIELD_NAME)) {
    +      FieldStorageConfig::create([
    +        'field_name' => static::VIDEO_EMBED_FIELD_NAME,
    +        'entity_type' => 'media',
    +        'type' => 'video_embed_field',
    +      ])->save();
    +    }
    +    FieldConfig::create([
    +      'entity_type' => 'media',
    +      'field_name' => static::VIDEO_EMBED_FIELD_NAME,
    +      'label' => 'Video URL',
    +      'required' => TRUE,
    +      'bundle' => $media_bundle_id,
    +    ])->save();
    +    // Make the field visible on the form display.
    +    $form_display = entity_get_form_display('media', $media_bundle_id, 'default');
    +    $form_display->setComponent(static::VIDEO_EMBED_FIELD_NAME, [
    +      'type' => 'video_embed_field_textfield',
    +    ])->save();
    +  }
    

    Approach that media_entity takes is to make main field configurable. Instead of pre-creating it we allow site builder to decide how entity data model looks like and determine that through configuration.

  2. +++ b/modules/video_embed_media/src/Plugin/MediaEntity/Type/VideoEmbedField.php
    @@ -0,0 +1,146 @@
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function providedFields() {
    +    return [
    +      'embed_code' => $this->t('Video Embed Code'),
    +    ];
    +  }
    

    If we'd be deprecating media_entity_embeddable_video I'd like list of provided fields to be equivalent. See https://github.com/drupal-media/media_entity_embeddable_video/blob/8.x-1...

  3. +++ b/modules/video_embed_media/video_embed_media.info.yml
    @@ -0,0 +1,8 @@
    +name: Video Embed Media
    +type: module
    +description: 'Integrates embedded videos into the Drupal Media Entity module.'
    +package: Field types
    +core: 8.x
    +dependencies:
    +  - media_entity
    +  - video_embed_field
    

    This module essentially provides only Media type plugin. I don't see any reason why this couldn't live in VEF.

  4. If we want to deprecate media_entity_embeddable_video we need to figure out how to handle sites that are using it. We could provide upgrade path or keep support for text/link fields. I am not strongly opinionated on that. The only thing that is important for me is that we don't leave current users behind.

In general I am in favour of merging the two modules. It will reduce fragmentation and make ecosystem more sustainable. The two most important things that I'd like to achieve before we do that is to handle existing sites and achieve feature parity. I am available on IRC if needed.

sam152’s picture

Hi slashrsm,

Appreciate the review.

1. I found this user experience a bit confusing and assumed that someone creating a "video" bundle wanted a video field seemed like a safe assumption. I'll defer to the standard way of handling things however.
2. Good point!
3. We'll see what size it ends up after #4.
4. Fair enough. I'll see what I can come up with for this.

I'm am also excited to reduce the fragmentation. Lets see how far we can get with this.

sam152’s picture

Status: Needs work » Needs review
StatusFileSize
new20.87 KB

Only half way through the above feedback, just just need a testbot run.

sam152’s picture

Status: Needs review » Needs work

The last submitted patch, 13: 2688927-media-entity-integration-13.patch, failed testing.

The last submitted patch, 13: 2688927-media-entity-integration-13.patch, failed testing.

The last submitted patch, 13: 2688927-media-entity-integration-13.patch, failed testing.

The last submitted patch, 13: 2688927-media-entity-integration-13.patch, failed testing.

The last submitted patch, 13: 2688927-media-entity-integration-13.patch, failed testing.

  • Sam152 committed 0d5381a on 8.x-1.x
    Issue #2688927 by Sam152: Test dependencies to HEAD
    
sam152’s picture

Status: Needs work » Needs review
StatusFileSize
new20.61 KB

Test dependencies to HEAD.

sam152’s picture

StatusFileSize
new20.61 KB
new541 bytes

Fixed test namespace.

sam152’s picture

StatusFileSize
new0 bytes

This patch is ready for review once more. It addresses the feedback in #11.

  1. For users with media_entity_embedded_video installed, if you install video_embed_media:
    1. All existing media bundles will have their type updated.
    2. A new video embed field will be added to the bundle.
    3. The field that was configured to store the video URL before, will be copied to the new field.
  2. The tests assert the module can be installed, the data is upgraded and media_entity_embedded_video disables cleanly. Aside from perhaps display related config, this should allow users to cleanly install/uninstall the modules without having to updated any media entities.
  3. I've added a config form for choosing which video field should be used for the media entity. I've still kept the automatic creation, but updated the message to make it more clear what is going on:

    A video embed field will be created on this media bundle when you save this form. You can return to this configuration screen to alter the video field used for this bundle, or you can use the one provided.
    This message disappears once a field is chosen or created.

  4. The fields from the previous plugins are available verbatim on the new plugin, so that when the type is changed any existing config should work as normal. There are some tests for this as well.

Let me know what you think.

Status: Needs review » Needs work

The last submitted patch, 23: 2688927-media-entity-integration-23.patch, failed testing.

The last submitted patch, 23: 2688927-media-entity-integration-23.patch, failed testing.

The last submitted patch, 23: 2688927-media-entity-integration-23.patch, failed testing.

sam152’s picture

Status: Needs work » Needs review
StatusFileSize
new23.24 KB

Real patch this time.

The last submitted patch, 23: 2688927-media-entity-integration-23.patch, failed testing.

The last submitted patch, 23: 2688927-media-entity-integration-23.patch, failed testing.

slashrsm’s picture

  1. +++ b/modules/video_embed_media/src/Plugin/MediaEntity/Type/VideoEmbedField.php
    @@ -0,0 +1,200 @@
    +/**
    + * @file
    + * Contains \Drupal\video_embed_media\Plugin\MediaEntity\Type\VideoEmbedField.
    + */
    

    This @file blocks are not required any more. More a FYI than a blocker.

  2. +++ b/modules/video_embed_media/src/UpgradeManager.php
    @@ -0,0 +1,83 @@
    +    $media_entities = $this->entityQuery->get('media')->condition('bundle', $bundle->id())->execute();
    +    foreach ($media_entities as $media_entity) {
    

    Number of items in this result set can be very large in general. I think it would be great idea to support batch processing to prevent timeouts and other problem.

    I am OK if we make this a follow-up.

  3. +++ b/modules/video_embed_media/src/UpgradeManager.php
    @@ -0,0 +1,83 @@
    +    // Copy the existing media bundle field value to the new field value.
    +    $existing_url = $media_entity->{$type_configuration['source_field']}->getValue();
    +    $media_entity->{VideoEmbedField::VIDEO_EMBED_FIELD_DEFAULT_NAME} = $existing_url;
    +    $media_entity->save();
    

    While this will correctly migrate values stored in text fields it won't succeed with the ones stored in link fields (both types are supported in MEEV). I manually tested it and that also confirmed this issue.

I manually tested it and it works nicely.

Great job. Almost there. When we commit this it would make sense to release a new version on VEF. After that we can put a deprecation message on MEEV project page.

It would also make sense to update our guide at that point.

slashrsm’s picture

Status: Needs review » Needs work
sam152’s picture

Status: Needs work » Needs review
StatusFileSize
new1.01 KB
new30.02 KB
  1. Thanks for the heads up.
  2. Good point. I think a follow-up works, especially given most sites are still in early stages and probably don't have thousands of videos.
  3. Thanks for pointing that out. Fixed (see interdiff).

I think after this gets in I'll tag RC6 and then 1.0 shortly after.

I'd be happy to write any docs required. Will submit PRs the github project after this goes RTBC.

sam152’s picture

StatusFileSize
new23.4 KB

Merged branch with 8.x-1.x. Interdiff is still the same.

sam152’s picture

Status: Needs review » Needs work

The last submitted patch, 33: 2688927-media-entity-integration-32.patch, failed testing.

sam152’s picture

Status: Needs work » Needs review

Fail is in HEAD.

slashrsm’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. Should we create follow-ups for batch migration and d8 guide update?

  • Sam152 committed 1be23c7 on 8.x-1.x
    Issue #2688927 by Sam152, slashrsm: Integrate with the media_entity...
sam152’s picture

Status: Reviewed & tested by the community » Fixed
slashrsm’s picture

Great job. Added a message to MEEV project page. https://www.drupal.org/project/media_entity_embeddable_video

Status: Fixed » Closed (fixed)

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

dadderley’s picture

I inherited a site that had hundreds of media entities of the video type created with 'Media entity embeddable video 8.x-1.0-beta2'.
Installing the latest dev version of this module (Video Embed Field 8.x-1.5+4-dev (2017-Dec-01)) saved me a whole world of hurt.
Thank you very much.

georg_nordhausen’s picture

Category: Feature request » Support request

Hi, I am trying to upgrade a drupal 8.9.20 system which heavily relies on the media_entity_embeddable_video module. I tried all the steps described here but the migration seems to srew up the database, so that all embedded videos disappear.
It seems like this is a two step pocess. First migration from media_entity_embeddable_video to VEF media entity 1.x/2.x and then migration to the core media module.
Does any of you have a hint what to do or where to look to solve this?