Download & Extend

Import file extension fails validation

Project:String Overrides
Version:7.x-1.8
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:needs review

Issue Summary

Importing string over rides fails because the file type *.po is not in the default list of allowed extentions.

To reproduce goto:
1) admin/config/regional/stringoverrides/import

2) select the *.po file that you exported successfully (after implementing this fix: http://drupal.org/node/1210180#comment-5384618)

3) Select the language

4) Click import button

5) get error message: The specified file my-string-overrides.en_.po could not be uploaded. Only files with the following extensions are allowed: jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp.

_______

I've fixed this but adding upload_validators to the import file field:

stringoverrides_migrate.admin.inc

function stringoverrides_migrate_admin_import() {
  $form = array();
  $form['#attributes'] = array('enctype' => "multipart/form-data");
  $languages = module_exists('locale') ? locale_language_list() : array('en' => t('English'));
  $form['file'] = array(
    //'#type' => 'file',
      // hack matt: only managed_file type can have upload_validators
    '#type' => 'managed_file',
    '#title' => t('File'),
    '#description' => t('Attach your *.po file here to import the string overrides.'),
    // hack matt: *.po fails standard validation
    '#upload_validators' => array(
      'file_validate_extensions' => array('po'),
    ),
  );
 
  $form['lang'] = array(
    '#type' => 'select',
    '#title' => t('Language'),
    '#description' => t('Which language to import the overrides to.'),
    '#options' => $languages,
  );
  $form['import'] = array(
    '#type' => 'submit',
    '#value' => t('Import'),
    '#weight' => 3,
  );
  return $form;
}

This probably isn't actually what you want to do, but it does allow you to at least import the strings. Probably be better to keep the #type as 'file' and implement the extension validation a different way.

nobody click here