Drupal views: list referenced nodes except the one used as contextual filter - drupal

i have the following case: I am building a website that has information on filmmakers and their films. I have a node type for the filmmaker, with biographical content, etc and another one for the films, with a field 'author' that references one or more of the filmmakers (since one film may have been made by several of them).
I also have a views block called 'filmography' that lists all the films whose author is the filmmaker (node) the user is seeing. Setting this up with a contextual filter was quite easy.
But now I want to present in this block along with the film name, all the filmmakers that may have made the film ('author' field in the film node) and that are different from the filmmaker being viewed. Displaying all the filmmaker nodes referenced by the author field is immediate, but I want to remove the filmmaker that I am using in the contextual filter. The goal is to get something like this:
Filmmaker 1
Movie 1
Movie 2 (with Filmmaker 2)
Movie 3
I have the notion that this might be done using views php and filtering the node references returned, but I wonder if there is an easier solution for that...
Thanks
Update: I have managed to get a result using the Views Field View module, passing the list of referenced nodes (filmmakers) as a contextual filter (node ID) and then adding another contextual filter (node ID as well) as an exclusion, and getting the default value of the letter from 'node id from URL option' (that is, from filmmaker's page the filmography view is embedded in). Keeping the question open for a while to get other, possibly more efficient, alternatives.

As I read your question, the Views Field View module popped into my mind as the obvious solution (then I saw your edit). I think this will still be your best bet. Definitely avoid using php fields as that is not a good practice in general from a security standpoint. If you are concerned about efficiency/performance, then you should just use views caching setting under the advanced options. Seems like this option is always looked over.
If you are looking for alternative options, one might be to use rendered nodes as your View style instead of fields, then use Display Suite to generate additional display modes beyond "Default" and "Teaser," create a view with the filters, then use the Entity Views Attachment (EVA) module to insert a view as a display mode field. While this is certainly a robust approach, it adds a lot of processing overhead with the rendered entities, so you definitely want to cache the results of that as well.
p.s. You might get faster/more responses over at https://drupal.stackexchange.com/

Related

Drupal 8 Views Question Involving Entity Reference

Trying to figure out views relationships and filters.
I'm trying to make a view that has the title of the page match the entity reference of the same page and make it reactive so I only need one. EX.) Page about animals, which there are nodes referencing the animal page as an entity reference.
Firstly, you have to take one unique field which can identify whether particular node is for animals or etc.
After that, In your views you need to select that field name in contextual filter and select option as you can see in screenshot and then save it.

Bulk update of Drupal 7 taxonomy terms

My Drupal 7 site has a bit redundant taxonomy structure with taxonomy terms "Article" and "Document" being used synonymously. Hence a large number (several hundreds) of nodes has both "Article" and "Document" terms applied to them. What I want to do is to "separate" these terms shuffling nodes randomly between them so about half of the nodes currently marked "Article" and "Document" will only have "Article" term and the other half will only be marked "Document".
What's the best way to go about this? Is there a module for bulk updating nodes adding/removing taxonomy terms? Am I better off with updating the database directly?
Thank you.
I found a solution for this:
I have "Administrative Views" module installed (Requires: Views, Chaos tools, Views Bulk Operations, Entity API - links are on the module page under dependencies).
From there you select the nodes you want to change and select "change value" in the "operations" dropdown and hit execute. Under "Fields for type {your nodetype}" you can click "tags" for example and enter the new value to overwrite all - or you click "Add new value(s) to Tags, instead of overwriting the existing values." and the value will be added.
It turns out adding a tag this way, there are new tags added for every updated node - so if you edit 20 nodes and add the tag "stackoverflow" there will be 20 tags called "stackoverflow" in the terms list. You may then merge the duplicates with "Term Merge" into one final term.
Since you need to update the taxonomy structure in bulk you can use - Taxonomy Manager
http://drupal.org/project/taxonomy_manager/
Which apart from other features has -
dynamic treeview
mass deleting
mass adding of new terms
moving of terms in hierarchies
You can also take a look at a similar question -
https://drupal.stackexchange.com/questions/11494/adding-taxonomy-terms-to-multiple-nodes-at-once
If nothing helps updating the database sure seems a simpler option, but use it only if you are very sure of your query, and don't forget to take a backup before.. :)
Taxonomy Manager is the a very good module for these purposes I used it myself to tag and add vocabularies to my website that has more than 100 posts. Its interface is also very intuitive and user-friendly.

Views 3 Relationship Handler

I am trying to write a relationship handler for Views 3 in Drupal 7, but am failing even to begin.
Basically, I have a bunch of nodes of various types all with the same field attached to them. This field is a reference field linking off to a Civicrm contact - but that's not important, as essentially these fields just contain integers.
Now, let's say I have a node of content type 'story', and its reference field contains the integer, oh, let's say 55. In addition, there are nodes of content type 'news' which also contain the reference ID 55.
I want to build a block view, that sits on the story page, that reads in the node's nid as its argument, and then through a relationship it discovers all other nodes that contain the same reference integer as itself.
(In my head, the sql looks something like: SELECT n.nid FROM node n INNER JOIN node n2 ON n.reference = n2.reference [Assuming, for the sake of simplicity, the field data is kept in the node table]).
How do I create a Views handler that caters for this relationship? The only documentation I can find is the views api, which is for version 2 and not 3, and besides is utterly unhelpful. Reading various module's views handlers is not helping either, and views tutorials on the web are almost non-existent.
What are you doing and what is the problem? It sounds like you have everything you need right here...the nid as an argument and the reference field as a relationship. What are your filters set to? and what display type are you using? You could just have the block display some information without sorting, arguments, or relationships and then using the devel module you can change the tpl file for the block to dpm($views) and see what information you have access to.
Let us know what you have configured so far and what your results are if any. Remember that you can use the nid as an argument in the preview, so if the nid is 213 you can type 213 in the preview field (make sure the display is set to the block you are talking about) and see what comes up.
Good luck.

Using Node Reference without popup?

I am using two content types company and Employee . I am using node reference here(Company -> Employee). Within the Company form , the Employee node comes as a popup ,Employee form need to bring the display and functionality to the company form and should keep the node reference. .
Unfortunately, embedding one form in another is nearly impossible in Drupal. That is due to its form-handling and node-handling system.
If you want such relationships, you often need to write a simple, small module that maintains relationships in the database, offers forms to insert/update them and ways to extend nodes with your relational behaviour.
Best I could suggest is an iFrame holding the employee form - but still it's not very elegant.

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.

Resources