Responsive support (data-width)

Created on 16 August 2017, almost 7 years ago
Updated 12 January 2024, 6 months ago

Facebook provides data-width option to control the width of the iframe: https://developers.facebook.com/docs/plugins/embedded-posts/

I think we should provide an option to the formatter to let the site builder customize this.

Patch will follow.

✨ Feature request
Status

Needs work

Version

4.0

Component

Code

Created by

πŸ‡«πŸ‡·France SylvainM

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΈπŸ‡°Slovakia kaszarobert

    Needs a reroll since 2 years have passed and the module changed a little bit.

  • πŸ‡«πŸ‡·France Nicolas S. Lyon, France

    Here is a new patch to apply to current 4.x version

  • Status changed to Needs review 9 months ago
  • πŸ‡«πŸ‡·France Nicolas S. Lyon, France
  • Status changed to Needs work 6 months ago
  • πŸ‡ΈπŸ‡°Slovakia kaszarobert

    Because the module has changed a bit, a new approach should be set:
    - the result in $oembedResult = $source->getMetadata($media, 'html'); is no longer a #markup but a render array. Where '#is_iframe' is TRUE if someone uses the Oembed API, and FALSE if someone uses Embedded Posts.
    - For the Oembed API, the current approach of string replace should be fine.
    - For Embedded Posts, the $oembedResult is going to be a render array like this:

          $oembedResponse['html'] = [
            '#theme' => 'media_entity_facebook',
            '#url' => $resource_url,
            '#script_attributes' => $scriptAttributes,
            '#is_iframe' => $isIFrame,
            '#fb_sdk_langcode' => $fbLangcode,
          ];
    
          $oembedResponse['author_name'] = 'Facebook';
          $oembedResponse['width'] = '500';
          $oembedResponse['height'] = 'auto';
          $oembedResponse['url'] = $resource_url;
          return $oembedResponse;
    

    The hardcoded width should be altered in FacebookEmbedFormatter::viewElements() in $oembedResult. And also, a new '#data-width' parameter should be added to the render array, to media_entity_facebook_theme() hook, and web/modules/contrib/media_entity_facebook/templates/media-entity-facebook.html.twig template so that the data-width value is rendered properly.

Production build 0.69.0 2024