You are here

function _minisite_field_validate_minisite_file_settings in Mini site 7

Element validate callback for the allowed file extensions field.

1 string reference to '_minisite_field_validate_minisite_file_settings'
minisite_field_instance_settings_form in includes/minisite.field.inc
Implements hook_field_instance_settings_form().

File

includes/minisite.field.inc, line 384
Minisite field.

Code

function _minisite_field_validate_minisite_file_settings($element, &$form_state) {
  if (!empty($element['#value'])) {
    $extensions = preg_replace('/([, ]+\\.?)/', ' ', trim(strtolower($element['#value'])));
    $extensions = array_filter(explode(' ', $extensions));
    $extensions_array = array_unique($extensions);
    $extensions = implode(' ', array_unique($extensions_array));
    if (!preg_match('/^([a-z0-9]+([.][a-z0-9])* ?)+$/', $extensions)) {
      form_error($element, t('The list of allowed extensions is not valid, be sure to exclude leading dots and to separate extensions with a comma or space.'));
    }
    elseif (_minisite_field_validate_minisite_file_blacklist($extensions_array) === FALSE) {
      form_error($element, t('The list of allowed extensions is not valid. The following extensions are NOT allowed: %extensions-blacklist', array(
        '%extensions-blacklist' => implode(' ', minisite_site_extensions_blacklist()),
      )));
    }
    else {
      form_set_value($element, $extensions, $form_state);
    }
  }
}