I hope this is the place to ask this question. If not please let me know and I will move my question. I am building a site that allows authorized users to upload images of their cars and my client wants them to have the capability of uploading a max number of 24 images. I know that I can set to unlimited but his request was 24. when I do a search for increase max uploads it only shows how to increase the size of the file. I have found a module for D6 "Upload max files". Is their a module that works for D7?

Comments

jmr3460’s picture

I found where this is happening in the field module.
field_ui.admin.inc file
line 1934 I changed 10 to 24.

  $form['field']['cardinality'] = array(
    '#type' => 'select',
    '#title' => t('Number of values'),
    '#options' => array(FIELD_CARDINALITY_UNLIMITED => t('Unlimited')) + drupal_map_assoc(range(1, 24)),
    '#default_value' => $field['cardinality'],
    '#description' => $description,
  );

This will work until the next update.
I have always been told don't hack core.
Didn't find anything else I could do.
Any suggestions?

jmr3460’s picture

What is the deal? I thought I would try my project with Webform and when I created a form and got to my file upload part the max was 10. So I hacked webform. Found the same variable and changed 10 to 24. Is there no module that will allow me to change the value of that function. drupal_map_assoc().

Jaypan’s picture

As you already seem to know, you shouldn't hack core.

If you want to add 24 as an option, implement hook_form_alter(), and add 24 as an option to the element that defines the select list.

jmr3460’s picture

I have never done any hook_ anything before, but if this is the way to do it I will research now and get back with you.

This is the first positive feedback I have gotten on my issue. Thanks again.

jmr3460’s picture

Hook_form_alter is changing the select list but when I try to save it it does not save my selection. It stays at unlimited. this is my code.

/**
 * Implements hook_form_alter().

function select_24_form_alter(&$form, $form_state, $form_id) {
  drupal_set_message("Form ID is : " . $form_id);
}
 */
 
function select_24_form_alter(&$form, &$form_state, $form_id){
   if($form_id == 'field_ui_field_edit_form'){
   
     $form['field']['cardinality'] = array(
    '#type' => 'select',
    '#title' => t('Number of values'),
    '#options' => array(FIELD_CARDINALITY_UNLIMITED => t('Unlimited')) + drupal_map_assoc(range(1, 24)),
    '#default_value' => $field['cardinality'],
    '#description' => $description,
  );
   }
}

This code changes my select list values but saves as unlimited.

This code is in the field_ui.admin.inc file around line 1931.

  $form['field']['cardinality'] = array(
    '#type' => 'select',
    '#title' => t('Number of values'),
    '#options' => array(FIELD_CARDINALITY_UNLIMITED => t('Unlimited')) + drupal_map_assoc(range(1, 10)),
    '#default_value' => $field['cardinality'],
    '#description' => $description,
  );

My goal is to change the range function to (range(1, 24))

I am also getting these notices:
Undefined variable: field in select_24_form_alter() (line 17 of /home/public_html/sites/all/modules/select_24/select_24.module).
Undefined variable: description in select_24_form_alter() (line 18 of /home/public_html/sites/all/modules/select_24/select_24.module).

Jaypan’s picture

You're getting closer, but you're off a little bit on how you are trying to do it.

hook_form_alter() is for altering forms. In this case, you want to alter the element that allows you to select the cardinality. You are defining a new form element, but this is not what you want to do. What you want to do is alter the #options for the existing form element.

You'll want to do something like this:

function select_24_form_alter(&$form, &$form_state, $form_id){
   if($form_id == 'field_ui_field_edit_form'){
     $form['some_element']['cardinality']['#options'] = array(FIELD_CARDINALITY_UNLIMITED => t('Unlimited')) + drupal_map_assoc(range(1, 24));
   }
}

Note that I've used $form['some_element']. This will not be the correct path to the element. You'll need to do some digging yourself to find out what the correct path to the element is. You can do this by dumping the form first, and analyzing the data to find the actual path to the element. You can dump the form data by doing the following:

function select_24_form_alter(&$form, &$form_state, $form_id){
  if($form_id == 'field_ui_field_edit_form'){
    die('<pre>' . print_r($form, TRUE) . '</pre>');
  }
}

This will dump the form to the screen.

jmr3460’s picture

Thank you so very much. When I added your print_r function I got a look at a var_dump of the page and found this:


   [field] => Array
        (
            [#type] => fieldset
            [#title] => Images field settings
            [#description] => 
These settings apply to the Images field everywhere it is used.


            [#tree] => 1
            [cardinality] => Array
                (
                    [#type] => select
                    [#title] => Number of values
                    [#options] => Array
                        (
                            [-1] => Unlimited
                            [1] => 1
                            [2] => 2
                            [3] => 3
                            [4] => 4
                            [5] => 5
                            [6] => 6
                            [7] => 7
                            [8] => 8
                            [9] => 9
                            [10] => 10
                        )

                    [#default_value] => 24
                    [#description] => Maximum number of values users can enter for this field.
                )

            [settings] => Array
                (
                    [uri_scheme] => Array
                        (
                            [#type] => radios
                            [#title] => Upload destination
                            [#options] => Array
                                (
                                    [public] => Public files
                                )

                            [#default_value] => public
                            [#description] => Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.
                        )

                    [default_image] => Array
                        (
                            [#title] => Default image
                            [#type] => managed_file
                            [#description] => If no image is uploaded, this image will be shown on display.
                            [#default_value] => 0
                            [#upload_location] => public://default_images/
                        )

                )

        )
        

I followed the list up the chain and saw that #options was in the cardinality array and that array was in the field array. I then replaced the some_element parameter with field and not only worked the first submit it got rid of my errors.

Thank you very much Jaypan! You have helped me so very much.

Dev1.addweb’s picture

You can use following form_alter function in your custom module to do the trick.

function YOURMODULE_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id){
  if($form['#field']['field_name'] == 'YOUR FIELD NAME') { 
    $form['field']['cardinality']['#options']['24'] = '24';
  }
}

Let me know if you face any query/concern regarding this.

Thanks!