Improve the way that JS is attached

Created on 18 October 2023, about 1 year ago
Updated 28 February 2024, 10 months ago

Problem/Motivation

At present inline javascript is being embedded within the template responsible for rendering the Facebook post. If you have more than one Facebook post being rendered on a page the JS is being executed more than once (which is unnecessary). Ideally a library(s) should be attached.

Steps to reproduce

Proposed resolution

Use a dynamic library for the SDK to accomodate the active language. Use a library to initialise the SDK. Remove the placeholder element from the template in favour of putting the URL within the Facebook post element - this will be substituted by the SDK, but will exist in CKEditor.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Needs review

Version

4.0

Component

Code

Created by

πŸ‡¦πŸ‡ΊAustralia mortim07

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

Comments & Activities

  • Issue created by @mortim07
  • Status changed to Needs review about 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Patch Failed to Apply
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Patch Failed to Apply
  • Issue was unassigned.
  • Status changed to Needs work 12 months ago
  • πŸ‡ΈπŸ‡°Slovakia kaszarobert

    2 things need to be checked:

    1. In media_entity_facebook_library_info_build():
    + $language_id = \Drupal::languageManager()->getCurrentLanguage()->getId() ?? 'en_US';

    We cannot really use this as FB SDK's langcodes differ from Drupal's. The proper langcode-map is already there in FacebookFetcher $langcodes array. That array needs to be refactored to a service that contains one public method getFacebookSdkLangcodeByDrupalLangcode($drupalLangcode) and that should be called in this hook.

    2. Also, in the patch does this library load for every single page? It should load only if a Facebook media is rendered.

    Also, note for myself: if we change the way how we attach libraries, then the Facebook cookie consent module we made β†’ also needs a new way of blocking the FB SDK script.

  • πŸ‡¦πŸ‡ΊAustralia mortim07

    @kaszarobert Thanks for looking at the patch.

    In regards to point 2. It only loads when the template media-entity-facebook is rendered and is_frame is FALSE.

    I'll take a look at the language mapping and make the necessary changes.

  • πŸ‡¦πŸ‡ΊAustralia mortim07

    @kaszarobert Sorry for the delay in getting this done.

  • Status changed to Needs review 10 months ago
  • πŸ‡¦πŸ‡ΊAustralia mortim07
Production build 0.71.5 2024