Hello

Full description of the problem can be found in the following link
https://www.drupal.org/node/2318519

Comments

Giannis Pagonas created an issue.

joseph.olstad’s picture

I recommend seeing my patch in
#2318519: How do I select a file type on /file/add with plupload enabled?

--- a/file_entity/file_entity.pages.inc
+++ b/file_entity/file_entity.pages.inc
@@ -603,6 +603,15 @@ function file_entity_add_upload_multiple_submit($form, &$form_state) {

       $file = file_uri_to_object($destination);
       $file->status = FILE_STATUS_PERMANENT;
+      if (isset($form_state['storage']['type']) || isset($form_state['values']['type'])) {
+        if (!empty($form_state['storage']['type'])) {
+          $file->type = $form_state['storage']['type'];
+        }
+        if (isset($form_state['values']['type'])) {
+          $file->type = $form_state['values']['type'];
+       }
+      }
+

long story short, I'm also using a patch for allowing upload location selection which
https://www.drupal.org/files/issues/allow_selection_of-2000934-30.patch
apply this also to file_entty

Created a file_entity type called 'default_news'

then added a menu link called file/add/default_news so that users can click it and the path becomes file/add/default_news

based on the path or POST value, force the default upload location, use this for validation

I wrote custom validation in :

hook_form_file_entity_add_upload_multiple_alter(&$form, &$form_state, $form_id) {
  $current_path = drupal_get_path_alias(current_path());
  $is_default_news = FALSE;
  if ($current_path == 'file/add/default_news' || $_POST['upload_path'] == 'default_news') {
    $is_default_news = TRUE;
  }
  
    //add the form type to the beginning of file/add/default_news
    $form['type'] = array(
      '#type' => 'radios',
      '#title' => t('File type'),
      '#options' => _custom_admin_get_filetype_candidates($form_state),
      '#default_value' => ($is_default_news == TRUE ? ( $current_path == 'file/add/default_news' ? 'default_news' : 'image' ) : ( $current_path == 'file/add/default_news' ? 'default_news' : 'image' )),
      '#required' => TRUE,
      '#disabled' => ($is_default_news == TRUE ? ( $current_path == 'file/add/default_news' ? TRUE : FALSE ) : ( $current_path == 'file/add/default_news' ? TRUE : FALSE )),
    );

}

function _custom_get_filetype_candidates(&$form_state) {
  $current_path = drupal_get_path_alias(current_path());
  if ($current_path == 'file/add/default_news' || $_POST['upload_path'] == 'default_news' ) {
    $candidates['default_news'] = 'Image for News Default';
  } else {
    $candidates['image'] = 'Image';
    $candidates['audio'] = 'Audio';
    $candidates['document'] = 'Document';
    $candidates['video'] = 'Video';
    if (isset($form_state['storage']['type'])) {
      if ($form_state['storage']['type'] == 'image') {
        $candidates = array();
        $candidates['image'] = 'Image';
      }
      if ($form_state['storage']['type'] == 'audio') {
        $candidates = array();
        $candidates['audio'] = 'Audio';
      }
      if ($form_state['storage']['type'] == 'document') {
        $candidates = array();
        $candidates['document'] = 'Document';
      }
      if ($form_state['storage']['type'] == 'video') {
        $candidates = array();
        $candidates['video'] = 'Video';
      }
    }
  }
  return $candidates;
}