Example #1
0
/**
 * Implementation of hook_settings() for themes.
 */
function singular_settings($settings)
{
    // Add js & css
    drupal_add_css('misc/farbtastic/farbtastic.css', 'module', 'all', FALSE);
    drupal_add_js('misc/farbtastic/farbtastic.js');
    drupal_add_js(drupal_get_path('theme', 'singular') . '/js/settings.js');
    drupal_add_css(drupal_get_path('theme', 'singular') . '/css/settings.css');
    file_check_directory(file_directory_path(), FILE_CREATE_DIRECTORY, 'file_directory_path');
    // Check for a new uploaded logo, and use that instead.
    if ($file = file_save_upload('background_file', array('file_validate_is_image' => array()))) {
        $parts = pathinfo($file->filename);
        $filename = 'singular_background.' . $parts['extension'];
        if (file_copy($file, $filename, FILE_EXISTS_REPLACE)) {
            $settings['background_path'] = $file->filepath;
        }
    }
    $form = array();
    $form['layout'] = array('#title' => t('Layout'), '#type' => 'select', '#options' => array('fixed' => t('Fixed width'), 'fluid' => t('Fluid width')), '#default_value' => !empty($settings['layout']) ? $settings['layout'] : 'fixed');
    $form['messages'] = array('#type' => 'fieldset', '#tree' => FALSE, '#title' => t('Autoclose messages'), '#descriptions' => t('Select the message types to close automatically after a few seconds.'));
    $form['messages']['autoclose'] = array('#type' => 'checkboxes', '#options' => array('status' => t('Status'), 'warning' => t('Warning'), 'error' => t('Error')), '#default_value' => !empty($settings['autoclose']) ? $settings['autoclose'] : array('status'));
    $form['style'] = array('#title' => t('Styles'), '#type' => 'select', '#options' => singular_get_styles(), '#default_value' => !empty($settings['style']) ? $settings['style'] : 'sea');
    $form['custom'] = array('#tree' => FALSE, '#type' => 'fieldset', '#attributes' => array('class' => $form['style']['#default_value'] == 'custom' ? 'singular-custom-settings' : 'singular-custom-settings hidden'));
    $form['custom']['background_file'] = array('#type' => 'file', '#title' => t('Background image'), '#maxlength' => 40);
    if (!empty($settings['background_path'])) {
        $form['custom']['background_preview'] = array('#type' => 'markup', '#value' => !empty($settings['background_path']) ? theme('image', $settings['background_path'], NULL, NULL, array('width' => '100'), FALSE) : '');
    }
    $form['custom']['background_path'] = array('#type' => 'value', '#value' => !empty($settings['background_path']) ? $settings['background_path'] : '');
    $form['custom']['background_color'] = array('#title' => t('Background color'), '#type' => 'textfield', '#size' => '7', '#maxlength' => '7', '#default_value' => !empty($settings['background_color']) ? $settings['background_color'] : '#888888', '#suffix' => '<div id="singular-colorpicker"></div>');
    $form['custom']['background_repeat'] = array('#title' => t('Tile'), '#type' => 'select', '#options' => array('no-repeat' => t('Don\'t tile'), 'repeat-x' => t('Horizontal'), 'repeat-y' => t('Vertical'), 'repeat' => t('Both')), '#default_value' => !empty($settings['background_repeat']) ? $settings['background_repeat'] : 'no-repeat');
    return $form;
}
 function addStreamFormSubmit($form_id, $form_values)
 {
     module_load_include('inc', 'Fedora_Repository', 'api/fedora_utils');
     module_load_include('inc', 'Fedora_Repository', 'api/fedora_item');
     module_load_include('php', 'Fedora_Repository', 'ObjectHelper');
     $types = array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.wordperfect', 'application/wordperfect', 'application/vnd.oasis.opendocument.text', 'text/rtf', 'application/rtf', 'application/msword', 'application/vnd.ms-powerpoint', 'application/pdf');
     global $user;
     /* TODO Modify the validators array to suit your needs.
        This array is used in the revised file_save_upload */
     $fileObject = file_save_upload('file_uploaded');
     if (!in_array($fileObject->filemime, $types)) {
         drupal_set_message(t('The detected mimetype %s is not supported', array('%s' => $fileObject->filemime)), 'error');
         return false;
     }
     file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME');
     $objectHelper = new ObjectHelper();
     $pid = $form_values['pid'];
     $fedora_item = new Fedora_Item($pid);
     $test = NULL;
     $test = $fedora_item->add_datastream_from_file($fileObject->filepath, 'OBJ');
     if ($test) {
         $this->updateMODSStream($form_values['pid'], $form_values['version'], $form_values['usage']);
     }
     file_delete($fileObject->filepath);
     return true;
 }
/**
 * Save settings data.
 */
function black_lagoon_settings_submit($form, &$form_state)
{
    $settings = array();
    // Update image field
    foreach ($form_state['input']['images'] as $image) {
        if (is_array($image)) {
            $image = $image['image'];
            if ($image['image_delete']) {
                // Delete banner file
                file_unmanaged_delete($image['image_path']);
                // Delete banner thumbnail file
                file_unmanaged_delete($image['image_thumb']);
            } else {
                // Update image
                $settings[] = $image;
            }
        }
    }
    // Check for a new uploaded file, and use that if available.
    if ($file = file_save_upload('image_upload')) {
        $file->status = FILE_STATUS_PERMANENT;
        if ($image = _black_lagoon_save_image($file)) {
            // Put new image into settings
            $settings[] = $image;
        }
    }
    // Save settings
    black_lagoon_set_banners($settings);
}
Example #4
0
 /**
  * 'upload_zip' upload field must refer to a zip file containing 
  *   all files for the pubnode (may be at top-level or inside a subdirectory)
  */
 public function import(&$form_state, $docid = NULL)
 {
     $validators = array('file_validate_extensions' => array('zip'), 'file_validate_size' => array(100000000, 0));
     if ($file = file_save_upload($this->fieldname, $validators, file_directory_temp(), FILE_EXISTS_REPLACE)) {
         $zip = new ZipArchive();
         if ($zip->open($file->filepath) !== TRUE) {
             form_set_error(t("Cannot open !file", array("!file" => $file->filename)), 'error');
             return FALSE;
         }
         // else
         if (empty($docid)) {
             $docid = $this->hashFile($file->filepath);
         }
         $pubpath = $this->constructPubPath($docid);
         //drupal_set_message("PUBPATH: " . $pubpath);
         file_check_directory($pubpath, FILE_CREATE_DIRECTORY);
         $zip->extractTo($pubpath);
         drupal_set_message(t("Extracted !num files to directory !dir", array('!num' => $zip->numFiles, '!dir' => $pubpath)));
         $zip->close();
         $this->pubpath = $pubpath;
         return TRUE;
     }
     // else validations failed and error message will be set by upload function
     return FALSE;
 }
