You are here

function video_preset_submit in Video 7.2

Same name and namespace in other branches
  1. 7 modules/video_ui/video.preset.inc \video_preset_submit()

Submit handler for the preset form.

1 string reference to 'video_preset_submit'
video_preset_form in modules/video_ui/video.preset.inc
Preset form builder.

File

modules/video_ui/video.preset.inc, line 600
Administrative interface for maintaining video presets.

Code

function video_preset_submit($form, &$form_state) {
  $v =& $form_state['values'];
  $old = isset($form_state['preset']) ? $form_state['preset'] : NULL;
  $preset = array();
  if ($old && isset($old['pid'])) {
    $preset['pid'] = $old['pid'];
  }

  // There is only a name if this isn't a module provided preset
  $preset['name'] = isset($v['name']) ? $v['name'] : $old['name'];
  $preset['description'] = $v['description'];

  // unset unwanted values saved to database
  unset($v['name'], $v['description'], $v['submit'], $v['delete'], $v['form_build_id'], $v['form_token'], $v['form_id'], $v['op'], $v['revert']);
  $preset['settings'] = video_preset_array_flatten($v);

  // Save this preset.
  $preset = video_preset_save($preset);

  // Save new watermark image if exists
  if (!empty($v['video_watermark_fid'])) {
    $file = file_load($v['video_watermark_fid']);
    if ($file->status != FILE_STATUS_PERMANENT) {
      $file->status = FILE_STATUS_PERMANENT;
      file_save($file);
      file_usage_add($file, 'video', 'preset', $preset['pid']);
    }
  }

  // Remove the old watermark if different
  if ($old && !empty($old['settings']['video_watermark_fid']) && $old['settings']['video_watermark_fid'] != $form_state['values']['video_watermark_fid']) {
    $oldfile = file_load($old['settings']['video_watermark_fid']);
    if (!empty($oldfile)) {
      file_usage_delete($oldfile, 'video');
      $oldfile->status = 0;
      file_save($oldfile);
    }
  }
  drupal_set_message(t('Preset %preset successfully saved.', array(
    '%preset' => $preset['name'],
  )));
  $form_state['redirect'] = 'admin/config/media/video/presets';
}