0

We all know that by default drupal allows the users to create Lists consists of (float, integer, decimal and text) field types that can be useful for webforms element, but this kind of list can't be very useful and haven't enough efficiency in content type (of course this is my personal opinion only) However, I think this kind of list can be more flexible and powerful if combine with other types of field like Link and especially in the case of Files.
Because these kind of fields (Link & File) consists of two components Title (can be equal to field label For more convenience) that can be Stable and Value that can be Unstable.
for example I have a predefined, stable and limited list of title, List(text) and against of it there is a list of unstable and changeable of file fields in my custom content type, for this reason I decide to combine the power of lists (like default drupal list(text)) with file upload fields and create new and more powerful field type like List(file) something like below:

enter image description here

Advantages of this field:

  • Not have to change the Description (Title or label of the link) of file field eachtime that you want to upload or update a new file
  • Not have to change ugly file names like '102-32.exe' to something can be more human readable.(If you want to use generic display format)
  • Get rid of any change or add more complexity to template files.
  • Hi Mojtaba, using FIeld API you can add new widget and formatter for your fields. sometimes more details about scenario helps better understanding of your question – Alireza Tabatabaeian Sep 7 '16 at 18:36
  • 1
    Nice to see you too Mr Reyhani, I think what you want is : user checks "Win 64Bit" so a file field shows up and user can upload his/her "win 64Bit" file using that, is it true? – Alireza Tabatabaeian Sep 7 '16 at 19:40
  • @Alireza Tabatabaeian: Yes, that's right. – Mojtaba Reyhani Sep 7 '16 at 19:43
  • 1
    And one more question : "there are only "Win 64,Win 32,Deb 64,Deb 32" or you want a solutions which leads to unlimited titles for fields? I mean are these titles fixed or they can be change? – Alireza Tabatabaeian Sep 7 '16 at 20:26
  • @Alireza Tabatabaeian: Yes, they are limited to that restricted Item only. – Mojtaba Reyhani Sep 8 '16 at 2:23
6
+50

Add 4 file fields to your content type with desired labels (ex. "Win 64bit"), Then you will have this 4 fields in your add content form.

Now it's time to make them optional, first of all using hook_form_alter you can add 4 new elements of class "checkbox" to your form like this:

$form['dependent']['win64'] = array(
  '#type' => 'checkbox',
  '#title' => t('Win 64bit'),
);

and then for your fields add a #states like below :

$form["win 64 file field"]= array(
  '#states' => array(
    'visible' => array(
      ':input[name="dependent[win64]"]' => array('checked' => TRUE),   
  ),
);
  • good solution based on Drupal's API. vote up – Yusef Mohamadi Sep 12 '16 at 6:34
  • @Alireza Tabatabaeian: Thanks for taking the time to help out and reply- I appreciate it greatly, but whatever I try I cant get any result. can you explain a bit more? – Mojtaba Reyhani Sep 13 '16 at 4:11
  • 2
    Did u create a custom module to implement form alter – Shreya Shetty Sep 14 '16 at 13:05
  • 1
    Hi Mr.Reyhani , as @Sherya Shetty mentioned, you need to create a custom module, and don't forget to include proper using in head of your .module file – Alireza Tabatabaeian Sep 15 '16 at 5:54
  • @Alireza Tabatabaeian: Thanks Reza, my problem was solved. – Mojtaba Reyhani Sep 16 '16 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.