1 system.admin.inc | system_site_information_settings_validate($form, &$form_state) |
Validates the submitted site-information form.
File
- core/
modules/ system/ system.admin.inc, line 1423 - Admin page callbacks for the System module.
Code
function system_site_information_settings_validate($form, &$form_state) {
// Handle file uploads.
$validators = array('file_validate_extensions' => array('ico png gif jpg jpeg apng svg'));
// Check for a new uploaded logo, create a temporary File entity for
// validation.
$file = file_save_upload('site_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']['site_logo_upload'] = $file;
}
else {
// File upload failed.
form_set_error('site_logo_upload', t('The logo could not be uploaded.'));
}
}
// Check for a new uploaded favicon, create a temporary File entity for
// validation.
$file = file_save_upload('site_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']['site_favicon_upload'] = $file;
}
else {
// File upload failed.
form_set_error('site_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']['site_logo_path'])) {
$path = _system_site_information_settings_validate_path($form_state['values']['site_logo_path']);
if (!$path) {
form_set_error('site_logo_path', t('The custom logo path is invalid.'));
}
}
if (!empty($form_state['values']['site_favicon_path'])) {
$path = _system_site_information_settings_validate_path($form_state['values']['site_favicon_path']);
if (!$path) {
form_set_error('site_favicon_path', t('The custom favicon path is invalid.'));
}
}
// Get the normal path of the home page.
form_set_value($form['front_page']['site_frontpage'], backdrop_get_normal_path($form_state['values']['site_frontpage']), $form_state);
// Validate home page path.
if (!backdrop_valid_path($form_state['values']['site_frontpage'])) {
form_set_error('site_frontpage', t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_frontpage'])));
}
// Get the normal paths of both error pages.
if (!empty($form_state['values']['site_403'])) {
form_set_value($form['error_page']['site_403'], backdrop_get_normal_path($form_state['values']['site_403']), $form_state);
}
if (!empty($form_state['values']['site_404'])) {
form_set_value($form['error_page']['site_404'], backdrop_get_normal_path($form_state['values']['site_404']), $form_state);
}
// Validate 403 error path.
if (!empty($form_state['values']['site_403']) && !backdrop_valid_path($form_state['values']['site_403'])) {
form_set_error('site_403', t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_403'])));
}
// Validate 404 error path.
if (!empty($form_state['values']['site_404']) && !backdrop_valid_path($form_state['values']['site_404'])) {
form_set_error('site_404', t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_404'])));
}
}