/**
 * Implements hook_setings_submit().
 */
function nuboot_radix_settings_submit($form, &$form_state)
{
    $settings = array();
    // If the user entered a path relative to the system files directory for
    // for the hero unit, store a public:// URI so the theme system can handle it.
    if (!empty($values['hero_path'])) {
        $values['hero_path'] = _system_theme_settings_validate_path($values['hero_path']);
    }
    // Get the previous value.
    $previous = $form['hero']['hero_path']['#default_value'];
    if ($previous !== 'profiles/dkan/themes/contrib/nuboot_radix/assets/images/hero.jpg') {
        $previous = 'public://' . $previous;
    } else {
        $previous = FALSE;
    }
    if ($file = file_save_upload('hero_upload')) {
        $parts = pathinfo($file->filename);
        $destination = 'public://' . $parts['basename'];
        $file->status = FILE_STATUS_PERMANENT;
        if (file_copy($file, $destination, FILE_EXISTS_REPLACE)) {
            $_POST['hero_path'] = $form_state['values']['hero_path'] = $destination;
            // If new file has a different name than the old one, delete the old.
            if ($previous && $destination != $previous) {
                drupal_unlink($previous);
            }
        }
    } else {
        // Avoid error when the form is submitted without specifying a new image.
        $_POST['hero_path'] = $form_state['values']['hero_path'] = $previous;
    }
}
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Process the upload and perform validation. Note: we're using the
     // form value for the $replace parameter.
     if (!$form_state->isValueEmpty('file_subdir')) {
         $destination = 'temporary://' . $form_state->getValue('file_subdir');
         file_prepare_directory($destination, FILE_CREATE_DIRECTORY);
     } else {
         $destination = FALSE;
     }
     // Setup validators.
     $validators = array();
     if ($form_state->getValue('is_image_file')) {
         $validators['file_validate_is_image'] = array();
     }
     if ($form_state->getValue('allow_all_extensions')) {
         $validators['file_validate_extensions'] = array();
     } elseif (!$form_state->isValueEmpty('extensions')) {
         $validators['file_validate_extensions'] = array($form_state->getValue('extensions'));
     }
     $file = file_save_upload('file_test_upload', $validators, $destination, 0, $form_state->getValue('file_test_replace'));
     if ($file) {
         $form_state->setValue('file_test_upload', $file);
         drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->getFileUri())));
         drupal_set_message(t('File name is @filename.', array('@filename' => $file->getFilename())));
         drupal_set_message(t('File MIME type is @mimetype.', array('@mimetype' => $file->getMimeType())));
         drupal_set_message(t('You WIN!'));
     } elseif ($file === FALSE) {
         drupal_set_message(t('Epic upload FAIL!'), 'error');
     }
 }
/**
 * Validate handler where we actually save the files...
 */
function flux_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('cover_photo_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']['cover_photo_upload'] = $file;
        } else {
            // File upload failed.
            form_set_error('cover_photo_upload', t('The image could not be uploaded.'));
        }
    }
    $validators = array('file_validate_extensions' => array('ico png gif jpg jpeg apng svg'));
    // If the user provided a path for a logo or favicon file, make sure a file
    // exists at that path.
    if ($form_state['values']['cover_photo_path']) {
        $path = flux_system_theme_settings_validate_path($form_state['values']['cover_photo_path']);
        if (!$path) {
            form_set_error('cover_photo_path', t('The custom path is invalid.'));
        }
    }
}
Example #8
0
/**
 * Validation callback for platon_form_system_theme_settings_alter().
 */
function platon_form_system_theme_settings_alter_validate($form, &$form_state)
{
    if (!empty($_FILES['files']['name']['platon_header_image_upload'])) {
        $file = file_save_upload('platon_header_image_upload', array('file_validate_is_image' => array(), 'file_validate_extensions' => array('png gif jpg jpeg')), 'public://');
        if ($file) {
            $file->status = FILE_STATUS_PERMANENT;
            file_save($file);
            $form_state['storage']['header_file'] = $file;
        } else {
            form_set_error('platon_header_image_upload', t("Couldn't upload file."));
        }
    }
    if (!empty($_FILES['files']['name']['platon_home_page_image_upload'])) {
        $file = file_save_upload('platon_home_page_image_upload', array('file_validate_is_image' => array(), 'file_validate_extensions' => array('png gif jpg jpeg')), 'public://');
        if ($file) {
            $file->status = FILE_STATUS_PERMANENT;
            file_save($file);
            $form_state['storage']['home_file'] = $file;
        } else {
            form_set_error('platon_home_page_image_upload', t("Couldn't upload file."));
        }
    }
    if (!empty($form_state['values']['platon_css_override_content'])) {
        if ($fid = _platon_store_css_override_file($form_state['values']['platon_css_override_content'])) {
            $form_state['storage']['css_fid'] = $fid;
        } else {
            form_set_error('platon_css_override_content', t("Could not save the CSS in a file. Perhaps the server has no write access. Check your public files folder permissions."));
        }
    }
}
Example #9
0
/**
 * implements ddaycare_background_validate
 */
function daycare_background_validate($element, &$form_state)
{
    global $base_url;
    $validators = array('file_validate_is_image' => array());
    $file = file_save_upload('background', $validators, "public://", FILE_EXISTS_REPLACE);
    if ($file) {
        // change file's status from temporary to permanent and update file database
        $file->status = FILE_STATUS_PERMANENT;
        file_save($file);
        $file_url = file_create_url($file->uri);
        $file_url = str_ireplace($base_url . '/', '', $file_url);
        // set to form
        $form_state['values']['bg_file'] = $file_url;
    }
}
Example #10
0
function bulkSavePictures(&$form_state)
{
    $num_files = count($_FILES['files']['name']);
    for ($i = 0; $i < $num_files; $i++) {
        $file = file_save_upload($i, array('file_validate_is_image' => array(), 'file_validate_extensions' => array('png gif jpg jpeg')));
        if ($file) {
            if ($file = file_move($file, 'public://')) {
                $form_state['values']['file'][$i] = $file;
            } else {
                form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
            }
        } else {
            form_set_error('file', t('No file was uploaded.'));
        }
    }
}
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // Validate options.
     $roles = $form_state->getValue(['config', 'roles']);
     $roles_selected = array_filter($roles, function ($item) {
         return $item;
     });
     if (empty($roles_selected)) {
         $form_state->setErrorByName('roles', $this->t('Please select at least one role to apply to the imported user(s).'));
     }
     // Validate file.
     $this->file = file_save_upload('file', $form['file']['#upload_validators']);
     if (!$this->file[0]) {
         $form_state->setErrorByName('file');
     }
 }
