getting all ImageFields associated with a node - drupal

How do i get all the image fields attached to a content type on a full node without knowing the field names? Just out of curiosity, is there a way we can get all the fields of a specific type?
I am developing a module that needs image fields tied to a specific node and i'm using hook_node_view for fetching the node data.
I already viewed following post and it seems pretty relevant but i had difficulty understanding.
How to get the first image field from a node without knowing the field's name?

This can be done by checking all the fields of your content type & check its "type" field
if the type field is a image you can render it

Well, i finally found the function i was looking for and it was pretty simple. All i had to do was to get all the fields field_info_instances() with $entity_type as the first parameter and then iterating over the result to get the widget type 'image_image' for ImageFields.

Related

How do I get the location field to show anything in plone-4.x collections

I am trying to use a collection that will list items by state and provide a link to them in the location field of a table listing. The reason the location is important is that the same item can be added to lots of different folders/objects, so the title and type is not informative enough. Anyway, my problem is that the location gives a blank entry in the table displaying the collection. I have tried this for all types of items on my site: pages, folders, custom dexterity content types, etc.. Any hints?
Present configuration is Plone-4.3
Thanks.
The "location" field you are using is probably the ones only populated by the Event content type (please, check it).
If I'm not wrong, you can:
add a new index to the catalog that index the getLocation attribute, that will load the "Location" metadata; then add a new collection configuration for loading this new metadata
add a new indexer that will load the getLocation information using the same "location"
The 1 is the easy way (probably you can do all TTW) but way 2 is cleaner (but require some development)

Plone and dexterity custom index

I've created a custom folderish content type (bobo) using dexterity and a custom index (ibobo) in the catalog.
I'm able to put images inside bobo with no problem.
The problem is the images are being indexed in ibobo and I don't want this.
The ibobo index is working well when I change bobo data but the images keep the old data in its ibobo index.
It is crazy because images don't have ibobo index.
How can I avoid images indexing in this case?
Thank you.
If I understood correctly, you want use a dedicated index for you content type and avoid indexing anything else into your index.
You can achieve this by
Create a custom indexer using plone.indexerfor you content type interface.
Create an another indexer using plone.indexer for zope.interface.Interface that only to raises AttributeError.
That should stop the default indexing and only your dedicated content type gets indexed into your index.
The issue is, that for historical reasons Plone (Zope2/ZCatalog) indexes try to index everything, which either has an attribute with the name of the index (or its configured indexable attribute) or can acquire a such attribute using acquisition.

Weird hierarchical select requirement for Drupal

Anybody know of a module or other way to do a hierarchical select in Drupal that first pulls in a taxonomy vocabulary from which you select and then based on your taxonomy selection limits a CCK related node field to a specific content type.
AFAIK, there is no module that does that. A node reference field does allow you to specify a view as its source, but unfortunately, you cannot pass a dynamic argument to that view.
If you can figure out a way to take the selected taxonomy term and pass it to the view as an argument to filter the results by, you're done...
There is a start for something similar on http://drupal.org/node/473670, but that code fetches the dynamic argument on the PHP level from a GET variable. The behavior you describe should work on the Javascript level, because your argument is a variable selected on the form by the user.

Drupal: Display only specific NodeReferrer field in Views

I have a content type appointment with a date field that references nodes of the content type person using the Nodereference module. In the content type person I added a Nodereferrer field that shows the reverse of this references (Person -> appointments).
I now want to create a view of person nodes that shows the last appointment date of that person. I can create a View of persons with a relationship to appointments that displays all appointments, but I have no idea on how to display only the most recent one.
Any ideas on how to achieve this?
Personally I have not had much success with using views and node reference. It never seems to work out the relationships properly.
So my advice would be to write your own query. If you look here you can see a way to override the SQL generated by views, so you still get a lot of the goodness which comes with views.
By the way I would be very interest to see if there is a better answer than this
Instead of adding the Nodereferrer field to the view, try adding the Nodereferrer relationship then adding the Node title (using that relationship) as a field. You should be able to sort from newest to oldest, and then set the view to be Distinct so that only the first row for each person shows up.

Anyone familiar in Drupal 6 Services module specifically node.save

I can save/update on regular fields but I'm having trouble saving/updating CCK fields. here's an example node.save() XML request - http://pastebin.com/m5ceca16
I'm assuming your XML data mirrors the node object format.
A CCK field 'field_custom' will be accessible via $node->field_custom. Regardless of type and the limit on number of entries, fields are always arrays. If the CCK field only allows one entry, it is $node->field_custom[0].
The indexes below that level depend on the field type. Most, especially numeric and text fields, are 'value' (eg., $node->field_custom[0] = 'foo'). I've used Nodereference fields which use 'nid', from which I would assume Userreference fields use 'uid'.
The structure of your XML seems correct. I would check the structure of a node object on the site (using a var_dump() or the devel module) to make sure all of your array keys and variable names are correct for your field and field type.
2 things to check:
A var_dump of the results of a node_load() doesn't give you the exact format you should use. Your XML must emulate the input format of the node edit form. So while a var_dump might show you several taxonomy terms in an array, the node edit form may expect the taxonomy terms separated by commas. Off-hand I don't see any fields in your example that this would seem to apply to but I mention it anyway.
Your "changed" timestamp must not be in the future, nor must it be too far in the past. The node will not save if this is off by much. This can be an issue if the clocks on one of the computers isn't very accurate. I had an issue where my services server was about 20 seconds behind my services client so all the updates were getting rejected (the server apparently rejected them on the grounds that they were from the future).

Resources