diff --git a/scald_youtube.module b/scald_youtube.module index d4b7bc6..02d15ac 100644 --- a/scald_youtube.module +++ b/scald_youtube.module @@ -156,7 +156,7 @@ function scald_youtube_scald_add_form_fill(&$atom, $form, $form_state) { ); } } - + // Save video width and height. $atom->data['video_width'] = $infos->width; $atom->data['video_height'] = $infos->height; @@ -210,6 +210,20 @@ function scald_youtube_form_scald_atom_add_form_options_alter(&$form, &$form_sta '#tree' => TRUE, '#parents' => array($key, 'scald_youtube_show_related'), ); + + $scald_youtube_autoplay = variable_get('scald_youtube_autoplay', FALSE); + if (isset($scald['atoms'][$index]->data['youtube_autoplay'])) { + $scald_youtube_autoplay = $scald['atoms'][$index]->data['youtube_autoplay']; + } + $form[$key]['scald_youtube_autoplay'] = array( + '#type' => 'checkbox', + '#default_value' => $scald_youtube_autoplay, + '#title' => t('Autoplay the video'), + '#description' => t('If checked, the video will be automatically read.'), + '#weight' => $form[$key]['scald_thumbnail']['#weight'] + .7, + '#tree' => TRUE, + '#parents' => array($key, 'scald_youtube_autoplay'), + ); } } @@ -225,6 +239,7 @@ function scald_youtube_extra_options_save_handler(&$form, &$form_state) { if (strpos($key, 'atom') === 0) { $index = intval(substr($key, 4)); $form_state['scald']['atoms'][$index]->data['show_related'] = $form_state['values'][$key]['scald_youtube_show_related']; + $form_state['scald']['atoms'][$index]->data['youtube_autoplay'] = $form_state['values'][$key]['scald_youtube_autoplay']; } } } @@ -262,6 +277,9 @@ function scald_youtube_scald_prerender($atom, $context, $options, $mode) { if (isset($atom->data['show_related']) && empty($atom->data['show_related'])) { $query['rel'] = '0'; } + if (isset($atom->data['youtube_autoplay']) && !empty($atom->data['youtube_autoplay'])) { + $query['autoplay'] = '1'; + } $video_url = url(SCALD_YOUTUBE_EMBED . $atom->base_id, array( 'query' => $query, )); @@ -536,6 +554,12 @@ function scald_youtube_form_scald_admin_type_form_alter(&$form, &$form_state, $f '#title' => t('Show related videos by default'), '#description' => t('If checked the related videos will be visible at the end of the video by default for new Atoms.'), ); + $form['defaults']['scald_youtube']['scald_youtube_autoplay'] = array( + '#type' => 'checkbox', + '#default_value' => variable_get('scald_youtube_autoplay', FALSE), + '#title' => t('Autoplay the video'), + '#description' => t('If checked, the video will be automatically read.'), + ); $form['#submit'][] = 'scald_youtube_configuration_submit'; } } @@ -570,6 +594,7 @@ function scald_youtube_validate_api_key($element, &$form_state) { function scald_youtube_configuration_submit($form_id, &$form_state) { variable_set('scald_youtube_api_key', $form_state['values']['scald_youtube_api_key']); variable_set('scald_youtube_show_related', $form_state['values']['scald_youtube_show_related']); + variable_set('scald_youtube_autoplay', $form_state['values']['scald_youtube_autoplay']); } /**