Drupal views, get node id from url - drupal

I want to make a view, that can show a single blog post. This is to be used in a panel.
Is it possible to create a view, that show a node getting the node id from the url?
I have tried creating a view with :
CONTEXTUAL FILTERS -> nodeid -> WHEN THE FILTER VALUE IS NOT AVAILABLE
->Provide default value -> Content ID From URL
This does not seem to work though, maybe the URL to the panel holding the view is constructed wrong?

1) If the panel page is a node template override it will have no problems and it will work without extra settings (you will see that also when you set the panel pane, there are not extra settings).
2) If not (eg if it is a frontpage panel page) you have to pass the argument from panel to views. The path for that page should have a nid argument or a panel pane may have this. Eg your path may be "home/%node". And you have to add a context to your panel that is of type node. Then Assign the Node: id to this argument.
See a similar discussion at https://drupal.stackexchange.com/questions/63538/how-to-pass-a-nid-to-panel-and-load-a-node-with-the-given-nid-as-context

Related

Drupal joining multiple views in master view

I have multiple views I want to join into the one master view.
View A: List of pages of content type A
View B: List of pages of content type B
I need to join Views A and B into Vew C, which will be the master view accessible via menu.
So far, I have found a module called "Views Field View", which works, but for me only for 50%.
For demonstration, I will add an image, which I will refer to:
The problem is, I cannot call the views A and B into main content - into FIELDS (Red on image).
For some reason, Anything with GLOBAL category will not get displayed.
Sadly, even "Custom text" and "Show" or "Views_field_view" are part of the GLOBAL category.
The only way how it is working now, is adding it as a HEADER (Blue on first image - HLAVIÄŒKA).
So far so good.
But I need also add headers.
Bad thing is, that the inner views are shown without their headers. But in HEADER category on configuration of the view, there is no possibility of adding Global:Custom text, so I cannot add the headers manualy in master view C too...
So, any ideas, how to have
View C{
Header A
View A
Header B
View B
}
Or
View C{
View A{header, content}
View B{header, content}
}
?
Thanks in advance.

adding new menu in Select (All,Inverted Selection) in Alfresco Share

I am newbie to the Alfresco.Now my requirement is how to add new menu[All(All pages)] in Select. wherever user perform search function lets say 250 results have found & user selects All in page 1 & its selecting only current page results and not selecting entire 250 records & then user goes page by page can edit the properties for the entire 250 records.in the new functionality if user selects [All(All pages)] then all records should be selected & edit the properties for 250 records at one go.So I want to add new menu with All(All pages) & change the existing menu current labels as All(Current Page).How to achieve this functionality and what files need to changed.How should i know that which files are currently used?Is there any debugger can be used to know the files?
Alfresco Version
4.2.e
My guess, is that if you go through this previous version of Jeff Potts' Tutorial you will be able to figure this out by yourself.
Simplest option is to edit label of that particular action in out of box property file.
You can find it under
<ALF_HOME>\tomcat\webapps\share\WEB-INF\classes\alfresco\messages\slingshot.properties
This entry
menu.select.all=All
Change label here and it will be reflected.
NOTE: It is not best way to implement this. Ideally you need to override property file and change label
The issue here is that only the items shown on the page have been loaded. This means that the metadata for the items not shown on the page won't be available. The metadata of each node is used to evaluate it's applicability to any action. If the node is locked or has had its permissions changed then it won't be possible to edit it. This is why "all" only means all items on the current page of data.

Drupal 7: how to filter view content (with entity reference field) based on current page content

in my drupal 7 I have 2 content-types like these:
ContentA
ContentB (with a field Entity Reference to ContentA)
In the front-end detail page of ContentA, I would love to show a block/view with a list of ContentB whose Entity Reference field is set to the current ContentA.
I made a view of type Block and added it correctly to the page, but I cannot filter ContentB based on the current ContentA.
Could you help me?
Thanks
You should add a contextual filter for the value you will use for filtering to the block View of ContentB.
Then in your contextual filter in the "When the filter value is NOT in the URL" area select "Provide default value" and Type "PHP code" (You should have enable php filter for this). In your php code area you should have the following code
$node=menu_get_object();
return $node->field_your_machine_field_name['und'][0]['target_id']; // this is the field you will use for fitlering
Hope it helps
UPDATE
The above code will work if you need to show in your block similar results with the same selection (for example similar results of ContentB with the same selection in the referencing field of ContentA ).I will not delete because you might need it also in your project.I misunderstood. Actually the solution is simpler. You should add the contextual filter to the field and in "When the filter value is NOT in the URL" area select "Provide default value" and "Provide id from url"

Dynamically changing a portion of a Drupal page based on clicking links from a view

