How to get the view of the current page in drupal.
I have a filter, whenever the user enters the search item, the view is changed.
$view = views_get_current_view();
does not work.
This worked for me :
$view = views_get_page_view();
Depending on the situation, the data should be in
$page_data = page_manager_get_current_page();
when called from MYTHEME_preprocess_page().
You may need to print_r the data, but I think the view name will be set as $page_data['handler']->subtask. I have used this in themes before, but depending on how your site is put together, this may not always work.
Related
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.
I followed the collective.examples.userdata directive to add fields to member and I works very fine.
The new infos are well stored and visible in the ##personal-information but now I'd like to go to the next step and show the new fields in the author.cpt page to make the new fields visible for every members(in a site directory for instance). I think I need to customize the membershiptool.getUserInfo() function but I just don't now how to proceed. Anyone knows how could I do to show this new fields in the author.cpt ?
Thanks
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...
I want to disable a cck field inside a specific form in Drupal 6.
I´ve created a new module full of alterations, using hook_form_alter.
The form id is articulo_node_form. The field in question is text, I´ve checked and it can be disabeled.
I´ve tried this:
function modding_form_articulo_node_form_alter(&$form, &$form_state, $form_id) {
$form['field_articulo_tipo']['#disabled'] = 1;
}
The field doesn´t disable at all, instead, it dissappears.
Anyway that happens when I try to create a new articulo node or when I try to edit that node. I want to target only node edits, I mean, the same form, but when it´s being edited.
What´s wrong with that code?
THANKS FOR YOUR HELP!!
Rosamunda
I can't think of a reason why the code you've got wouldn't work but you can use code like this to 'force' the attribute to be displayed:
$form['field_articulo_tipo']['#attributes']['disabled'] = 'disabled';
Inserted new menu item in hook_menu. But the menu item is not reflected. So in module i added the statement as
function {module_name}_menu_alter(&$items) {
$items['archives/faculty_article'] = array(
'access callback'=>'archives_list_faculty_article',
'access arguments'=>array(1),
);
$items['archives/faculty_article']['access callback'] = 'user_access';
}
Problem raised
1. Not able to access admin panel
2. user warning: Table 'nodewords_custom' doesn't exist query: SELECT * FROM nodewords_custom ORDER BY weight ASC
How can I correct the problem.
Have you flushed your menu cache after creating your new menu entry in the hook_menu()? It's mandatory if you want your new menu entry to be evaluated.
About your code snippet in the hook_menu_alter(), you are not altering properly the menu item, either your rewrite the full attributes of the item (title, page callback, access callback etc) either you just override one attribute (such as what you did for the access callback).
If you want to override two attributes you have to do something like that:
$items['archives/faculty_article']['access callback'] = 'user_access';
$items['archives/faculty_article']['access arguments'] = array('view');
After implementing the hook_menu_alter() you also have to flush your caches.
That's for problem 1. For problem 2, it means that you didn't install nodewords correctly, try to disabling it, uninstalling it and then re-enabling it to try to fix the issue. It should recreate the table for you.