function open_framework_settings_validate($form, &$form_state)
{
    $validators = array('file_validate_is_image' => array());
    // Check for a new uploaded logo.
    $file = file_save_upload('body_bg_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']['body_bg_upload'] = $file;
        } else {
            // File upload failed.
            form_set_error('body_bg_upload', t('The background image could not be uploaded.'));
        }
    }
}
Example #13
0
function intranet_system_theme_settings_submit($form, &$form_state)
{
    $settings = array();
    $file = file_save_upload('footer_image_upload');
    $bg_imags = array('bg_image_upload' => 'bg_image_path', 'header_image_upload' => 'header_image_path', 'footer_image_upload' => 'footer_image_path');
    foreach ($bg_imags as $upload => $path) {
        // Check for a new uploaded file, and use that if available.
        if ($file = file_save_upload($upload)) {
            $parts = pathinfo($file->filename);
            $destination = 'public://' . $parts['basename'];
            $file->status = FILE_STATUS_PERMANENT;
            if (file_copy($file, $destination, FILE_EXISTS_REPLACE)) {
            }
            $form_state['values'][$path] = $destination;
        }
    }
}
function parallax_bg_region5_validate($element, &$form_state)
{
    global $base_url;
    $validateFile = array('file_validate_is_image' => array());
    $UploadedFile = file_save_upload('parallax_bg_region5_image', $validateFile, "public://", FILE_EXISTS_REPLACE);
    if ($form_state['values']['delete_parallax_bg_region5_image'] == TRUE) {
        file_unmanaged_delete($form_state['values']['parallax_bg_region5_preview']);
        $form_state['values']['parallax_bg_region5_preview'] = NULL;
    }
    if ($UploadedFile) {
        $UploadedFile->status = FILE_STATUS_PERMANENT;
        file_save($UploadedFile);
        $file_url = file_create_url($UploadedFile->uri);
        $file_url = str_ireplace($base_url, '', $file_url);
        // set to form
        $form_state['values']['parallax_bg_region5_preview'] = $file_url;
    }
}
Example #15
0
function hosting_themes_settings_submit($form, &$form_state)
{
    // Get the previous value
    $previous = 'public://' . $form['contact']['contact_icon']['#default_value'];
    $file = file_save_upload('contact_icon_upload');
    if ($file) {
        $parts = pathinfo($file->filename);
        $destination = 'public://' . $parts['basename'];
        $file->status = FILE_STATUS_PERMANENT;
        if (file_copy($file, $destination, FILE_EXISTS_REPLACE)) {
            $_POST['contact_icon'] = $form_state['values']['contact_icon'] = $destination;
            if ($destination != $previous) {
                return;
            }
        }
    } else {
        // Avoid error when the form is submitted without specifying a new image
        $_POST['contact_icon'] = $form_state['values']['contact_icon'] = $previous;
    }
}
Example #16
0
function _agency_1_theme_settings_map($form, &$form_state)
{
    $validators = array('file_validate_is_image' => array());
    $file = file_save_upload('background_file', $validators);
    $map_file = file_save_upload('footer_contact_us_map_image', $validators);
    //Map image
    if (isset($map_file)) {
        // File upload was attempted.
        if ($map_file) {
            // Move the file, into the Drupal file system
            if ($map_filename = file_unmanaged_copy($map_file->uri, 'public://background_images', FILE_EXISTS_RENAME)) {
                //resize, if necessary
                $map_resized = image_load($map_file->uri);
                list($map_width, $map_height) = getimagesize($map_file->uri);
                if ($map_width > 150 || $map_height > 150) {
                    if ($map_width / $map_height >= 1) {
                        image_scale($map_resized, 150);
                    } else {
                        image_scale($map_resized, null, 150);
                    }
                    image_save($map_resized, $map_filename, FILE_EXISTS_RENAME);
                    $map_resized->status = FILE_STATUS_PERMANENT;
                    drupal_set_message('Uploaded image was greater than 150px.  Image has been resized.');
                }
                //end resize
                unset($form['footer_contact_us']['settings']['footer_contact_us_map_path']);
                $form['footer_contact_us']['settings']['footer_contact_us_map_path']['#value'] = $map_filename;
                $form['footer_contact_us_map_path']['#parents'] = array('footer_contact_us_map_path');
                form_set_value($form['footer_contact_us_map_path'], file_create_url($map_filename), $form_state);
                watchdog('Theme Settings', 'New Footer Map Image uploaded: ' . file_create_url($map_filename));
                drupal_set_message('Map Image uploaded.  URL: ' . file_create_url($map_filename));
            } else {
                form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
            }
        } else {
            // File upload failed.
            form_set_error('background_file', t('The image could not be uploaded.'));
        }
    }
}
Example #17
0
function academy_settings_submit($form, &$form_state)
{
    $settings = array();
    // Get the previous value
    $previous = 'public://' . $form['bg_image']['bg_path']['#default_value'];
    $file = file_save_upload('bg_upload');
    if ($file) {
        $parts = pathinfo($file->filename);
        $destination = 'public://' . $parts['basename'];
        $file->status = FILE_STATUS_PERMANENT;
        if (file_copy($file, $destination, FILE_EXISTS_REPLACE)) {
            $_POST['bg_path'] = $form_state['values']['bg_path'] = $destination;
            // If new file has a different name than the old one, delete the old
            if ($destination != $previous) {
                drupal_unlink($previous);
            }
        }
    } else {
        // Avoid error when the form is submitted without specifying a new image
        $_POST['bg_path'] = $form_state['values']['bg_path'] = $previous;
    }
}
 /**
  * Save uploaded file. Call this from the form submit handler
  * @return
  * 		true if success, false if not
  * @param object $file_field[optional]
  * 		field name of the form
  * @param object $file_type[optional]
  * 		acceptable MIME type substring, e.g. 'image/'
  */
 function saveFile($file_field = 'attachment', $file_type = '')
 {
     if (isset($_FILES[$file_field]) && !empty($_FILES[$file_field]['name'])) {
         // we only care about single file uploads here
         $uploadkey = '';
         //the original name of the file is $_FILES[$file_field]['name'][$upload_key]
         if (is_array($_FILES[$file_field]['name'])) {
             foreach ($_FILES[$file_field]['name'] as $key => $val) {
                 $uploadkey = $key;
                 break;
             }
         }
         // valid attachment ?
         if ($file_type != '') {
             if (!eregi($file_type, $uploadkey == '' ? $_FILES[$file_field]['type'] : $_FILES[$file_field]['type'][$uploadkey])) {
                 // invalid data mime type found
                 return false;
             }
         }
         //01. we store the file into the file_managed table temporarily, and get the file object
         $file = file_save_upload($uploadkey, array(), NULL);
         //02. we get the file id in the file_managed table, and by using the file id together with the original filename, we create the new filename
         //also, we store the file id into the last_upload_id
         $filename = $file->fid . $_FILES[$file_field]['name'][$uploadkey];
         $this->last_uploaded_id = $file->fid;
         //03. we save the file to be uploaded into the public file directory.
         $file = file_move($file, 'public://' . $filename, FILE_EXISTS_REPLACE);
         //04. set file the status to be permanently and save the file.
         $file->status = FILE_STATUS_PERMANENT;
         variable_set('file_id', $file->fid);
         file_save($file);
         //upload success;
         return true;
     } else {
         // invalid attachment data found
         return false;
     }
 }
