You are here

function _touch_icons_precomp_upload_validate in Touch Icons 6

Validate custom precomposed touch icon upload.

Saves the uploaded file and prepares file path variable.

1 string reference to '_touch_icons_precomp_upload_validate'
touch_icons_form_system_theme_settings_alter in ./touch_icons.module
Implementation of hook_form_FORM_ID_alter(). Implementation of hook_form_system_theme_settings_alter().

File

./touch_icons.module, line 352
Adds a fieldset to theme settings form which allows site administrators to specify Apple Touch icons for Drupal websites. The Touch icon settings behave in a similar manner to the Site Logo and Favicon settings provided by Drupal core.

Code

function _touch_icons_precomp_upload_validate($element, &$form_state) {

  // need theme key for saving theme-specific icons
  // e.g. garland_apple-touch-icon.png
  $key = _touch_icons_get_theme_settings_key();

  // ensure there is a directory to save touch icons
  $directory_path = file_directory_path() . '/touch_icons';
  file_check_directory($directory_path, FILE_CREATE_DIRECTORY);

  // Handle precomposed touch icon upload
  if ($file = file_save_upload('touch_icon_precomp_upload', array(
    'file_validate_is_image' => array(),
  ))) {
    $parts = pathinfo($file->filename);
    $filename = $key ? 'touch_icons/' . str_replace('/', '_', $key) . '_apple-touch-icon-precomposed.' . $parts['extension'] : 'touch_icons/' . 'apple-touch-icon-precomposed.' . $parts['extension'];
    if (file_copy($file, $filename, FILE_EXISTS_REPLACE)) {
      drupal_set_message(t('The new precomposed touch icon was saved.'));
      $form_state['values']['touch_icon_precomp_path'] = $file->filepath;

      // prepare theme settings variables for storage
      // keep consistent with core logo/favicon behaviour
      $form_state['values']['default_touch_icon_precomp'] = 0;
      $form_state['values']['toggle_touch_icon_precomp'] = 1;
    }
  }
}