By Imaaxa-Cory on
I have a page that is created by views using contextual filters to filter down the page results.
The contextual filter is the nid of a content type.
I created a view to create a menu on the page that just links back to the page with the context argument added to the end. Example: resource/44
Client added the requirement later for drop-down menus. So I am using Nice Menus for this.
To try to make it easy for the client to update the drop-down menu, the menu cache will be flushed upon the creation of the content type mentioned above.
Here is the code I am using:
/**
* Implementation of hook_menu()
*/
function mymodule_menu(){
// get the content type data from the DB
$result = cm_get_category_nodes();
// loop through the $result
// and create a menu item with the data
foreach ($result as $key => $value) {
$items['resource/' . $key] = array(
'title' => $value,
'description' => 'Resources',
'page callback' => 'views_page',
'page arguments' => array('resources', 'page_1',),
'access_callback' => 'views_access',
'access arguments' => array('administer filters'),
'weight' => 0,
'menu_name' => 'main-menu',
'tab_root' => 'resource',
);
}
return $items;
}
The problem is now the views page is not filtering with the nid from the end of the url. Can anyone see what I am missing?
Comments
Why is Views not filtering Update
I just noticed that if I add the content type id again as another argument, the view filters on the argument.
Example: resource/44 <-does not work. resource/44/44 <-does work.
Is there something I am not adding to the menu $items array causing views to not filter on the first argument instance?
New discovery
During testing, I disabled the module, flushed the caches. The links that the module created remained in the database, and views is now filtering the contextual argument properly.
I made a copy of the menu-cache with it working correctly. Enabled the module again, flushed the caches, tested that views once again is not filtering the contextual arguments. Made a copy of the menu-cache again.
I compared the two cache entries and only found some extra closing curly brackets }.
Does anyone know if there is a way to add the menu links to the menu_links table without using hook_menu()?
I am also open to other ideas.
Solution found
Made change to above function:
Changed the 'page callback' => 'views_page'; to 'page callback' => 'mymodule_page',
Then copied the views_page function from views.module, renamed it with mymodule name and added some php: