function _touch_icons_plain_upload_validate in Touch Icons 6
Validate custom plain touch icon upload.
Saves the uploaded file and prepares file path variable.
1 string reference to '_touch_icons_plain_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 320 - 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_plain_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 plain touch icon upload
if ($file = file_save_upload('touch_icon_plain_upload', array(
'file_validate_is_image' => array(),
))) {
$parts = pathinfo($file->filename);
$filename = $key ? 'touch_icons/' . str_replace('/', '_', $key) . '_apple-touch-icon.' . $parts['extension'] : 'touch_icons/' . 'apple-touch-icon.' . $parts['extension'];
if (file_copy($file, $filename, FILE_EXISTS_REPLACE)) {
drupal_set_message(t('The new touch icon was saved.'));
$form_state['values']['touch_icon_plain_path'] = $file->filepath;
// prepare theme settings variables for storage
// keep consistent with core logo/favicon behaviour
$form_state['values']['default_touch_icon_plain'] = 0;
$form_state['values']['toggle_touch_icon_plain'] = 1;
}
}
}