You are here

function media_import_validate in D7 Media 7

Validate handler for media_import().

File

includes/media.admin.inc, line 473
This file contains the admin functions for the Media module.

Code

function media_import_validate($form, &$form_state) {
  if ($form_state['values']['op'] != t('Confirm')) {
    $directory = $form_state['values']['directory'];
    $pattern = $form_state['values']['pattern'];
    if (!is_dir($directory)) {
      form_set_error('directory', t('The provided directory does not exist.'));
    }
    $pattern = !empty($pattern) ? $pattern : '*';
    $files = glob("{$directory}/{$pattern}");
    if (empty($files)) {
      form_set_error('pattern', t('No files were found in %directory matching %pattern', array(
        '%directory' => $directory,
        '%pattern' => $pattern,
      )));
    }
    $form_state['storage']['files'] = $files;
  }
}