Introduction
I'm a bit new to Drupal, so I'm still trying to wrap my head around how all the different ways of implementing dynamic content work. Let me explain my desired end state and explain some methods I have tried. Also, I'm using Drupal 7.
Desired end state
I want a page that pulls a context argument from the URL to display content (level 1) based on the Taxonomy Term ID in the URL. On this page, fields from the selected content node are displayed and a view displays associated sub-content (level 2) in a grid of icons. When one of the sub-content (level 2) icons are clicked, another region of the page updates with fields from the sub-content (level 2) node that match the icon selected. This pane should update with AJAX to prevent page reloads.
Current design
What I have so far is a PAGE that uses contextual filters to pass the Taxonomy Term ID as an argument in the URL to display the correct page content. This works.
To this page, I have added a panel for the content (level 1) I want to display. Additionally, I added a VIEW panel that displays only the sub-content (level 2) icons associated with the content (level 1). This works.
Attempted solutions
I am at a loss for how to display the NODE content for the selected sub-content (level 2) icon. I made a PAGE with the appropriate arguments to display exactly what I want. The intention being that I would add the PAGE as a panel to the existing PAGE and pass the arguments to this PAGE by rewriting the icon linking and setting the target parameter. I have not found a way to embed a page within a page.
My next thought was to create a VIEW that used contextual filters to display only the NODE content for the selected sub-content, but I haven't found a way to pass the contextual filters from a click of the icon to the VIEW.
Conclusion
I'm sure there are many ways to do this, but I am looking for the least invasive way. What I mean by that, is that I'm looking for a method using existing techniques within panels, panelizer, views, etc. if it exists. As a last resort, any custom code modifications would have to be contained within a module for ease of maintenance. I'm not exactly sure what I'm looking for because the terminology for everything in Drupal is still confusing to me, but some pointers in the right direction would be great.
Here's a mockup of what I'm describing:
I found a method of doing this that is working like a charm.
What I did:
I used Panelizer to modify the appearance of a node of content type 1, and added the fields I wanted displayed.
Next, I created a View for the sub-content icons. One of the fields for the sub-content is an Entity Reference to specific nodes of content type 1. I exploited this reference with a Views Relationship and a Views Contextual Filter to limit the output of my view to sub-content related to the specified node ID. I defined this node ID in the panel settings for the view in Panelizer Content by selecting "Content ID" as the context.
I added the "Nid" (Node ID) field to the view, but excluded the output. Next, I applied a rewrite rule to the Icon field and changed the link path to an absolute path of "ajax-viewer/nojs/[nid]".
Next, I created another view for the full display of the sub-content. I applied the same Views Relationship and Views Contextual Filter as the other view, however I didn't specify the context in the Panelizer Content settings, but I did add a CSS ID. I added a Content Pane to the view and set the name of the pane. Also I turned "Use AJAX" to "On".
I created one more view for the icons of sub-sub-content, but used the entity reference to sub-content instead of content. I also didn't define the context in Panelizer Content, but did define a CSS ID. I made the view a Content Pane and defined the name of the pane.
This set up all of the structure to the page, but I still had to make a module to power the AJAX call. I referenced this page for the idea. However, I made a second helper function for my second view. In Sean's example, the views call (which I used) has to be changed to match the view.
return views_embed_view ('machine-name-of-view','name-of-content-pane-in-view', $nid);
Since one function can only return one value, I modified the ajax_link_response() function a bit...
function ajax_link_response($type = 'ajax', $nid = 0) {
/* These next two lines are different */
$sub-content-output = _ajax_reader_load_noder_sub_content($nid);
$sub-sub-content-output = _ajax_reader_load_noder_sub_sub_content($nid);
if ($type == 'ajax') {
$commands = array();
/* These next two lines are different. The # and id= must match the CSS IDs set in Panelizer Content. */
$commands[] = ajax_command_replace('#sub-content', '<div id="sub-content">' . $sub-content-output . '</div>');
$commands[] = ajax_command_replace('#sub-sub-content', '<div id="sub-sub-content">' . $sub-sub-content-output . '</div>');
$page = array(
'#type' => 'ajax',
'#commands' => $commands
);
ajax_deliver($page);
}
else {
/* These next three lines are different. Same as above with the CSS IDs. */
$sub-content-output = '<div id="sub-content">' . $sub-content-output . '</div>';
$sub-sub-content-output = '<div id="sub-sub-content">' . $sub-sub-content-output . '</div>';
$output = $sub-content-output + $sub-sub-content-output;
return $output;
}
}
One last thing I did was to not include the _init() function in Sean's example as the view was activating AJAX already since I set it on. Including the _init() function caused AJAX on my forms to break.
This set-up works like a charm. One last thing I did was to specify a default Node ID in the Views Contextual Filter for the sub-content and sub-sub-content so that initial content is displayed.

How do you access the title (Node module element) field in Drupal 7?

I have a computed field in a Drupal 7 content type that is populated by my description (text) field:
$entity_field[0]['value'] = $entity->field_desciption['und'][0]['value'];
It works fine. I want to create another computed field that is populated by the title (Node module element) field.
I tried with the following lines, but they don't work.
$entity_field[0]['value'] = $entity->title['und'][0]['value'];
$entity_field[0]['value'] = $node->title;
How can I achieve this?
The node title is not a field; therefore, using $entity->title['und'][0]['value'] will not work. What you should use is $entity->title.
As side note, to get the value of a field, you should use field_get_items(), which takes care of the language set for the field, which isn't necessarily LANGUAGE_NONE.
If it's a node module element, it should be accessible via $entity->title directly.
Try a print_r($entity); die; to get all elements of the entity. Hope this help you.
You should look at printing the array/object to the page to see what you are working with exactly.
Try adding print_r($entity); or print_r($node); to the page where the entity or node is displayed followed by exit;
You can then right click the page and click 'View page source' to display the output in a structured format. Use this to see the variable names, object/array types and hierachy to then write your full variable code correctly.
print_r($node);
exit;
I would imagine it should have been $node->title though...

Resources