How to add additional fields to a file field/widget in Drupal7 - drupal

I have a file field in Drupal 7 that I need to add additional fields to.
Currently the only available field is the file upload itself and a description. I would like to add a title field and a dropdown with some hard-coded options. I still require all the functionality of the file field.
How can I do this? I think I need to create a new file widget but not sure how to begin.
Thanks.

One solution is to use http://drupal.org/project/field_collection
It basically allows you to group a number of fields together to a single "thing".
http://drupal.org/project/media is a different approach, which makes images, videos and so on to separate entities to which you can attach fields.

You could also create your own field, but it's probably overkill, http://www.agileapproach.com/blog-entry/compound-fields-drupal-7.
Personally I would recommend the Media module, sadly it's a little buggy right now.

Related

Drupal : how to create a view that displays all the content-types

It may sound 'weird' but I need to have a view that lists all the content types I have.
For example i have two content types : contenttypeA, contenttypeB
I want to create a view that just displays the two content types (and show number of items of that type, but that can be done later).
For now what I did is add one content of each content type and list them but only show the 'node type'; it works well if there's at least one content but I want to display even without any content of that content type.
Any idea ?
Introducing the node_type table to Views requires a custom module and some Views API knowledge however http://drupal.org/node/1001222 will give you a head start.
Use a Customfield: PHP code field and custom code the whole thing with PHP. This is provided by the Views Custom Field module.
Use the Table Wizard module to make the node_type table available to views. You may need to use the Data module as well since they say that all future development is going there.
Expose the node_type table yourself by writing a custom module using the Views API as suggested by chx.
Number one is the quick and dirty way, but number 2 might be a little more manageable, but I am not completely sure it will do everything you want. If you do number 3 make sure you contribute back to the community by putting your module on drupal.org.
There is no native functionality in Views to do that. You can write a static page or (overkill) a module that provide a "system"-like type similar to Views Watchdog.

Drupal: how to add pdf links to a block?

I've some blocks in my Drupal website with some text.
I need to other some links in the text, to pdfs (and upload them from back-end).
Can I add some upload fields to the block pages, and link them from the text ?
thanks
Check out the Insert module, which allows you to upload files to a FileField and then easily link to them from within the node body.
I usually just end up attaching them to a node and then linking them manually. Not the answer you were probably looking for, but it works.
If you have views module available you can create a view that lists the pdfs attached to a particular node, using the node id (nid) as an argument, or use more complicated arguments if you want, as long as the fields displayed in the view are the the filefields you used for your pdf you can get pretty creative with how the pdfs are organized.
It's somewhat tricky to get arguments into views blocks but it's certainly possible, using panels, or using other tricks. More info on that:
here: http://drupal.org/node/150482
here: http://drupal.org/node/695124
http://drupal.org/node/161867#comment-1086587
Might not actually help you, but the D7 version of http://drupal.org/project/block_api creates fieldable blocks, which means that you can attach any type of fields to created blocks.
For D6, the solution is more complex I guess. You could create a separate content type, attach the files there (by using Inline, FileField, ...). Then, either write a custom module that exposes a block for each node of that type and then renders the node in those blocks or use Views to create a view of a single node. Using views would be a bit overkill I guess but should be relatively fast if you can use caching..

DRUPAL: combine CCK image and videos in a common ordered list. Possible?

I'm working on multiple videos and images page on Drupal.
I would like to know if I can combine Video and Image CCK fields in back-end content type pages, in order to assign them a common mixed order, when I have multiple images and videos.
ps. I don't want to create a node for each image/video, I prefer to use the CCK fields, since it is easier for my customer to manage the files, change the order and delete them.
thanks
I suppose you can set a generic field type, use filefield module, and in the 'allowed filetypes' setting enter all image and video filetypes (png jpg gif avi flv etc), then also set 'unlimited' for the quantity allowed.
That said, maybe you need to explain your question or situation further, maybe provide a more detailed use case. Everyone seems confused about your question, and your basic structural plan may be flawed.
Usually you want to keep these things in separate fields, then use different views to pull exactly what you want. View1 would pull videos from the video field of the content type, View2 would pull images from the image field of the content type, View3 would pull videos and images, etc. When they are all mixed into one field you have to do extra parsing on the end to get what you want out, and that's more difficult.
But I don't think we understand what you are asking, an example case may help us help you.
If you're just asking if you can have image fields and video fields on the same content type, then the answer is yes.
That said, I have no idea what you mean by "a common mixed order."
You could look at using Views. http://drupal.org/project/views
Set it up to display Nodes and then add in all the fields you want, you can then set the style to be Ordered List. This should give you something similar to what your trying to achieve.

