Embedding video with entity embed in layout builder + CKEditor5

Created on 6 May 2024, 10 months ago

Problem/Motivation

I'm using Drupal core 9.5.x with Layout builder and CKEditor5

Steps to reproduce

1. Create a page with layout builder
2. Try adding text block, in the body field (CKEditor5) embed video and select any Brightcove video
3. Save the block
4. Then save the page
5. Now, when you edit the block, you will see that CKEditor is missing
6. When you check the console log, it says CKEditor failed to load

Proposed resolution

With my initial investigation it is caused by the video script being loaded in the CKEditor on layout builder pages from following template:

{#
/**
 * @file brightcove-video-player.html.twig
 * Default theme implementation to display Brightcove video player.
 *
 * This template is used when dispalying the Brightcove video player.
 *
 * Available variables:
 *   - account (string): Account ID.
 *   - data_usage (string): Module version indicator.
 *   - embed (string): Parent/child relationship, where parent is always
 *                     default, and child players has the ID of the parent player.
 *   - id (int): ID of the Brightcove video or playlist.
 *   - is_playlist (bool): Indicates whether it is a playlist player or a single video player.
 *   - player (string): Player ID.
 *   - type (string): The type of the player, playlist or video.
 *   - video_id (string): Video ID.
 *
 * @ingroup themeable
 */
#}
<div class="brightcove-player sizing-responsive">
  <div style="max-width: {{- max_width ~ units -}};">
    <video-js class="vjs-fluid"
      controls=""
      data-account="{{- account -}}"
      data-embed="{{- embed -}}"
      data-player="{{- player -}}"
      data-usage="{{- data_usage -}}"
      data-{{- type -}}-id="{{- id -}}"
    ></video-js>
  </div>
  {% if is_playlist %}
    <ol class="vjs-playlist"></ol>
  {% endif %}
  <script src="//players.brightcove.net/{{- account -}}/{{- player -}}_{{- embed -}}/index.min.js"></script>
</div>

Remaining tasks

We need a find a way, where we need to create a placeholder for video in layout builder without video script.

πŸ› Bug report
Status

Active

Version

3.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States imran1217

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

Comments & Activities

  • Issue created by @imran1217
  • πŸ‡­πŸ‡ΊHungary yce

    Hi @imran1217,

    Can you please elaborate on the 2nd step?

    I've tried to add the video to ckeditor using the media module, but I only see the video's title, the player does not load at all.

    However the script shouldn't run in the ckeditor anyway (on the node edit form), I would rather display the preview or thumbnail image in the editor instead, much safer. It may require some customization though.

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

    Hi @ yce β†’ ,

    Can you please elaborate on the 2nd step?

    On pages where the layout builder is enabled, CKEditor5 fields are available only within blocks. Therefore, I provided an example of adding a text block that includes a body field, which allows you to embed videos.

    Please refer attach screenshot for more details.

    I've tried to add the video to ckeditor using the media module, but I only see the video's title, the player does not load at all.

    Not sure what could be the reason but in my case it works fine.

    However the script shouldn't run in the ckeditor anyway (on the node edit form), I would rather display the preview or thumbnail image in the editor instead, much safer. It may require some customization though.

    I am already using this approach as a workaround and would like the Brightcove team to adjust the player script to work with CKEditor5 as well (on the node edit form).

    Thanks!

  • πŸ‡­πŸ‡ΊHungary yce

    I don't see the benefit why it would be good to render the video player inside the ckeditor, so I would say it is works as designed.

    You can also override the template of the video from your theme if needed and create custom displays to customize how it should be rendered.

  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    For the OP, I ran into this as well and could not get Brightcove's iFrame to work, so I ended up with this:

    In mytheme.theme.

    /**
     * Implements hook_preprocess_brightcove_player_responsive()
     *
     * We cannot render Brightcove inside CKEditor.
     */
    function mytheme_theme_preprocess_brightcove_player_responsive(&$variables) {
      $variables['preview'] = FALSE;
      $route = \Drupal::routeMatch();
      if ($route instanceof RouteMatchInterface && $route->getRouteName() === 'embed.preview') {
        $variables['preview'] = TRUE;
      }
    }
    

    In mytheme/templates/brightcove/brightcove-player-responsive.html.twig

    
    {% if preview %}
      {% set img_url = '/' ~ directory ~ '/imgs/video-thumbnail-.jpg' %}
    
      <div class="brightcove-player sizing-responsive">
        <div style="max-width: {{- max_width ~ units -}};">
          <img class="video__thumbnail" src="{{ img_url }}">
        </div>
      </div>
    {% else %}
      <div class="brightcove-player sizing-responsive">
        <div style="max-width: {{- max_width ~ units -}};">
          <video-js class="vjs-fluid"
                    controls=""
                    data-account="{{- account -}}"
                    data-embed="{{- embed -}}"
                    data-player="{{- player -}}"
                    data-usage="{{- data_usage -}}"
                    data-{{- type -}}-id="{{- id -}}"
          ></video-js>
        </div>
        {% if is_playlist %}
          <ol class="vjs-playlist"></ol>
        {% endif %}
        <script src="//players.brightcove.net/{{- account -}}/{{- player -}}_{{- embed -}}/index.min.js"></script>
      </div>
    {% endif %}
    
    
Production build 0.71.5 2024