You are here

function system_theme_settings_validate in Drupal 7

Validator for the system_theme_settings() form.

1 string reference to 'system_theme_settings_validate'
system_theme_settings in modules/system/system.admin.inc
Form builder; display theme configuration for entire site and individual themes.

File

modules/system/system.admin.inc, line 608
Admin page callbacks for the system module.

Code

function system_theme_settings_validate($form, &$form_state) {

  // Handle file uploads.
  $validators = array(
    'file_validate_is_image' => array(),
  );

  // Check for a new uploaded logo.
  $file = file_save_upload('logo_upload', $validators);
  if (isset($file)) {

    // File upload was attempted.
    if ($file) {

      // Put the temporary file in form_values so we can save it on submit.
      $form_state['values']['logo_upload'] = $file;
    }
    else {

      // File upload failed.
      form_set_error('logo_upload', t('The logo could not be uploaded.'));
    }
  }
  $validators = array(
    'file_validate_extensions' => array(
      'ico png gif jpg jpeg apng svg',
    ),
  );

  // Check for a new uploaded favicon.
  $file = file_save_upload('favicon_upload', $validators);
  if (isset($file)) {

    // File upload was attempted.
    if ($file) {

      // Put the temporary file in form_values so we can save it on submit.
      $form_state['values']['favicon_upload'] = $file;
    }
    else {

      // File upload failed.
      form_set_error('favicon_upload', t('The favicon could not be uploaded.'));
    }
  }

  // If the user provided a path for a logo or favicon file, make sure a file
  // exists at that path.
  if (!empty($form_state['values']['logo_path'])) {
    $path = _system_theme_settings_validate_path($form_state['values']['logo_path']);
    if (!$path) {
      form_set_error('logo_path', t('The custom logo path is invalid.'));
    }
  }
  if (!empty($form_state['values']['favicon_path'])) {
    $path = _system_theme_settings_validate_path($form_state['values']['favicon_path']);
    if (!$path) {
      form_set_error('favicon_path', t('The custom favicon path is invalid.'));
    }
  }
}