Drupal: getting attached files from nid and field name - drupal

In Drupal 7.x, given a nid and a file field name, I'm trying to get the files (as $fid or objects) which have been uploaded as file attachments to that node.
Drupal will populate the uploaded files only when they are set as "displayed" but I need to do this for all the files of that field, no matters how they display setting is.
I've spent quite some time investigating into this but the new d7 file api looks pretty obscure from a documentation and code point of view. IMHO, too much "drupal magic" happening there for a fast understanding.
Any pointer to good documentation and/or suggestion on the solution greatly appreciated.
Thanks.

Although your question seems a little unclear to me, but according to me:
you want to get all the files attached to a node. Just do $node = node_load($nid); and then check your $node->field_name['LANGUAGE_NONE'/lang code]
This will give you an array of files uploaded using that filefield.
Thanks

Related

Wanted API codes to download files of particular extension from Windchill

Can any one help me with the code to download all files of particular extension (say *.prt or *.asm) from windchill to local. Please suggest suitable API
It's not really the way Windchill works... Windchill is a PDM software, so you should first search for the correct metadata (certainly EPMDocument in your case), and then get the attach files. You'll have to specify the type of attachment you want to have (primary, secondary content, etc.)
=> you need to understand the datamodel and specify what you really want to do.
You can do a query using queryspec and sort. The download part Im not sure about, but it is possible.

how to implement a type file in symfony2

The problem is to handle the file type fields.
By doing this I take the field as "Browse to upload the file" now to save time remains. I do not know how to handle it properly if anyone has an example. would be very useful.
The cookbook has a nice tutorial
http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html
Plus more basics in the reference
http://symfony.com/doc/current/reference/forms/types/file.html

How does a CCK formatter know which field and node it's referring to?

I'm new to CCK development and I'm having some problems creating a new field for my system.
In particular, I'm writing a widget that attaches a file to a field. Once that happens, how can a formatter function figure out which field and node it's referring to in order to retrieve the right file associated with that field? Is there any way to store the file information directly in the $element array?
I'd appreciate examples that show how this could be done. I'd also appreciate good references on how to build widgets and formatters...
Thanks so much!
A long time ago I wrote about CCK field formatters on my blog.
Field formatters are basically theme functions, CCK call them when it has gotten the content and want it rendered. The nature of the content can vary a lot, it depends what field/widget that is used.
I'm not exactly sure what your end goal is, but there may already be a module that does what you are trying to do. If you could explain it a little more I can let you know if I know of a module that would be of help to you.

How to programmatically add new nodequeue?

I'm writing an install file for a custom module, that needs to create some new nodequeues. But a drupal and google search are so far turning up empty. Anyone know how to do this?
Drupal 6
The closet thing you come to a API function to save nodes is nodequeue_save, but all you really need to do, is to insert some data to the {nodequeue_queue} table. You can do it yourself with SQL or use the function, but the result will be the same.
You should remember to add the nodequeue module as a dependency in your module's info file and check if it's installed before running your stuff in hook_install.
Some API documentation might help you on the road? http://api.lullabot.com/file/contrib/nodequeue/nodequeue.module

Wrong label for a nodereference in Drupal content-type

We have a content-type built using CCK. One of the fields is a node reference. The node picker is using a view to build the options.
A few days ago, everything was working well.
Today, it looks like all node reference fields using views to populate the selection options are displaying the wrong label. Every single label in the option is ``A'', but the actual node number is correct. The form actually works, just the labels are incorrect.
We have tried just about every combination of edit/save, disable/enable, reboot, clear cache, clone the view, rebuild the view, new view, etc, but we still have a big list of As.
If we create a brand new content type with a brand new node reference field, we get the problem.
Through some backup/restore exercises, we have determined that the problem is actually in the database and not in the code.
We can restore our last good backup, but we will lose a decent amount of work we have put into other parts of the database.
We enabled mysql query logging, and the view is actually being called properly, but we cannot track down where the problem is creeping in after that (unraveling the CCK / Views / Drupal plumbing is a challenge).
The install was build with latest stable versions as of April.
The problems referred to in http://drupal.org/node/624422 is similar, but our code versions include the patches mentioned.
Any ideas would be appreciated. Thanks.
I had a similar problem with using views for node reference, after quite a lot of hair pulling it turned out to be that my caching layer was buggy. I was using memcached, but memcached wasn't truned on on the server. It may be worth checking.
Thanks for the responses. We finally got to the bottom of this.
There was a module that was doing a custom hook_views_post_render() that did a prep_replace to rewrite some output. Unknown to us, there are instances where the $output parameter isn't a string, but an array, and this was causing the problem. One of those instances happens to be when you attach a view to a build a select in CCK.

Resources