When multiple players are displayed (e.g. an unlimited cardinality field) each player has a duplicate ID.

Patch to follow.

CommentFileSizeAuthor
#6 youtube-multiple-ids-2268873-6.patch5.44 KBAnonymous (not verified)
#1 youtube-multiple-ids-2268873-1.patch2.87 KBmsmithcti

Comments

msmithcti’s picture

Status: Active » Needs review
StatusFileSize
new2.87 KB

Attached is a patch that moves the configurable ID to a class and uses drupal_html_id() to ensure IDs are unique. This will break and JS/CSS targeting a second or greater video embed as drupal_html_id() will append an integer onto the ID name. The first video on the page should not be affected by this change.

guschilds’s picture

splatio,

Thanks for this. It definitely makes sense. A couple thoughts:

+  // Legacy variable, @see youtube_update_7101().
   variable_del('youtube_playerid');

Why not just delete this variable when creating the youtube_playerclass variable in youtube_update_7101 and then remove it completely from youtube_uninstall()?

+/**
+ * Implements hook_update_N().
+ */

This is what is shown when updating the db with drush or otherwise so it typically makes more sense to write what is actually happening. See views.install for an example.

-  $form['youtube_global']['youtube_playerid'] = array(
+  $form['youtube_global']['youtube_playerclass'] = array(
     '#type' => 'textfield',
     '#title' => t('Javascript API Player ID'),
-    '#default_value' => variable_get('youtube_playerid', 'youtube-field-player'),
+    '#default_value' => variable_get('youtube_playerclass', 'youtube-field-player'),
     '#states' => array(
       'visible' => array(
         ':input[name="youtube_enablejsapi"]' => array('checked' => TRUE),

Probably want to update the title of this option. Also wondering if we remove the visibility state so it is always visible. Maybe even add a description explaining that the player's ID will be based on this value, which brings me to my final thought:

-  $output = '<iframe id="' . $playerid . '" width="' . $dimensions['width'] . '"
+  $output = '<iframe id="' . drupal_html_id('youtube-field-player') . '" class="' . $player_class . '" width="' . $dimensions['width'] . '"

Why not just base the ID off $player_class with drupal_html_id($player_class)? That may reduce confusion.

Let me know your thoughts. I can re-roll the patch with these changes if you'd like. Definitely makes sense to commit this in some form, though!

Thanks again,
Gus

guschilds’s picture

Status: Needs review » Needs work

  • guschilds committed 111554e on 7.x-1.x
    Issue #2268873 by splatio, guschilds: Fixed bug where multiple players...
guschilds’s picture

Title: Multiple Players Causing Duplicate IDs » [8.x] Multiple Players Causing Duplicate IDs
Version: 7.x-1.x-dev » 8.x-1.x-dev

A variation of the patch in #2 was committed to the 7.x-1.x branch and will be available in the next release.

I'm marking this as "[8.x]" in the title and version to ensure that this gets fixed for the 8.x branch as well.

Anonymous’s picture

Assigned: Unassigned »
Status: Needs work » Needs review
StatusFileSize
new5.44 KB

This patch fixes the problem in 8.x. Please apply the patch from #22 of #2213867: [8.x blocker] 8.x branch is out of date with current Drupal 8 release before this one.

  • guschilds committed 9918538 on 8.x-1.x
    Issue #2268873 by pferlito, guschilds: Added handling of player_class to...
  • guschilds committed 9a8ce57 on 8.x-1.x authored by pferlito
    Issue #2268873 by pferlito, guschilds: Fixed bug where multiple players...
guschilds’s picture

Status: Needs review » Fixed

I had to reroll the patch in #6 because it no longer applied (I also think there was also some stuff left in there from another issue). Once I did, I successfully tested and committed your work. You did miss setting the variable when the config form is saved, so I added that in another commit.

Thanks again for your work here and patience as I slowly get to testing everything!

guschilds’s picture

Title: [8.x] Multiple Players Causing Duplicate IDs » Multiple Players Causing Duplicate IDs

Status: Fixed » Closed (fixed)

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