function scald_video_form_scald_atom_add_form_options_alter in Scald: Media Management made easy 7
Implements hook_form_FORM_ID_alter().
File
- modules/
providers/ scald_video/ scald_video.module, line 167 - Scald Video is a Scald Atom Provider for video files.
Code
function scald_video_form_scald_atom_add_form_options_alter(&$form, &$form_state) {
// We check for multiple atoms on the form:
if (isset($form_state['scald']['atom'])) {
$atoms = array(
$form_state['scald']['atom'],
);
}
else {
$atoms = $form_state['scald']['atoms'];
}
// Set one atom's form options. This can be called multiple times in case
// a multifile field is used.
foreach ($atoms as $key => $atom) {
$form["atom{$key}"]['#tree'] = TRUE;
if ($atom->provider !== 'scald_video') {
break;
}
$width = '';
$height = '';
if (isset($atom->sid)) {
if (isset($atom->data['video_width'])) {
$width = $atom->data['video_width'];
}
if (isset($atom->data['video_height'])) {
$height = $atom->data['video_height'];
}
}
else {
// Retrieve informations of Video by ffmpeg
// http://ffmpeg-php.sourceforge.net/doc/api/ffmpeg_movie.php
if (class_exists('ffmpeg_movie')) {
$ffmpeg_video = new ffmpeg_movie(drupal_realpath($atom->file_source), FALSE);
$ffmpeg_width = (int) $ffmpeg_video
->getFrameWidth();
if ($ffmpeg_width > 0) {
$width = check_plain($ffmpeg_width);
}
$ffmpeg_height = (int) $ffmpeg_video
->getFrameHeight();
if ($ffmpeg_height > 0) {
$height = check_plain($ffmpeg_height);
}
/* Does not work : page reset, but no error... (php and ffmpeg 5.4 from Linux Mint)
$title = $ffmpeg_video->getTitle();
if ($title != '') {
$form['title']['#default_value'] = check_plain($title);
}*/
}
}
$form["atom{$key}"]['width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#size' => 10,
'#element_validate' => array(
'element_validate_integer_positive',
),
'#required' => TRUE,
'#default_value' => $width,
);
$form["atom{$key}"]['height'] = array(
'#type' => 'textfield',
'#title' => t('Height'),
'#size' => 10,
'#element_validate' => array(
'element_validate_integer_positive',
),
'#required' => TRUE,
'#default_value' => $height,
);
// Multi sources support: (https://drupal.org/node/2074349):
$form["atom{$key}"]['uploaded_video_sources'] = array(
'#tree' => TRUE,
);
$uploaded_videos_form =& $form["atom{$key}"]['uploaded_video_sources'];
$uploaded_videos_form['description']['#markup'] = '<label>Alternative video sources</label>';
$uploaded_videos_form['description']['#markup'] .= 'Alternative sources will be used as additional source tags within the video.<br/>';
if (isset($atom->data['alternative_video_sources']) && count($atom->data['alternative_video_sources'])) {
$uploaded_videos_form['description']['#markup'] .= 'Uncheck to remove additional source file from the atom.';
foreach ($atom->data['alternative_video_sources'] as $source_key => $video_file) {
$uploaded_videos_form[$source_key] = array(
'#type' => 'checkbox',
'#title' => l($video_file->filename, file_create_url($video_file->uri)),
'#default_value' => 1,
);
}
}
scald_video_get_video_file_form($form["atom{$key}"]['alternative_video_sources']);
}
$form['#submit'][] = 'scald_video_form_scald_atom_add_form_options_submit';
}