View content in blocks depending on selected language - drupal

How can i display content nodes in blocks depending on the selected language by the user?
I already know how to do it for 'normal' nodes, just not in blocks.
Edit: I tried to do this with views. Filtering on a node and content translation: language. The problem is, i don't know how to filter two id's (of the nodes), just one.

If you have created the nodes after each other, you can do it pretty easily, since you can query for a range of node ids.
The views UI doesn't support making OR in where clauses, so it's not easy to make a query that looks like this.
SELECT nid FROM {nodes} WHERE nid = 5 OR nid = 10 OR nid = 17;
Making OR is views have been asked a few times here, I've answer it here.

Related

Use views to select nodes

I'm trying to find a way to let users select nodes from views results, and then get information from the selected nodes (such as node ID) for use in my module. This would probably be done in a form.
More broadly, what I'm trying to accomplish is to present users with a list of nodes tagged with a certain term x, have them to select any number of nodes from that list, and then have my module apply another term y to the selected nodes. I can handle that last part, but I'm struggling with creating a list of nodes that users can select from, and then somehow getting the information about the nodes selected that way.
I assumed views are the way to go but after a lot of searching I haven't found a way to achieve this functionality. Can anyone can show me a solution or point me in the right direction?
Thanks!
I'm using Drupal 7, and Views 7.x-3.7
EDIT: If I had the ability to select nodes with checkboxes via a module like VBO, I would like to do something like the following (terrible) pseudo-code:
foreach (vbo_selected_node) {
$node = vbo_selected_node -> node;
$nid = $node -> nid;
$node = node_load($nid);
$node->field_vocabulary_field['und'][0]['tid'] = $termID;
}
I hope that makes sense. Basically I want to take each selected node and apply another term to it.
I've been through a similar scenario and came up with a solution through custom module. I'm not sure if it is the best option but still you can use node_load_multiple() method. A quick reference can be found in
http://eureka.ykyuen.info/2012/08/08/drupal-7-get-mulitple-nodes-using-entityfieldquery-and-node_load_multiple/

How do I create a page that shows two specific nodes?

We want to create a page that shows two specific nodes.
The first node will be localized content (an article node in the user's language). There will be at least 5 different language versions of that page.
The second node will be a Webform node that the user can submit to "sign" the document. It will be language neutral.
Originally I figured that I could have one Webform node and then translate it into the appropriate languages. But what I discovered was that the "translated" version of the Webform node was, in fact, a completely new node--which means a completely new webform. This makes sense if you think about how Drupal handles multilingual content--each translation is a separate node.
But in the case of our webform, we don't want to split the submissions into 10+ different webform submission sets. Everybody who "signs" has their signatures placed into the same "bin" of data.
I can think of two possible solutions:
Create a page that will display two nodes: the localized version of an "article" node (selected depending on the user's language selection), and the webform.
Create multiple Webform nodes (one per language), and then create a MySQL view that merges all the user submissions into a single set of records. This would allow us to extract our data without a great deal of headache.
I'm not sure if 2 is possible. I'm assuming that I'll have to go with 1. But, so far my efforts to accomplish this have also been fruitless! How can I do this?
-Josh
I think 1 is much easy and possible solution. You can create webform node and make body field as php code (for that you need to enable php filter). And put in body follow lines:
<?php
$nid = NODE_ID;
$node = node_load($nid);
$node_view = node_view($node, 'full');
print drupal_render($node_view);
?>
Just replace NODE_ID with nid of multilanguage node.

How to fetch pretty advanced relation in Drupal 6 - Views 2?

I have three content types: Artist, Artwork, Exhibition. An Exhibition has a field 'artworks' (unlimited values). An Artwork has a field 'artist' (1 value, required).
And there is the relation I can't seem to find with Views: I want all Exhibitions an Artist ever participated in. Which means: on the Artist page, show all Exhibitions all Artworks of this Artist were ever in.
The problem (I think) is that one field (Exhibition.artworks) has many values. Yet Artwork.artist has just 1 value.
I don't know what the problem is =) but it's not working and I've tried a million things. At this point, I'll accept writing SQL queries, but the drupal content database is so incredibly untransparent that I have no idea what to query and how.
Obviously I'd be happiest with an unhacked Views solution, but I'm not getting my hopes up. Anyone experience with relations like this?
You can build dependent relationships that should help you to accomplish this. Use a relationship (Artwork) on exhibition.artworks and a relationship (Artist) on (Artwork).Artist
It would be easier to understand what you're doing with exports of the views & content types.
The database structure for content types in Drupal works as follows;
The node is the base table, with nid as index. Your content types have their own tables, content_type_XXXXXX with all single entry fields (that aren't shared among content types) members of that table. Multiple entry and shared fields get their own table content_field_XXXXXX. All of the tables relate on the nid field, and multiple entry fields use a "delta" to indicate the entry order.

Drupal view to list nodes and comments

I want to create a view that shows the latest posts in a forum and also any latest comments. The comments and the posts would all show in the same view. Is it possible for me to do this?
Thanks in advance,
Ben
In essence: no. Views requires you to choose one main resource in the first step: you there (amongst others) choose to go with either nodes, or comments.
However, with some (ugly) configuration, you can load the comments that go with nodes. Each result would look like, Node - Comment, e.g.:
Can I have cheesburgers - First!
Can I have cheesburgers - No, I was first!!!111oneone
Can I have cheesburgers - LAME.
and so on. With some styling, you can then get it to show comments and nodes in separate rows.
However, this is ugly and hackish. My advise: write a simple module that either exposes a block, or a menu+page, and do two simple (and light) queries on the database: SELECT nid, title, ... FROM {nodes} LIMIT 10 and SELECT nid, name AS title, ... FROM {comments} LIMIT 10 then mix these two up. Or, with some (more complex) SQL magic, you could even join the two tables and create fancy results that e.g. order by created date of either nodes or comments.
With Drupal 7 you can add a relationship Last comment and then add that field to the view.
One idea I've seen is to use Views Custom Field to "attach" a wholly separate view with PHP code. See comment #4 for the code (in a request for this feature in Views. for a code example).

Views 1: Filter by custom table/field (or using Argument Hand. Code)

I have a page which should list nodes. The views is called from a locality page (a taxonomy term page). What I need is almost the same as using the Taxonomy: tid in arguments and passing the tid.
I can't use the term_node table, as (for other reasons) we have a custom table term_node_hierarchy (with nid and tid only). The table term_node_hierarchy is like term_node but also saves the tid of the parents (from an "external" code)
I've been looking for options but still no joy.
Currently I'm building an array of the nid's that should be displayed on the current page, and passing them like print views_build_view('embed', $view, $matching_nids); but the Argument Node: ID states This argument is a single Node ID. As said, only the first node is displayed when printing the views. It would be great if it could filter on more than one nid.
I'm open to any kind of suggestions on how to do this.
Thanks
You could create your own module for this. You could populate the $page_content variable with the results of your own custom query where you allow the user to sort against multiple nids. You could do this a number of different ways. You could display a list of the existing nids with corresponding checkboxes, so that, when the user clicks submit, all the nids that match the selected checkboxes get used in the query. Then you just display the result of that query. That's the easiest way I can think of to offer that degree of flexibility.

Resources