You are here

function _touch_icons_plain_validate in Touch Icons 7.2

Same name and namespace in other branches
  1. 7 touch_icons.module \_touch_icons_plain_validate()

Validate custom plain touch icon settings

1 string reference to '_touch_icons_plain_validate'
touch_icons_form_system_theme_settings_alter in ./touch_icons.admin.inc
Implement hook_form_FORM_ID_alter(). Implement hook_form_system_theme_settings_alter().

File

./touch_icons.admin.inc, line 148
Settings form and helper functions for touch icons module

Code

function _touch_icons_plain_validate($element, &$form_state) {

  // If the user provided a path for plain touch icon
  // make sure a file exists at that path.
  if ($form_state['values']['touch_icon_path_plain']) {
    $path = _system_theme_settings_validate_path($form_state['values']['touch_icon_path_plain']);
    if (!$path) {
      form_set_error('touch_icon_path_plain', t('The custom plain-touch-icon path is invalid.'));
      return;
    }
  }

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

  // Check for a new uploaded plain touch icon.
  $file = file_save_upload('touch_icon_upload_plain', $validators);
  if (isset($file)) {

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

      // If the user uploaded a new plain touch-icon, save it to a permanent
      // location and use it in place of the default theme-provided file.
      $filename = file_unmanaged_copy($file->uri);
      $form_state['values']['touch_icon_path_plain'] = $filename;
      $form_state['values']['default_touch_icon_plain'] = 0;
      $form_state['values']['toggle_touch_icon_plain'] = 1;
      unset($form_state['values']['touch_icon_upload_plain']);
    }
    else {

      // File upload failed.
      form_set_error('touch_icon_upload_plain', t('The touch icon (plain) could not be uploaded.'));
      return;
    }
  }

  // If the user entered a path relative to the system files directory for a
  // plain touch icon, store a public:// URI so the theme system can handle it.
  if (!empty($form_state['values']['touch_icon_path_plain'])) {
    $form_state['values']['touch_icon_path_plain'] = _system_theme_settings_validate_path($form_state['values']['touch_icon_path_plain']);
  }
}