function asu_webspark_bootstrap_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('picture_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']['picture_upload'] = $file;
        } else {
            // File upload failed.
            form_set_error('logo_picture', t('The logo could not be uploaded.'));
        }
    }
    if ($form_state['values']['picture_path']) {
        $path = _system_theme_settings_validate_path($form_state['values']['picture_path']);
        if (!$path) {
            form_set_error('picture_path', t('The custom logo path is invalid.'));
        }
    }
}
Example #20
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Process the upload and perform validation. Note: we're using the
     // form value for the $replace parameter.
     if (!$form_state->isValueEmpty('file_subdir')) {
         $destination = 'temporary://' . $form_state->getValue('file_subdir');
         file_prepare_directory($destination, FILE_CREATE_DIRECTORY);
     } else {
         $destination = FALSE;
     }
     // Setup validators.
     $validators = array();
     if ($form_state->getValue('is_image_file')) {
         $validators['file_validate_is_image'] = array();
     }
     if ($form_state->getValue('allow_all_extensions')) {
         $validators['file_validate_extensions'] = array();
     } elseif (!$form_state->isValueEmpty('extensions')) {
         $validators['file_validate_extensions'] = array($form_state->getValue('extensions'));
     }
     // The test for drupal_move_uploaded_file() triggering a warning is
     // unavoidable. We're interested in what happens afterwards in
     // file_save_upload().
     if (\Drupal::state()->get('file_test.disable_error_collection')) {
         define('SIMPLETEST_COLLECT_ERRORS', FALSE);
     }
     $file = file_save_upload('file_test_upload', $validators, $destination, 0, $form_state->getValue('file_test_replace'));
     if ($file) {
         $form_state->setValue('file_test_upload', $file);
         drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->getFileUri())));
         drupal_set_message(t('File name is @filename.', array('@filename' => $file->getFilename())));
         drupal_set_message(t('File MIME type is @mimetype.', array('@mimetype' => $file->getMimeType())));
         drupal_set_message(t('You WIN!'));
     } elseif ($file === FALSE) {
         drupal_set_message(t('Epic upload FAIL!'), 'error');
     }
 }
Example #21
0
File: Upload.php Project: aakb/cfia
 /**
  * Operation handler: upload.
  */
 public function opUpload(ImceFM $fm)
 {
     $folder = $fm->activeFolder;
     if (!$folder || !$folder->getPermission('upload_files')) {
         return;
     }
     // Prepare save options
     $destination = $folder->getUri();
     $replace = $fm->getConf('replace', FILE_EXISTS_RENAME);
     $validators = array();
     // Extension validator
     $exts = $fm->getConf('extensions', '');
     $validators['file_validate_extensions'] = array($exts === '*' ? NULL : $exts);
     // File size and user quota validator
     $validators['file_validate_size'] = array($fm->getConf('maxsize'), $fm->getConf('quota'));
     // Image resolution validator.
     $width = $fm->getConf('maxwidth');
     $height = $fm->getConf('maxheight');
     if ($width || $height) {
         $validators['file_validate_image_resolution'] = array(($width ? $width : 10000) . 'x' . ($height ? $height : 10000));
     }
     // Name validator
     $validators[get_class($this) . '::validateFileName'] = array($fm);
     // Save files
     if ($files = file_save_upload('imce', $validators, $destination, NULL, $replace)) {
         $fs = \Drupal::service('file_system');
         foreach (array_filter($files) as $file) {
             // Set status and save
             $file->setPermanent();
             $file->save();
             // Add to the folder and to js response.
             $name = $fs->basename($file->getFileUri());
             $folder->addFile($name)->addToJs();
         }
     }
 }
Example #22
0
/**
 * This is a hook used by node modules. It is called after load but before the
 * node is shown on the add/edit form.
 *
 * @param $node
 *   The node being saved.
 *
 * For a usage example, see image.module.
 */
