Commit 0c977a20 authored by Todd Zebert's avatar Todd Zebert Committed by jenlampton

Issue #3034836 by Todd Zebert: Support delegate autoplay permission iframe...

Issue #3034836 by Todd Zebert: Support delegate autoplay permission iframe policy attribute, etc. (patch included)
parent 229ab9fa
...@@ -280,6 +280,8 @@ function youtube_field_formatter_info() { ...@@ -280,6 +280,8 @@ function youtube_field_formatter_info() {
'youtube_autohide' => FALSE, 'youtube_autohide' => FALSE,
'youtube_iv_load_policy' => FALSE, 'youtube_iv_load_policy' => FALSE,
'youtube_playsinline' => FALSE, 'youtube_playsinline' => FALSE,
'youtube_allow_autoplay' => FALSE,
'youtube_allow_fullscreen' => FALSE,
), ),
), ),
// This formatter just displays a thumbnail for your video. // This formatter just displays a thumbnail for your video.
...@@ -374,6 +376,16 @@ function youtube_field_formatter_settings_form($field, $instance, $view_mode, $f ...@@ -374,6 +376,16 @@ function youtube_field_formatter_settings_form($field, $instance, $view_mode, $f
'#title' => t('This parameter controls whether videos play inline or fullscreen in an HTML5 player on iOS (playsinline).'), '#title' => t('This parameter controls whether videos play inline or fullscreen in an HTML5 player on iOS (playsinline).'),
'#default_value' => $settings['youtube_playsinline'], '#default_value' => $settings['youtube_playsinline'],
); );
$element['youtube_allow_autoplay'] = array(
'#type' => 'checkbox',
'#title' => t('The autoplay feature controls access to autoplay of media requested through the HTMLMediaElement interface (allow autoplay).'),
'#default_value' => $settings['youtube_allow_autoplay'],
);
$element['youtube_allow_fullscreen'] = array(
'#type' => 'checkbox',
'#title' => t('The fullscreen feature controls whether the requestFullscreen() method is allowed to request fullscreen (allow fullscreen).'),
'#default_value' => $settings['youtube_allow_fullscreen'],
);
} }
if ($display['type'] == 'youtube_thumbnail') { if ($display['type'] == 'youtube_thumbnail') {
...@@ -435,6 +447,8 @@ function youtube_field_formatter_settings_summary($field, $instance, $view_mode) ...@@ -435,6 +447,8 @@ function youtube_field_formatter_settings_summary($field, $instance, $view_mode)
$settings['youtube_autohide'], $settings['youtube_autohide'],
$settings['youtube_iv_load_policy'], $settings['youtube_iv_load_policy'],
$settings['youtube_playsinline'], $settings['youtube_playsinline'],
$settings['youtube_allow_autoplay'],
$settings['youtube_allow_fullscreen'],
); );
foreach ($parameters as $parameter) { foreach ($parameters as $parameter) {
...@@ -506,6 +520,8 @@ function youtube_field_formatter_view($entity_type, $entity, $field, $instance, ...@@ -506,6 +520,8 @@ function youtube_field_formatter_view($entity_type, $entity, $field, $instance,
'#autohide' => array_key_exists('youtube_autohide', $display['settings']) ? $display['settings']['youtube_autohide'] : FALSE, '#autohide' => array_key_exists('youtube_autohide', $display['settings']) ? $display['settings']['youtube_autohide'] : FALSE,
'#iv_load_policy' => array_key_exists('youtube_iv_load_policy', $display['settings']) ? $display['settings']['youtube_iv_load_policy'] : FALSE, '#iv_load_policy' => array_key_exists('youtube_iv_load_policy', $display['settings']) ? $display['settings']['youtube_iv_load_policy'] : FALSE,
'#playsinline' => array_key_exists('youtube_playsinline', $display['settings']) ? $display['settings']['youtube_playsinline'] : FALSE, '#playsinline' => array_key_exists('youtube_playsinline', $display['settings']) ? $display['settings']['youtube_playsinline'] : FALSE,
'#allow_autoplay' => array_key_exists('youtube_allow_autoplay', $display['settings']) ? $display['settings']['youtube_allow_autoplay'] : FALSE,
'#allow_fullscreen' => array_key_exists('youtube_allow_fullscreen', $display['settings']) ? $display['settings']['youtube_allow_fullscreen'] : FALSE,
); );
} }
break; break;
...@@ -684,6 +700,8 @@ function youtube_theme($existing, $type, $theme, $path) { ...@@ -684,6 +700,8 @@ function youtube_theme($existing, $type, $theme, $path) {
'autohide' => FALSE, 'autohide' => FALSE,
'iv_load_policy' => FALSE, 'iv_load_policy' => FALSE,
'playsinline' => FALSE, 'playsinline' => FALSE,
'allow_autoplay' => FALSE,
'allow_fullscreen' => FALSE,
), ),
'file' => 'youtube.theme.inc', 'file' => 'youtube.theme.inc',
), ),
......
...@@ -24,6 +24,10 @@ function theme_youtube_video($variables) { ...@@ -24,6 +24,10 @@ function theme_youtube_video($variables) {
$iv_load_policy = array_key_exists('iv_load_policy', $variables) ? $variables['iv_load_policy'] : FALSE; $iv_load_policy = array_key_exists('iv_load_policy', $variables) ? $variables['iv_load_policy'] : FALSE;
$playsinline = array_key_exists('playsinline', $variables) ? $variables['playsinline'] : FALSE; $playsinline = array_key_exists('playsinline', $variables) ? $variables['playsinline'] : FALSE;
$allow = array();
if (array_key_exists('allow_autoplay', $variables)) $allow[] = 'autoplay';
if (array_key_exists('allow_fullscreen', $variables)) $allow[] = 'fullscreen';
// Get YouTube settings. // Get YouTube settings.
$suggest = variable_get('youtube_suggest', TRUE); $suggest = variable_get('youtube_suggest', TRUE);
$modestbranding = variable_get('youtube_modestbranding', FALSE); $modestbranding = variable_get('youtube_modestbranding', FALSE);
...@@ -109,10 +113,19 @@ function theme_youtube_video($variables) { ...@@ -109,10 +113,19 @@ function theme_youtube_video($variables) {
// Alternative content for browsers that don't understand iframes (WCAG). // Alternative content for browsers that don't understand iframes (WCAG).
$alternative_content = l($player_title, $src); $alternative_content = l($player_title, $src);
$output = '<iframe id="' . drupal_html_id($player_class) . '" class="' . $player_class . '" $attributes = array(
width="' . $dimensions['width'] . '" height="' . $dimensions['height'] . '" 'id' => drupal_html_id($player_class),
src="' . $src . '" title="' . $player_title . '" frameborder="0" 'class' => $player_class,
allowfullscreen>' . $alternative_content . '</iframe>'; 'width' => $dimensions['width'],
'height' => $dimensions['height'],
'src' => $src,
'title' => $player_title,
'frameborder' => "0",
'allowfullscreen' => "",
"allow" => implode('; ', $allow),
);
$output = '<iframe ' . drupal_attributes($attributes) . '>' . $alternative_content . '</iframe>';
if ($size == 'responsive') { if ($size == 'responsive') {
$output = '<div class="youtube-container--responsive">' . $output . '</div>'; $output = '<div class="youtube-container--responsive">' . $output . '</div>';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment