Sort view by a node reference field - drupal

I need to sort my view by a specific field that is actually a node reference field.
For some reason, however, the node reference field does not appear in the sort criteria list.
Is there any reason for that? How can I solve this problem?

You can't sort by a node because Drupal wouldn't know the criteria for sorting a node to say which is first and which is second, etc.
I assume you mean that you want to sort by some field (like the title) of a node that is referenced.
To sort by a field in the referenced node, you have to the referenced node in a relationship to join the tables. Them you can simply add a sort by 'title' field but be sure to select the correct relationship under the Relationship drop down when you create the sort field.

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.

how to merge entity reference relationship field value

I am facing problem in drupal views.
In my view display table having relationship with other entity type.
I am not getting desire output. It show duplicate rows with same title due to entity relationship.
I wanted to aggregate entity relationship field with ",".
I already try some module like : view distinct, views_merge_rows.
But did not work for me.
Please suggest some module.
Have a look at Views Calc and if you cant do it in the database Views Aggregator Plus gives you even more options.

Inline term reference field for each checkbox of node reference field

I have a content type with a node reference field biblio attached to it for this which can have multiple values selected. Now I want to attach a vocabulary (term reference) named languages attached to each selected value of the node reference field. I need a solution that will make it easier to manage the database side as well as the widget for the field.![enter image description here][1]
On the left we have list of nodes with their IDs and check box to select each node. What I want to do is, add check boxes to select one or more languages to be attached to the selected node. For this I created a vocabulary named languages but there does not seem to be a direct way to do this using references or entity reference or any of the available modules.
One way would be adding language field to vocabulary it self.
But if you want to allow admin to select term and language while editing nodes in your content type use field collections:
https://www.youtube.com/watch?v=1V1ofpgUw-Y
https://www.drupal.org/project/field_collection

Create filter of an attibute and other of a date range

I've a list of items of my Entity. I want to filter it by an attribute as do SonataAdminBundle or other Admin Generator.
For example, if I have an attribute "color" then in my view should have a select field with the types of color and when the user choose one of them my view should only show the list of items filtered by "color"
How do I do it?
Edit:
I have almost solved first filter creating a form and in the controller action get the attribute using the request. Then I used findBy to filter the query.
Now is time of date range filter and merge it with the filter above. I want to filter my list of items by two o three filters.
How do I get from the controller to return only items that belong to a date range?
What is the sentence DQL to use three filters which are optional? I can filter out for none, one or all filters.
You already mentioned the solution: Doctrine Filters
This is what I use if I only want to get a subset of related entities. I think the Documentation is straight forward.

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