Drupal views: Allowing users to choose sort criteria on node display

I have some nodes I am displaying in a view. They are displayed as nodes, unformatted. I would like the user to be able to choose from some predefined sort criteria ( via drop down list or similar).
So they could pick recently active, most commented, newest, etc., and re-query for new results.
Its easy with tables because you can make the labels clickable, but I do not know how to have similar functionality with a raw node preview display.
Just a thought, from me to me, and for anyone else who may be trying to do this.
An easy, sleezy option would be to just add another page view for each of the required sorts, and provide a link to these other views in the header of each of the pages.
This could also allow for (easier) linking to the individual sorts, so say if you have a sidebar block displaying recently commented nodes, you could adjust the .tpl.php of the block to have the title link to the view displaying the full set of recently commented nodes.
also im pretty sure there should be a way to do this with arguments, but i dont know how
Views 3 supports exposing sort order (just like you can expose filters)
Select the sort order (e.g. add sort by node creation date, then click on the settings for that), you should be able to expose the sort order to the end user. This is just like clicking on the settings for a filter and then choosing to expose it.
Standard views isn't going to support this, so IMO you're best off implementing a custom solution using just a plain old view and this jQuery plugin. You can either do this at the theme layer (the same way as any other JS in a theme) or a custom module (via drupal_add_js() to add the plugin and your bit of custom code). Either way will work, although the custom module has the obvious benefit of being theme independent (and thus more portable).
If you go the custom module route, please consider releasing it as a contrib module on http://drupal.org.

How to theme a view in drupal

Can any one help me out on how to theme a view.
For each view created i want to have different templates.
Theming views can be somewhat tricky, depending on the kind of views you have created and the changes you need to make. Check out this introduction for Views 2, and make sure to install the Advanced Help module to get at the views2 documentation from the views module itself (there will be a link to the documentation on your views overview and edit pages, once you activated the Advanced Help module).
You can also find some questions/answers here on SO (e.g. Drupal 6: How to quickly theme a view?), if you search a bit.
I actually did this the other day. Ill give you a brief overview and expand a little later.
Set up your view; by going to Views -> Add View
Once, your view is completely set up, at the bottom of the view (left column in D6, right-most "Advanced" column in D7), you will see a link called "Theme: Information", click on it.
What you will be presented with is a list of templates (.tpl.php) files that the views uses to theme your data. Basically the file names that are bolded are the files views is using to theme the data.
To Customize Your Views
Select the page you need to theme. For Example, if you created a "Block" view, and I wanted to customize the basic html layout, I would pick a name (other than the one that is currently bolded) that is being displayed to me and create the file in my themes directory (sites/all/zen/custom-file-view-fields-views.tpl.php) - this is if views told me that I could use the filename custom-file-view-fields-views.tpl.php
The next step is knowing what code you need to put in there. The quickest way, is to go back to the theming information in views, click on the link of the file your replacing and grab the code that is presented to you. Paste that code in the file you created.
From here on out, you can now successfully customize that view.
Keep in mind that the theming information presented to you is presented from basic to complex (up to down). So choose which file you need to edit carefully. Ill put up some images in this answer a little later.
Hope this helps! Cheers!
Is there something specific you're trying to accomplish? There's a lot of ways to "theme" a view, unless you mean "theme" in the strict Drupal sense.
Personally I just give the fields classes and use those, rewriting the output to include variables as classes if need be. This tends to be easier and more manageable than modifying TPL files directly.

Resources