NOTE: this is a split post from http://drupal.org/node/55448

I will post the issue in detail in a second post below.

Comments

asparagus’s picture

It seems that a combination of url_aliases and multiple filters on taxonomies provides for some very unexpected results. As i'm a little stumped about the cause, i'll simply describe the situation in detail.

I have a site with four views. Of these four views, 2 are page views. These page views are accessed using 'url aliases' provided by the 'path' module. I'm using aliases to access these page views as i have navigation that is created and will not render the menu if the node aliased to this page is not published. If i do not use 'url aliases' and use the url field in the view, things work fine but i have no way to determine if the page is a view as i cannot obtain a views/vid type url from drupal_get_normal_path function. It would seem that setting up a url_alias should be no problem. It causes some very odd issues though. What seems to happen is that both of the url's provide only the last view created.

I've encluded a section of the menu code as well as the export of the two views.

Please let me know if further detail is required.

Thank you in advance.

here is a excerpt from the menu code for reference
// function start not shown
foreach ($menu['visible'][$pid]['children'] as $mid) { 
	$isActive = 0;
	$path = explode("/", drupal_get_normal_path($menu['visible'][$mid]['path']));
	$type = $path[0];
	switch($type)
	{
		case "node":
			$node_id = intval($path[1]);
			$node = node_load($node_id);
			$isActive = $node->status;
			break;
		case "view":
			$isActive = 1;
			break;
	}
	if ($isActive)
	{
	// write html for menu
	}
}
// function end not showm
view one - works if view two doesn't exist
  $view = new stdClass();
  $view->name = 'newsIndex_commercial';
  $view->description = 'News Index Page for Commercial';
  $view->access = array (
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = '';
  $view->page_header = '';
  $view->page_header_format = '4';
  $view->page_footer = '';
  $view->page_footer_format = '4';
  $view->page_empty = '';
  $view->page_empty_format = '4';
  $view->page_type = 'node';
  $view->url = '';
  $view->use_pager = FALSE;
  $view->nodes_per_page = '10';
  $view->sort = array (
    array (
      'tablename' => 'node',
      'field' => 'created',
      'sortorder' => 'DESC',
      'options' => '',
    ),
  );
  $view->argument = array (
  );
  $view->field = array (
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => 'dynamic',
),
    ),
    array (
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
    array (
      'tablename' => 'term_node_2',
      'field' => 'tid',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => '6',
  1 => '7',
),
    ),
    array (
      'tablename' => 'term_node_1',
      'field' => 'tid',
      'operator' => 'AND',
      'options' => '',
      'value' => array (
  0 => '1',
),
    ),
  );
  $view->requires = array(node, term_node_2, term_node_1);
  $views[$view->name] = $view;
view two - takes everything over
  $view = new stdClass();
  $view->name = 'commInvestIndex_realty';
  $view->description = 'Realty Commercial Investments Index Page';
  $view->access = array (
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = '';
  $view->page_header = '';
  $view->page_header_format = '4';
  $view->page_footer = '';
  $view->page_footer_format = '4';
  $view->page_empty = '';
  $view->page_empty_format = '4';
  $view->page_type = 'node';
  $view->url = '';
  $view->use_pager = FALSE;
  $view->nodes_per_page = '99';
  $view->sort = array (
  );
  $view->argument = array (
  );
  $view->field = array (
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => 'dynamic',
),
    ),
    array (
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
    array (
      'tablename' => 'term_node_2',
      'field' => 'tid',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => '8',
),
    ),
    array (
      'tablename' => 'term_node_1',
      'field' => 'tid',
      'operator' => 'AND',
      'options' => '',
      'value' => array (
  0 => '2',
),
    ),
  );
  $view->requires = array(node, term_node_2, term_node_1);
  $views[$view->name] = $view;
merlinofchaos’s picture

Neither of the exported views have URLs at all. Please explain to me how you're accessing these views. I feel like there's something absolutely key that you're not explaining, and it's this something that's causing your basic problem.

At this point I'm feeling more and more like it's not actually a problem with Views, but that you're doing something you think should work and does not; but that's just a feeling based upon not having enough information about what you're actually doing.

merlinofchaos’s picture

Also, where is this menu code you're showing? You're using code that pulls from info deep in the menu system, but it's not clear to me where this code is actually located, or what it's actually attempting to do.

merlinofchaos’s picture