function hook_prepare($node)
{
    if ($file = file_check_upload($field_name)) {
        $file = file_save_upload($field_name, _image_filename($file->filename, NULL, TRUE));
        if ($file) {
            if (!image_get_info($file->uri)) {
                form_set_error($field_name, t('Uploaded file is not a valid image'));
                return;
            }
        } else {
            return;
        }
        $node->images['_original'] = $file->uri;
        _image_build_derivatives($node, TRUE);
        $node->new_file = TRUE;
    }
}
Example #23
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $validators = array('file_validate_extensions' => array('opml xml'));
     if ($file = file_save_upload('upload', $validators, FALSE, 0)) {
         $data = file_get_contents($file->getFileUri());
     } else {
         // @todo Move this to a fetcher implementation.
         try {
             $response = $this->httpClient->get($form_state->getValue('remote'));
             $data = (string) $response->getBody();
         } catch (RequestException $e) {
             $this->logger('aggregator')->warning('Failed to download OPML file due to "%error".', array('%error' => $e->getMessage()));
             drupal_set_message($this->t('Failed to download OPML file due to "%error".', array('%error' => $e->getMessage())));
             return;
         }
     }
     $feeds = $this->parseOpml($data);
     if (empty($feeds)) {
         drupal_set_message($this->t('No new feed has been added.'));
         return;
     }
     // @todo Move this functionality to a processor.
     foreach ($feeds as $feed) {
         // Ensure URL is valid.
         if (!UrlHelper::isValid($feed['url'], TRUE)) {
             drupal_set_message($this->t('The URL %url is invalid.', array('%url' => $feed['url'])), 'warning');
             continue;
         }
         // Check for duplicate titles or URLs.
         $query = $this->feedStorage->getQuery();
         $condition = $query->orConditionGroup()->condition('title', $feed['title'])->condition('url', $feed['url']);
         $ids = $query->condition($condition)->execute();
         $result = $this->feedStorage->loadMultiple($ids);
         foreach ($result as $old) {
             if (strcasecmp($old->label(), $feed['title']) == 0) {
                 drupal_set_message($this->t('A feed named %title already exists.', array('%title' => $old->label())), 'warning');
                 continue 2;
             }
             if (strcasecmp($old->getUrl(), $feed['url']) == 0) {
                 drupal_set_message($this->t('A feed with the URL %url already exists.', array('%url' => $old->getUrl())), 'warning');
                 continue 2;
             }
         }
         $new_feed = $this->feedStorage->create(array('title' => $feed['title'], 'url' => $feed['url'], 'refresh' => $form_state->getValue('refresh')));
         $new_feed->save();
     }
     $form_state->setRedirect('aggregator.admin_overview');
 }
 /**
  * Override. Handle the file upload process before creating an actual entity.
  * The file could be a straight replacement, and this is where we handle that.
  */
 public function createEntity()
 {
     if ($this->checkEntityAccess('create', 'file', NULL) === FALSE && $this->checkGroupAccess('create') === FALSE) {
         // User does not have access to create entity.
         $params = array('@resource' => $this->getPluginKey('label'));
         throw new RestfulForbiddenException(format_string('You do not have access to create a new @resource resource.', $params));
     }
     $destination = 'public://';
     // do spaces/private file stuff here
     if (isset($this->request['private'])) {
         $destination = 'private://';
     }
     if (isset($this->request['vsite'])) {
         $path = db_select('purl', 'p')->fields('p', array('value'))->condition('id', $this->request['vsite'])->execute()->fetchField();
         $destination .= $path . '/files';
     }
     $writable = file_prepare_directory($destination, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY);
     if ($entity = file_save_upload('upload', $this->getValidators(), $destination, FILE_EXISTS_REPLACE)) {
         if (isset($this->request['vsite'])) {
             og_group('node', $this->request['vsite'], array('entity_type' => 'file', 'entity' => $entity));
             $entity = file_load($entity->fid);
         }
         if ($entity->status != FILE_STATUS_PERMANENT) {
             $entity->status = FILE_STATUS_PERMANENT;
             $entity = file_save($entity);
         }
         $wrapper = entity_metadata_wrapper($this->entityType, $entity);
         return array($this->viewEntity($wrapper->getIdentifier()));
     } elseif (isset($_FILES['files']) && $_FILES['files']['errors']['upload']) {
         throw new RestfulUnprocessableEntityException('Error uploading new file to server.');
     } elseif (isset($this->request['embed']) && module_exists('media_internet')) {
         $provider = media_internet_get_provider($this->request['embed']);
         $provider->validate();
         $validators = array();
         // TODO: How do we populate this?
         $file = $provider->getFileObject();
         if ($validators) {
             $file = $provider->getFileObject();
             // Check for errors. @see media_add_upload_validate calls file_save_upload().
             // this code is ripped from file_save_upload because we just want the validation part.
             // Call the validation functions specified by this function's caller.
             $errors = array_merge($errors, file_validate($file, $validators));
         }
         if (!empty($errors)) {
             throw new MediaInternetValidationException(implode("\n", $errors));
         } else {
             // Providers decide if they need to save locally or somewhere else.
             // This method returns a file object
             $entity = $provider->save();
             if ($entity->status != FILE_STATUS_PERMANENT) {
                 $entity->status = FILE_STATUS_PERMANENT;
                 $entity = file_save($entity);
             }
             if ($this->request['vsite']) {
                 og_group('node', $this->request['vsite'], array('entity_type' => 'file', 'entity' => $entity));
                 $entity = file_load($entity->fid);
             }
             $wrapper = entity_metadata_wrapper($this->entityType, $entity);
             return array($this->viewEntity($wrapper->getIdentifier()));
         }
     } else {
         if (!$writable) {
             throw new RestfulServerConfigurationException('Unable to create directory for target file.');
         } else {
             // we failed for some other reason. What?
             throw new RestfulBadRequestException('Unable to process request.');
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $local_cache = NULL;
     if ($form_state->getValue('project_url')) {
         $local_cache = update_manager_file_get($form_state->getValue('project_url'));
         if (!$local_cache) {
             drupal_set_message($this->t('Unable to retrieve Drupal project from %url.', array('%url' => $form_state->getValue('project_url'))), 'error');
             return;
         }
     } elseif ($_FILES['files']['name']['project_upload']) {
         $validators = array('file_validate_extensions' => array(archiver_get_extensions()));
         if (!($finfo = file_save_upload('project_upload', $validators, NULL, 0, FILE_EXISTS_REPLACE))) {
             // Failed to upload the file. file_save_upload() calls
             // drupal_set_message() on failure.
             return;
         }
         $local_cache = $finfo->getFileUri();
     }
     $directory = _update_manager_extract_directory();
     try {
         $archive = update_manager_archive_extract($local_cache, $directory);
     } catch (\Exception $e) {
         drupal_set_message($e->getMessage(), 'error');
         return;
     }
     $files = $archive->listContents();
     if (!$files) {
         drupal_set_message($this->t('Provided archive contains no files.'), 'error');
         return;
     }
     // Unfortunately, we can only use the directory name to determine the
     // project name. Some archivers list the first file as the directory (i.e.,
     // MODULE/) and others list an actual file (i.e., MODULE/README.TXT).
     $project = strtok($files[0], '/\\');
     $archive_errors = $this->moduleHandler->invokeAll('verify_update_archive', array($project, $local_cache, $directory));
     if (!empty($archive_errors)) {
         drupal_set_message(array_shift($archive_errors), 'error');
         // @todo: Fix me in D8: We need a way to set multiple errors on the same
         // form element and have all of them appear!
         if (!empty($archive_errors)) {
             foreach ($archive_errors as $error) {
                 drupal_set_message($error, 'error');
             }
         }
         return;
     }
     // Make sure the Updater registry is loaded.
     drupal_get_updaters();
     $project_location = $directory . '/' . $project;
     try {
         $updater = Updater::factory($project_location, $this->root);
     } catch (\Exception $e) {
         drupal_set_message($e->getMessage(), 'error');
         return;
     }
     try {
         $project_title = Updater::getProjectTitle($project_location);
     } catch (\Exception $e) {
         drupal_set_message($e->getMessage(), 'error');
         return;
     }
     if (!$project_title) {
         drupal_set_message($this->t('Unable to determine %project name.', array('%project' => $project)), 'error');
     }
     if ($updater->isInstalled()) {
         drupal_set_message($this->t('%project is already installed.', array('%project' => $project_title)), 'error');
         return;
     }
     $project_real_location = drupal_realpath($project_location);
     $arguments = array('project' => $project, 'updater_name' => get_class($updater), 'local_url' => $project_real_location);
     // This process is inherently difficult to test therefore use a state flag.
     $test_authorize = FALSE;
     if (drupal_valid_test_ua()) {
         $test_authorize = \Drupal::state()->get('test_uploaders_via_prompt', FALSE);
     }
     // If the owner of the directory we extracted is the same as the owner of
     // our configuration directory (e.g. sites/default) where we're trying to
     // install the code, there's no need to prompt for FTP/SSH credentials.
     // Instead, we instantiate a Drupal\Core\FileTransfer\Local and invoke
     // update_authorize_run_install() directly.
     if (fileowner($project_real_location) == fileowner($this->sitePath) && !$test_authorize) {
         $this->moduleHandler->loadInclude('update', 'inc', 'update.authorize');
         $filetransfer = new Local($this->root);
         $response = call_user_func_array('update_authorize_run_install', array_merge(array($filetransfer), $arguments));
         if ($response instanceof Response) {
             $form_state->setResponse($response);
         }
     } else {
         // The page title must be passed here to ensure it is initially used when
         // authorize.php loads for the first time with the FTP/SSH credentials
         // form.
         system_authorized_init('update_authorize_run_install', __DIR__ . '/../../update.authorize.inc', $arguments, $this->t('Update manager'));
         $form_state->setRedirectUrl(system_authorized_get_url());
     }
 }
Example #26
0
/**
 * Check and save the uploaded header background image
 */
function mayo_header_bg_validate($element, FormStateInterface $form_state)
{
    global $base_url;
    $validators = array('file_validate_extensions' => array('png gif jpg jpeg apng svg'));
    $file = file_save_upload('header_bg', $validators, "public://", NULL, FILE_EXISTS_REPLACE);
    if (!empty($file)) {
        // change file's status from temporary to permanent and update file database
        if (is_object($file[0]) == 1) {
            $file[0]->status = FILE_STATUS_PERMANENT;
            $file[0]->save();
            $uri = $file[0]->getFileUri();
            $file_url = file_create_url($uri);
            $file_url = str_ireplace($base_url, '', $file_url);
            $form_state->setValue('header_bg_file', $file_url);
        }
    }
}
Example #27
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $this->file = file_save_upload('file', $form['file']['#upload_validators'], 'translations://', 0);
     // Ensure we have the file uploaded.
     if (!$this->file) {
         $form_state->setErrorByName('file', $this->t('File to import not found.'));
     }
 }
Example #28
0
function bootstrap_settings($saved_settings)
{
    $defaults = array('layout_front_display_page_title' => 1, 'layout_front_display_page_content' => 1, 'layout_front_offcanvas_sidebar' => 1, 'mobile_contact_btns_icons' => 1, 'layout_staff_directory_layout' => 'grid', 'mobile_breadcrumb_btn_text' => 'Where am I?', 'mobile_offcanvas_btn_text' => 'What else is in this section?');
    $settings = array_merge($defaults, $saved_settings);
    // Staff directory layout
    $staff_directory_layout = array('rows' => t('rows'), 'grid' => t('grid'));
    // Form processing
    if ($file = file_save_upload('bootstrap_touch_icon_default_upload', array('file_validate_is_image' => array()))) {
        $parts = pathinfo($file->filename);
        $filename = $file->filename;
        if (file_copy($file, $filename, FILE_EXISTS_REPLACE)) {
            $settings['bootstrap_touch_icon_default_path'] = $file->filepath;
        } else {
            dsm('Failed to upload the default touch icon.');
        }
    }
    if ($file = file_save_upload('bootstrap_touch_icon_ipad_upload', array('file_validate_is_image' => array()))) {
        $parts = pathinfo($file->filename);
        $filename = $file->filename;
        if (file_copy($file, $filename, FILE_EXISTS_REPLACE)) {
            $settings['bootstrap_touch_icon_ipad_path'] = $file->filepath;
        } else {
            dsm('Failed to upload the iPad touch icon.');
        }
    }
    if ($file = file_save_upload('bootstrap_touch_icon_iphone_r_upload', array('file_validate_is_image' => array()))) {
        $parts = pathinfo($file->filename);
        $filename = $file->filename;
        if (file_copy($file, $filename, FILE_EXISTS_REPLACE)) {
            $settings['bootstrap_touch_icon_iphone_r_path'] = $file->filepath;
        } else {
            dsm('Failed to upload the iPhone Retina touch icon.');
        }
    }
    if ($file = file_save_upload('bootstrap_touch_icon_ipad_r_upload', array('file_validate_is_image' => array()))) {
        $parts = pathinfo($file->filename);
        $filename = $file->filename;
        if (file_copy($file, $filename, FILE_EXISTS_REPLACE)) {
            $settings['bootstrap_touch_icon_ipad_r_path'] = $file->filepath;
        } else {
            dsm('Failed to upload the iPad Retina touch icon.');
        }
    }
    if ($file = file_save_upload('bootstrap_touch_icon_windows_metro_upload', array('file_validate_is_image' => array()))) {
        $parts = pathinfo($file->filename);
        $filename = $file->filename;
        if (file_copy($file, $filename, FILE_EXISTS_REPLACE)) {
            $settings['bootstrap_touch_icon_windows_metro_path'] = $file->filepath;
        } else {
            dsm('Failed to upload the iPad Retina touch icon.');
        }
    }
    if ($file = file_save_upload('mobile_logo_upload', array('file_validate_is_image' => array()))) {
        $parts = pathinfo($file->filename);
        $filename = $file->filename;
        if (file_copy($file, $filename, FILE_EXISTS_REPLACE)) {
            $settings['mobile_logo_path'] = $file->filepath;
        } else {
            dsm('Failed to upload the mobile logo.');
        }
    }
    // Mobile
    $form['mobile'] = array('#type' => 'fieldset', '#title' => t('Mobile'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    // Mobile header
    $form['mobile']['mobile_nav_bg'] = array('#type' => 'textfield', '#title' => t('Override header background color'), '#size' => 6, '#description' => t('The 6 digit hexidecimal color value. Do not include hash (#).'), '#default_value' => $settings['mobile_nav_bg']);
    // Mobile breadcrumb button text
    $form['mobile']['mobile_breadcrumb_btn_text'] = array('#type' => 'textfield', '#title' => t('Breadcumb toggle text'), '#description' => t('Change the text on the breadcrumb toggle button.'), '#default_value' => $settings['mobile_breadcrumb_btn_text']);
    // Mobile offcanvas toggle button text
    $form['mobile']['mobile_offcanvas_btn_text'] = array('#type' => 'textfield', '#title' => t('Sidebar toggle text'), '#description' => t('Change the text on the sidebar toggle button.'), '#default_value' => $settings['mobile_offcanvas_btn_text']);
    // Custom contact action buttons
    $form['mobile']['mobile_contact_btns'] = array('#type' => 'fieldset', '#title' => t('Mobile contact buttons'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['mobile']['mobile_contact_btns']['mobile_contact_btns_icons'] = array('#type' => 'checkbox', '#title' => t('Display icons?'), '#default_value' => $settings['mobile_contact_btns_icons']);
    // Custom mobile logo
    $form['mobile']['mobile_logo'] = array('#type' => 'fieldset', '#title' => t('Mobile logo'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['mobile']['mobile_logo']['mobile_logo_markup'] = array('#type' => 'markup', '#value' => t('<p>Optional. Upload a logo to replace the default on small devices.</p>'));
    $form['mobile']['mobile_logo']['mobile_logo_use'] = array('#type' => 'checkbox', '#title' => t('Replace logo with mobile logo on small devices?'), '#default_value' => $settings['mobile_logo_use']);
    $form['mobile']['mobile_logo']['mobile_logo_path'] = array('#type' => 'textfield', '#title' => t('Path to logo'), '#value' => $settings['mobile_logo_path'], '#default_value' => '');
    $form['mobile']['mobile_logo']['mobile_logo_upload'] = array('#type' => 'file', '#title' => t('Upload image'));
    // If file exists then show image
    if (!empty($settings['mobile_logo_path'])) {
        $form['mobile']['mobile_logo']['mobile_logo_preview'] = array('#type' => 'markup', '#value' => !empty($settings['mobile_logo_path']) ? theme('image', $settings['mobile_logo_path']) : '');
    }
    /*
     * Form components
     */
    // Touch icons fieldset
    $form['touch_icons'] = array('#type' => 'fieldset', '#title' => t('Touch icons'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    // Default touch icon fieldset
    $form['touch_icons']['default_touch_icon'] = array('#type' => 'fieldset', '#title' => t('Default icon'), '#collapsible' => FALSE, '#collapsed' => FALSE);
    $form['touch_icons']['default_touch_icon']['bootstrap_touch_icon_default_description'] = array('#type' => 'markup', '#value' => t('The default touch icon used for older Apple and Android devices.<br />Size: 57x57px.'));
    // Use  apple touch icon
    $form['touch_icons']['default_touch_icon']['bootstrap_touch_icon_default_use'] = array('#type' => 'checkbox', '#title' => t('Use default  touch icon?'), '#default_value' => $settings['bootstrap_touch_icon_default_use']);
    // Default  touch icon path
    $form['touch_icons']['default_touch_icon']['bootstrap_touch_icon_default_path'] = array('#type' => 'textfield', '#title' => t('Path to touch icon'), '#value' => $settings['bootstrap_touch_icon_default_path'], '#default_value' => '');
    // Default touch icon file upload
    $form['touch_icons']['default_touch_icon']['bootstrap_touch_icon_default_upload'] = array('#type' => 'file', '#title' => t('Upload image'));
    // Default  touch icon preview
    // If file exists then show image
    if (!empty($settings['bootstrap_touch_icon_default_path'])) {
        $form['touch_icons']['default_touch_icon']['bootstrap_touch_icon_default_preview'] = array('#type' => 'markup', '#value' => !empty($settings['bootstrap_touch_icon_default_path']) ? theme('image', $settings['bootstrap_touch_icon_default_path']) : '');
    }
    // ipad touch icon fieldset
    $form['touch_icons']['ipad_touch_icon'] = array('#type' => 'fieldset', '#title' => t('iPad icon'), '#collapsible' => FALSE, '#collapsed' => FALSE);
    // Use ipad touch icon
    $form['touch_icons']['ipad_touch_icon']['bootstrap_touch_icon_ipad_use'] = array('#type' => 'checkbox', '#title' => t('Use iPad touch icon?'), '#default_value' => $settings['bootstrap_touch_icon_ipad_use']);
    // ipad icon path
    $form['touch_icons']['ipad_touch_icon']['bootstrap_touch_icon_ipad_path'] = array('#type' => 'textfield', '#title' => t('Path to iPad touch icon'), '#value' => $settings['bootstrap_touch_icon_ipad_path'], '#default_value' => '');
    // ipad icon file upload
    $form['touch_icons']['ipad_touch_icon']['bootstrap_touch_icon_ipad_upload'] = array('#type' => 'file', '#title' => t('Upload image'));
    // ipad icon preview
    // If file exists then show image
    if (!empty($settings['bootstrap_touch_icon_ipad_path'])) {
        $form['touch_icons']['ipad_touch_icon']['bootstrap_apple_touch_icon_ipad_preview'] = array('#type' => 'markup', '#value' => !empty($settings['bootstrap_touch_icon_ipad_path']) ? theme('image', $settings['bootstrap_touch_icon_ipad_path']) : '');
    }
    // iPhone Retina touch icon fieldset
    $form['touch_icons']['iphone_r_touch_icon'] = array('#type' => 'fieldset', '#title' => t('iPhone Retina icon'), '#collapsible' => FALSE, '#collapsed' => FALSE);
    // Use iPhone Retina touch icon
    $form['touch_icons']['iphone_r_touch_icon']['bootstrap_touch_icon_iphone_r_use'] = array('#type' => 'checkbox', '#title' => t('Use iPhone retina touch icon?'), '#default_value' => $settings['bootstrap_touch_icon_iphone_r_use']);
    // iPhone Retina icon path
    $form['touch_icons']['iphone_r_touch_icon']['bootstrap_touch_icon_iphone_r_path'] = array('#type' => 'textfield', '#title' => t('Path to iPhone Retina touch icon'), '#value' => $settings['bootstrap_touch_icon_iphone_r_path'], '#default_value' => '');
    // iPhone Retina icon file upload
    $form['touch_icons']['iphone_r_touch_icon']['bootstrap_touch_icon_iphone_r_upload'] = array('#type' => 'file', '#title' => t('Upload image'));
    // iPhone Retina icon preview
    // If file exists then show image
    if (!empty($settings['bootstrap_touch_icon_iphone_r_path'])) {
        $form['touch_icons']['iphone_r_touch_icon']['bootstrap_apple_touch_icon_iphone_r_preview'] = array('#type' => 'markup', '#value' => !empty($settings['bootstrap_touch_icon_iphone_r_path']) ? theme('image', $settings['bootstrap_touch_icon_iphone_r_path']) : '');
    }
    // iPad Retina touch icon fieldset
    $form['touch_icons']['ipad_r_touch_icon'] = array('#type' => 'fieldset', '#title' => t('iPad Retina icon'), '#collapsible' => FALSE, '#collapsed' => FALSE);
    // Use iPad Retina touch icon
    $form['touch_icons']['ipad_r_touch_icon']['bootstrap_touch_icon_ipad_r_use'] = array('#type' => 'checkbox', '#title' => t('Use iPad retina touch icon?'), '#default_value' => $settings['bootstrap_touch_icon_ipad_r_use']);
    // iPad Retina icon path
    $form['touch_icons']['ipad_r_touch_icon']['bootstrap_touch_icon_ipad_r_path'] = array('#type' => 'textfield', '#title' => t('Path to iPad Retina touch icon'), '#value' => $settings['bootstrap_touch_icon_ipad_r_path'], '#default_value' => '');
    // iPad Retina icon file upload
    $form['touch_icons']['ipad_r_touch_icon']['bootstrap_touch_icon_ipad_r_upload'] = array('#type' => 'file', '#title' => t('Upload image'));
    // iPad Retina icon preview
    // If file exists then show image
    if (!empty($settings['bootstrap_touch_icon_ipad_r_path'])) {
        $form['touch_icons']['ipad_r_touch_icon']['bootstrap_apple_touch_icon_ipad_r_preview'] = array('#type' => 'markup', '#value' => !empty($settings['bootstrap_touch_icon_ipad_r_path']) ? theme('image', $settings['bootstrap_touch_icon_ipad_r_path']) : '');
    }
    // Windows metro touch icon fieldset
    $form['touch_icons']['windows_metro_touch_icon'] = array('#type' => 'fieldset', '#title' => t('Windows metro tile'), '#collapsible' => FALSE, '#collapsed' => FALSE);
    // Use Windows metro touch icon
    $form['touch_icons']['windows_metro_touch_icon']['bootstrap_touch_icon_windows_metro_use'] = array('#type' => 'checkbox', '#title' => t('Use Windows metro touch icon?'), '#default_value' => $settings['bootstrap_touch_icon_windows_metro_use']);
    // Use Windows metro touch color
    $form['touch_icons']['windows_metro_touch_icon']['bootstrap_touch_icon_windows_metro_color'] = array('#type' => 'textfield', '#title' => t('Hex color value'), '#size' => 6, '#description' => t('The 6 digit hexidecimal color value. Do not include hash (#).'), '#default_value' => $settings['bootstrap_touch_icon_windows_metro_color']);
    // Windows metro icon path
    $form['touch_icons']['windows_metro_touch_icon']['bootstrap_touch_icon_windows_metro_path'] = array('#type' => 'textfield', '#title' => t('Path to Windows metro icon'), '#value' => $settings['bootstrap_touch_icon_windows_metro_path'], '#default_value' => '');
    // Windows metro icon file upload
    $form['touch_icons']['windows_metro_touch_icon']['bootstrap_touch_icon_windows_metro_upload'] = array('#type' => 'file', '#title' => t('Upload image'));
    // Windows metro icon preview
    // If file exists then show image
    $windows_metro_icon = '<div style="width:144px; height: 144px; padding: 20px 20px; background-color: #' . $settings['bootstrap_touch_icon_windows_metro_color'] . ';"><img src="/' . $settings['bootstrap_touch_icon_windows_metro_path'] . '"></div>';
    if (!empty($settings['bootstrap_touch_icon_windows_metro_path'])) {
        $form['touch_icons']['windows_metro_touch_icon']['bootstrap_apple_touch_icon_windows_metro_preview'] = array('#type' => 'markup', '#value' => $windows_metro_icon);
    }
    // Layout
    $form['layout'] = array('#type' => 'fieldset', '#title' => t('Layout'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    // Layout - Front
    $form['layout']['layout_front'] = array('#type' => 'fieldset', '#title' => t('Front'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['layout']['layout_front']['layout_front_display_page_title'] = array('#type' => 'checkbox', '#title' => t('Show page title?'), '#description' => t('Some designs dont require the page title to be visible. Uncheck if its not needed.'), '#default_value' => $settings['layout_front_display_page_title']);
    $form['layout']['layout_front']['layout_front_display_page_content'] = array('#type' => 'checkbox', '#title' => t('Show page content?'), '#description' => t('Some designs dont require the page content. Uncheck if its not needed.'), '#default_value' => $settings['layout_front_display_page_content']);
    $form['layout']['layout_front']['layout_front_offcanvas_sidebar'] = array('#type' => 'checkbox', '#title' => t('Stop off canvas sidebar?'), '#description' => t('By default, the left sidebar will hide off the screen on small devices. Check box to stop this on the front page.'), '#default_value' => $settings['layout_front_offcanvas_sidebar']);
    // Layout - Staff directory
    $form['layout']['layout_staff_directory'] = array('#type' => 'fieldset', '#title' => t('Staff directory'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['layout']['layout_staff_directory']['layout_staff_directory_layout'] = array('#type' => 'select', '#title' => t('Layout'), '#default_value' => $settings['layout_staff_directory_layout'], '#options' => $staff_directory_layout);
    return $form;
}
Example #29
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     if ($this->moduleHandler->moduleExists('file')) {
         // Handle file uploads.
         $validators = array('file_validate_is_image' => array());
         // Check for a new uploaded logo.
         $file = file_save_upload('logo_upload', $validators, FALSE, 0);
         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->setValue('logo_upload', $file);
             } else {
                 // File upload failed.
                 $form_state->setErrorByName('logo_upload', $this->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, FALSE, 0);
         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->setValue('favicon_upload', $file);
             } else {
                 // File upload failed.
                 $form_state->setErrorByName('favicon_upload', $this->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 ($form_state->getValue('logo_path')) {
             $path = $this->validatePath($form_state->getValue('logo_path'));
             if (!$path) {
                 $form_state->setErrorByName('logo_path', $this->t('The custom logo path is invalid.'));
             }
         }
         if ($form_state->getValue('favicon_path')) {
             $path = $this->validatePath($form_state->getValue('favicon_path'));
             if (!$path) {
                 $form_state->setErrorByName('favicon_path', $this->t('The custom favicon path is invalid.'));
             }
         }
     }
 }
Example #30
-1
/**
 * Custom Validation Hook
 */
function locke_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('seal_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']['seal_upload'] = $file;
        } else {
            // File upload failed.
            form_set_error('seal_upload', t('The seal could not be uploaded.'));
        }
    }
    // If the user provided a path for a seal file, make sure a file
    // exists at that path.
    if ($form_state['values']['seal_path']) {
        $path = _system_theme_settings_validate_path($form_state['values']['seal_path']);
        if (!$path) {
            form_set_error('seal_path', t('The custom seal path is invalid.'));
        }
    }
}