Drupal file attachments -> How to view parent node in search results - file

I'm using an content node type (let's say "A") with file attachments.
For search functionality the attachments are being indexed by "Search API" and "Search API Attachments".
At the search result view I want to view fields of the parent of a found file. How to achieve this?
For example:
If a search results in a file, the result page should view fields from the containing parent node (type "A"), for instance the title of the parent node.

You can add relationships down in your index, but not up, so you
probably want to index the parent content, and then add fields to your index which have a relationship to the file > filename. That way the filename is indexed (other other file entity fields), but the result you're return is the parent node.
You could then use a search result view mode to select which parent node fields you want to feature in the result.
Docs - https://www.drupal.org/docs/8/modules/search-api/getting-started/adding-an-index

Related

Retrieving items from AppleScript record

I have an AppleScript record, myJSON, which I've created from a JSON entry using JSON Helper:
{"height":200.0,"width":300.0,"productoption":["fabric","rectangle","roll"],"id":33,"product":["backdrop"]}
I can easily access all the keys with a single entry by using, for example,
product of myJSON
I can't figure out how to access the productoption key which has a multiple entries.
Actually it's exactly the same way, the value for key productoption is an array (list in AppleScript terms)
set options to productoption of myJSON
repeat with anOption in options
display dialog anOption
end repeat

Drupal 7: How do I use views to display information from the current node?

I have a Drupal 7 question. I would like to display certain pieces of information from my current node using a view.
I can use views to display information from other nodes easily by setting filters and other sorting features. That's no problem. However, I want to display information from the node which is currently opened. So, for example, if I'm on a page (node: 117, title: news), I can display all the images from that page, plus captions, by creating a view.
The logic, I suppose, would be to create a view with a filter (or contextual filter) stating that the node has to equal the current node, but I don't know how to do that.
Does anyone have any advice? How do I instruct a view to display information from the node which is currently open?
Thanks!
Edit the view
Add Content: Nid in contextual filter
In contextual filter options
WHEN THE FILTER VALUE IS NOT AVAILABLE
Select "Provide default value"
Type: Content ID from URL
Now the default argument will be the nid of the current node.

Dispaly nodes related to the newest taxonomy term

There are nodes of "product" content type which contains reference field to the "version" taxonomy terms.
User can add new term when he is creating a new node (by auto complete widget) and I need to display nodes related to the newest or "higher" term.
Is this possible without creating custom filter grammatically ?
It is just 2 lines of code , you can place it anywhere in your page.tpl.php or
page--front.tpl.php .
$term = max(taxonomy_get_tree(taxonomy_vocabulary_machine_name_load('version')->vid));
if ($term)
echo l("Latest Version Products", 'taxonomy/term/'.$term->tid);
By placing the above code in your template tpl file , you can find
"Lastest Version Product" link. and selecting that link will take user to the latest term page.

How can i create a DRUPAL view mixed with nodes and files?

as the title says I'm trying to create a view that displays rendered files and nodes together. Normally when you create a view you have to select what type of content (nodes, taxonomy, files ...) you want do display.
What i want to achieve is a view that displays all nodes and files. The files are NOT mandatory associated with a node. But they are also tagged with terms.
Any idea how to solve that?
Thanks in advance,
Fab
Why don't you create 2 block views and then display it in a page?
For example:
Create a view block that displays the files --> "display_files-block"
Create a view block that displays the nodes--> "display_nodes-block"
and then print them in a static page u create,
For example: "Display files and nodes", with id 1.
inside page--node--1.tpl.php write:
$block = module_invoke('views', 'block_view', 'display_files-block');
print render($block['content']);
$block = module_invoke('views', 'block_view', 'display_nodes-block');
print render($block['content']);
This doesn't answer the question correctly but can be used as a work around for getting data from two entities to appear in one view.
Through the UI, you could create a view called FilesAndNodes, and only add Global:Custom Text Area under the fields section.
Then create another view called Files, and add this view under the Header section of FilesAndNodes view.
And then do the same for nodes.
The Block created by the FilesAndNodes view can then be added to the page, and the content appears as one view.

Is there a content type "root" default template in Drupal?

I've created a new content type, say "Products". Is there some kind of default routing and templating based on the content type ?
For example, can I access my "root" content type by going to www.example.com/products/ ?
And would I also simply need to edit a certain tpl for that content type "root" page (for example the /products/ page that lists all products ?
For now, the solution I've got is to create a node of type "Page" called "Products", create a view and assign this view to the Products page. Then, create a TPL for this node (wich would list the products).
I find this solution a bit long .. is there another way ?
Thanks!
I've created a new content type, say "Products". Is there some kind of
default routing and templating based on the content type ?
No, you can only edit (by core) the content type fields etc through the admin inderface.
For now, the solution I've got is to create a node of type "Page"
called "Products", create a view and assign this view to the Products
page. Then, create a TPL for this node (wich would list the products).
You can use Views module to create lists of data. Use tpl.php files (see the template suggestions) for the display of each page, node, block etc. I would suggest to not add a views inside a node tpl through code but as a block.
Did I understand well?

Resources