Ok, I think I've figured out that your menu code is probably in menu.inc and you've actually hacked your Drupal install a bit. [IMO not the right way to accomplish this but that's another issue entirely].

You've got url aliases, but the views you've exported don't have URLs. This is part that is the most confusing to me right now. (Note the $view->url = '' in both views).

From the look of the code, it appears that your URLs should be more along the lines of 'view/foo' or 'view/bar' where you're using the first part of the URL to identify it as a view; if that were the case, that would make a little more sense to me.

asparagus’s picture

hello.

let me try to answer your two questions.

url's

neither view provides a url, that is correct. however, path aliases have been created for both views using the core 'path' module. the two aliases are as follows "pathPart/pageName" is the alias and "views/vid" is the system path. i'm using these as i need to know whether the menu item being referenced is for a "view" or for a "node".

I am using these settings as otherwise if i specify a url in the view itself, the call to drupal_get_normal_path does not return the "views/vid" system structure.

menu function

the menu code has nothing to do with this problem and was shown only for reference. i know that this is the case as also using the standard pushbutton theme will produce the same results with "out of the box" menu code. however, the code lives in my theme's php_template file.

views seems to treat the core path alias module differently than any of the other sections. ie "node, user, image, taxonomy" and this seems to be an issue.

please let me know if you need any further information.

thank you.

asparagus’s picture

just got your post and perhaps i'm seeing the issue as well but let me verify something.

if i specify a url in the 'url' field for a view, how do i then access that view url?

is it?

A - www.mysite.com/views/view_url
or
B - www.mysite.com/view_url

i was using the view id to access the views, so did not think a url was required as it is an optional field.

concerning the menu, however, i am not hacking the core at all, as i quite agree that that is the wrong approach. i am however, customizing a theme to generate a theme specific menu functionality.

thx.

merlinofchaos’s picture

The views URL is specified exactly the same way that your path aliases are specified.

Views does not automatically provide a URL such as 'view/vid' in the same way that there is a node/nid or a taxonomy/tid, you are correct. This is because not all views are URL viewable, so a global 'view/vid' is not appropriate. Originally, views DID work somewhat like this, but the vast majority of the time, 'view/vid' is not an appropriate URL, and an alias is required. Aliases have certain weaknesses (as you can must know since your code is basically trying to account for those very weaknesses). If you want that a view/vid, you'll have to enter that as the URL.

Here is a question for you: If your code sees a menu item, and determines that it is not a node at all, shouldn't it just assume the menu item is ok and print it? You don't actually do anything with the information that it's a view except set $isActive, which I assume prints the menu item. Shouldn't you simply have:

// function start not shown
foreach ($menu['visible'][$pid]['children'] as $mid) {
    $isActive = 0;
    $path = explode("/", drupal_get_normal_path($menu['visible'][$mid]['path']));
    $type = $path[0];
    switch($type)
    {
        case "node":
            $node_id = intval($path[1]);
            $node = node_load($node_id);
            $isActive = $node->status;
            break;
        default:
            $isActive = 1;
            break;
    }
    if ($isActive)
    {
    // write html for menu
    }
}

Using that, you wouldn't need to alias the view at all, and the code needn't care that it's a view.

asparagus’s picture

again, thanks for the response.

indeed i could simply use default on the switch, but don't want things to show up for "user, admin, etc", so i thought specifically switching on "views" was the more efficient option.

there is also one last catch where this alias is also important, which is within the page.tpl.php file for the theme. the menu structure for the entire set is built out with aliases using a combination of manual 'views' aliases [ ie our issue ] and aliases generated with path_auto. when a page is called up, i check to see if there is a system entry for this alias and if not, i generate a custom 404 with an email link indicating the offending page call.

it was then my assumption that views lack of similarity with other similar drupal elements [ ie the "views/vid" issue ] was a bug.

perhaps a workaround would be to create a url for each view such as "views/my_view_url" and then create an alias from "pathPart/pageName" to "views/my_view_url". seems a bit much to get 'views' to function more closely to what seems to me to be standard practice with id's etc. however, i'm don't have a long history with drupal and i understand that sometimes legacy code/structure can play a large part in things.

your opinion would be much appreciated.

thank you.

merlinofchaos’s picture

This doesn't really have anything to do with legacy code; it really is that not every view has a URL (views that provide only blocks, or views that exist just for customization) at all, and it seemed more efficient and more user friendly to let the user select the URL. In the future, Drupal is likely to make it easier to make generalized URLs, rather than the system/ID format that we see a lot of, whose URLs are so very often overridden anyway.

That said, I think you can accomplish what you seek simply by entering view/name in the URL field of the view, and then setting your alias up to point to that view.

For those other items (User, admin, etc) can't you just disable them using the normal drupal menu system? It seems like your check for unpublished nodes should be more of a special case, rather than the norm.

asparagus’s picture

Status: Active » Closed (works as designed)

that solution seems to be the one i'll go with.

sorry that i thought it was a bug, but given the variations in working methods kind of threw me.

thanks for the responses.