It's impossible to add additional arguments to a calendar view before the default year-month-day: I'm trying to build a view for urls like node/$arg/calendar/YYYY/MM/DD, where ther first argument is a nodereference field. The calendar doesn't replace $arg with the correct nid in the url it generates

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drupalcat-1’s picture

Title: Additional arguments handling » Visibility of the ALT in the view year
Component: Code » User interface
Category: bug » feature
Egon Bianchet’s picture

Title: Visibility of the ALT in the view year » Additional arguments handling
Component: User interface » Code
Category: feature » bug

drupalcat, please submit a new task instead of changing this one, thanks :-)

Egon Bianchet’s picture

I mean submit a new issue

patchak’s picture

Hi,

I have the same problem as the original poster of this issue. I'm trying to build a calendar views based on nodes that are posted by groups. So my though was to create a calendar for each group, but with a single view and arguments of course...

So my url is : node/$arg/calendar and the argument is og NID.

It works fine if you actually link to it for example as it will catch the argument, but then if you try to change from a year view to a month view, the argument is not passed, so it comes to page not found.

Also, I managed to pass the argument to a block, so on the page group it will display a calendar with only those group events, but then again, when you click on it, the argument is not passed to the URL so it's again page not found.

It would really be great if this could work as for me it would mean that I can build an advanced project manager (with separated groups) each with their own calendar. (and not all on the same calendar, as the client does not want everyone, to see every task and event.

Is this possible?

Thanks

patchak’s picture

Additional info: I run the 4.7 version btw

Lowell’s picture

Title: Additional arguments handling » I believe I have a similar question

Just looking for the right place to ask:-)

I am using the calendar with an exposed filter. When the exposed filter is used it appends the url (its a clean url) with a ?filter0=## (## varies with the filtered choice)

Then if we click on anything on the calendar, the filtered choice drops off and we are viewing the default filter again. This happens when we change from month to week to day, etc, etc.

If I need to I will alter the module myself but I need one or two things first.

1. is the ?filter0=## supposed to show up this way or is it just my installation?
2. how can I reference this variable in the code so I can append it to all of the calendar links in the code

If I do this, would this be a contribution, a patch?
It will be nice if the selected filter remains until it is changed intentionally, but again if it is only my installation, please let me know.

RayZ’s picture

Title: I believe I have a similar question » Additional arguments handling

Changing title back.

Egon Bianchet’s picture

Status: Active » Needs work
FileSize
0 bytes

Ok, I got it mostly working, by making our own calendar_get_url function, copied from views_get_url ... the week view is still buggy and there's some extra slashes in urls sometimes ...

Egon Bianchet’s picture

FileSize
6.45 KB

some code would be nice ;-)

KarenS’s picture

Status: Needs work » Fixed

A modification of has been committed, along with a fix to retain the filters and sorts from the url. Thanks!

Egon Bianchet’s picture

Status: Fixed » Active

There's still an issue with the week view, it always shows the "Week of January 1 1970"

KarenS’s picture

Status: Active » Fixed

That's a different issue. There are several issues already out there about problems with the week view and I'm pretty sure this is already mentioned.

Anonymous’s picture

Status: Fixed » Closed (fixed)
Egon Bianchet’s picture

Status: Closed (fixed) » Active

This is happening again since the 5.x-1.4 release

cdoyle’s picture

I'm also seeing this in calendar 5.x-1.4. Here's some code I used that I think fixes the problem as I understand it.

I inserted this at line 1344 in calendar.module to replace the array_push line. It's designed to check for one or more '$arg' strings and replace that with the current argument before trying to push the arg onto the end of the array (that turns into the path).

      $pos = strpos($parts[0], '$arg');
      if ($pos !== FALSE) {
        $parts[0] = substr_replace($parts[0], $arg, $pos, 4);
      } else {
        array_push($parts, $arg);
      }
jason.fisher’s picture

Status: Active » Needs work
FileSize
1.91 KB

This patch does two things with the goal of making node/$arg/calendar work properly for OG/organic groups.

1. It applies Egon's replacement calendar_get_url, this allows me to place the calendar in a tab on node/$arg/calendar and allows the calendar module to successfully link back to other tabs in the same space. Without this code, other tab links with $arg break and actually have "node/$arg/stuff" in the URL instead of "node//stuff"

function calendar_get_url($view, $args) {
  $url = $view->url;

  if (!empty($url)) {
    $where = 1;
    foreach ($args as $arg) {
      // This odd construct prevents us from strposing once there is no
      // longer an $arg to replace.
      if ($where && $where = strpos($url, '$arg')) {
        $url = substr_replace($url, $arg, $where, 4);
      }
    }
  }

  return $url;
}

2. After applying the above code, going to "node/$arg/calendar" would result in a blank display, but "node/$arg/calendar/2007" and "node/$arg/calendar/2007/10" would work fine. I narrowed it down to this line, on line 1230 in calendar.module (calendar_views_query_alter):

if (empty($view->args)) {

This line worked fine when the only args the view was expecting were related to the calendar. Now that some views will always have one arg (or not), this condition doesn't always work.

The replacement code I've used here is:

    $calendar_args = 0;    
    foreach ($view->argument as $delta => $argument) {
      if (in_array($argument['type'], array('calendar_year', 'calendar_month', 'calendar_day', 'calendar_week', 'calendar_ical')) && $view->args[$delta]) {
        $calendar_args++;
      }
    }

    if (empty($view->args) || !$calendar_args) {

I'd prefer to use a recursive array search function to clean the code up, but this seems to work. Instead of relying only on $view->args being empty, we count how many args we care about that have value.

This patch is against the latest -dev as of today.

KarenS’s picture

Status: Needs work » Closed (duplicate)

This methods used in this issue won't work any more since I have made a lot of changes to the module in the last couple days. I am in the process of trying to get a non-calendar argument working if it is used in front of the calendar arguments. It is mostly working with the latest commits, but there are still a couple bugs I'm tracking down.

Once you can put a non-calendar argument as the first argument in the view, you'll be able to use the OG argument there to filter a calendar down to a specific group.

There were several related issues opened on this subject. I'm going to mark this one a duplicate and use http://drupal.org/node/136968 as the official issue on this subject going forward, partly because this issue has been polluted with several other things (like the question about using an OG filter in the view, which is a completely different issue).