diff --git a/youtube.module b/youtube.module index 3bdd7d8..902362a 100644 --- a/youtube.module +++ b/youtube.module @@ -131,7 +131,10 @@ function youtube_field_formatter_info() { 'youtube_video' => array( 'label' => t('YouTube video'), 'field types' => array('youtube'), - 'settings' => array('youtube_size' => '420x315'), // TODO + 'settings' => array( + 'youtube_size' => '420x315', + 'youtube_autoplay' => variable_get('youtube_autoplay', FALSE), + ), ), // This formatter just displays a thumbnail for your video. 'youtube_thumbnail' => array( @@ -158,6 +161,11 @@ function youtube_field_formatter_settings_form($field, $instance, $view_mode, $f '#options' => youtube_size_options(), '#default_value' => $settings['youtube_size'], ); + $element['youtube_autoplay'] = array( + '#type' => 'checkbox', + '#title' => t('Autoplay?'), + '#default_value' => $settings['youtube_autoplay'], + ); } if ($display['type'] == 'youtube_thumbnail') { @@ -189,6 +197,9 @@ function youtube_field_formatter_settings_summary($field, $instance, $view_mode) else { $summary = t('YouTube video: 450px by 315px'); } + if ($settings['youtube_autoplay']) { + $summary .= t('; Autoplay: @autoplay', array('@autoplay' => $settings['youtube_autoplay'])); + } return $summary; } @@ -221,6 +232,7 @@ function youtube_field_formatter_view($entity_type, $entity, $field, $instance, '#theme' => 'youtube_video', '#video_id' => $item['video_id'], '#youtube_size' => $display['settings']['youtube_size'], + '#youtube_autoplay' => $display['settings']['youtube_autoplay'], ); } break; @@ -340,7 +352,7 @@ function youtube_theme($existing, $type, $theme, $path) { 'file' => 'youtube.theme.inc', ), 'youtube_video' => array( - 'variables' => array('video_id' => NULL, 'youtube_size' => NULL), + 'variables' => array('video_id' => NULL, 'youtube_size' => NULL, 'youtube_autoplay' => NULL), 'file' => 'youtube.theme.inc', ), ); diff --git a/youtube.theme.inc b/youtube.theme.inc index da8e19e..30da74f 100644 --- a/youtube.theme.inc +++ b/youtube.theme.inc @@ -10,6 +10,7 @@ function theme_youtube_video($variables) { $id = $variables['video_id']; $size = $variables['youtube_size']; + $autoplay = $variables['youtube_autoplay']; // Get YouTube settings. $old = variable_get('youtube_old', FALSE); @@ -29,6 +30,9 @@ function theme_youtube_video($variables) { if (!$suggest) { $query['rel'] = '0'; } + if ($autoplay) { + $query['autoplay'] = '1'; + } // Domain changes based on settings. $domain = ($privacy) ? 'youtube-nocookie.com' : 'youtube.com';