You are here

public function FeedsFileFetcher::configFormValidate in Feeds 7.2

Overrides parent::configFormValidate().

Ensure that the chosen directory is accessible.

Overrides FeedsConfigurable::configFormValidate

File

plugins/FeedsFileFetcher.inc, line 286
Home of the FeedsFileFetcher and related classes.

Class

FeedsFileFetcher
Fetches data via HTTP.

Code

public function configFormValidate(&$values) {
  $values['directory'] = trim($values['directory']);
  $values['allowed_schemes'] = array_filter($values['allowed_schemes']);
  if (!$values['direct']) {

    // Ensure that the upload directory field is not empty when not in
    // direct-mode.
    if (!$values['directory']) {
      form_set_error('directory', t('Please specify an upload directory.'));

      // Do not continue validating the directory if none was specified.
      return;
    }

    // Validate the URI scheme of the upload directory.
    $scheme = file_uri_scheme($values['directory']);
    if (!$scheme || !in_array($scheme, $this
      ->getSchemes())) {
      form_set_error('directory', t('Please enter a valid scheme into the directory location.'));

      // Return here so that attempts to create the directory below don't
      // throw warnings.
      return;
    }

    // Ensure that the upload directory exists.
    if (!file_prepare_directory($values['directory'], FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
      form_set_error('directory', t('The chosen directory does not exist and attempts to create it failed.'));
    }
  }
}