I need to feature April in the mini calendar. If I tack "?mini=calendar2/2009-04" onto the end of the URL of any page with the calendar, I get what I'm looking for. But how do I pass this info to the mini calendar behind the scenes?

Thanks,
Mickey

Comments

micnap’s picture

Title: pass argument to mini calendar » bump

Just a hint? Please?

KarenS’s picture

Title: bump » Custom default value for the mini calendar block
Status: Active » Fixed

You would have to configure the default value of the argument of the mini calendar. Select the 'Calendar block' of the calendar. Click on the date argument. Check the box to 'override' the argument so that the block will behave differently than the rest of the calendar. There is an option to set the default argument to the current date. Change it to set it to a fixed value for the argument instead and type in the value you want it to have. Do the same thing with the 'block view' (the mini calendar block is made up of two displays, the 'Calendar block' for the navigation and the 'block view' for the calendar itself).

Then don't forget to change it back when you do *not* want to feature April any more.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

chaps2’s picture

Version: 6.x-2.0-rc6 » 6.x-2.0
Status: Closed (fixed) » Active

Hi, I've reopened this as I was trying to do the same thing but without success. The validation in the calendar argument handlers requires that the default argument is Current date as in this code here:

    elseif ($arguments['date_argument']['default_action'] != 'default' || $arguments['date_argument']['default_argument_type'] != 'date') {
      if (empty($this->view->date_info->arg_missing_default)) {
        $errors[] = calendar_errors('missing_argument_default');
      }
      $this->view->date_info->arg_missing_default = TRUE;
    }

I had to comment this out in order to use the fixed entry and php code as the default argument.

However there's another problem with the views date argument handler which I commented on here http://drupal.org/node/333463#comment-1328040. Possible workaround would be to override get_default_argument in the calendar handlers and call the parent method with $raw = TRUE. But I'm not sure what other effects that may have.

Thanks,
Andy

sagannotcarl’s picture

Version: 6.x-2.0 » 6.x-2.x-dev
Component: Miscellaneous » Code
Category: support » bug

I am having the same problem with the dev version (from March 21). When I try to follow the instructions from #2 and set the default argument from Current Date to Fixed argument, I get the error:

The Date argument in this view must be set up to provide a default value set to the current date. Edit the argument, find 'Action to take if argument is not present.', choose 'Provide default argument', then select 'Current date'.

The view will also not accept the other date options for default argument such as Current node's creation time or Current node's update time.

Because the instructions in comment #2 said something about two displays making up the calendar block I set the default display to use fixed argument, as well as just changing the two displays used. Every time I got the same error.

sagannotcarl’s picture

chaps2,
In which file did you comment out that section? When I commented it out of a couple include files my block disappeared. Did you get this working or did that other views issue prevent it?

chaps2’s picture

For the fix in #4 to work you need to uncomment those lines in the calendar plugins that your views use. Typically for blocks these will be includes/calendar_plugin_style.inc and includes/calendar_plugin_display_block.inc.

I would provide a patch for this but I think it needs comment from one of the maintainers as the code that I have commented out looks like it was put there for a reason.

It did work for me but you do need to apply fix to the views handler as mentioned in http://drupal.org/node/333463#comment-1328040.

Latest: the views bug is fixed in the latest release of views-6.x-2.x-dev dated 25 March 2009.

osopolar’s picture

I changed the validate function in includes/calendar_plugin_display_block.inc and includes/calendar_plugin_style.inc to:

  /**
   * Display validation.
   */
  function validate() {
    $errors = parent::validate();
    
    $arguments = $this->display->handler->get_option('arguments');
    if (!in_array('date_argument', array_keys($arguments))) {
      if (empty($this->view->date_info->arg_missing)) {
        $errors[] = t("The Calendar period display '@display_title' will not work without a Date argument.", array('@display_title' => $this->definition['title']));      
      }
      $this->view->date_info->arg_missing = TRUE;
    }
    elseif ($arguments['date_argument']['default_action'] != 'default' || ($arguments['date_argument']['default_argument_type'] != 'date' && $arguments['date_argument']['default_argument_type'] != 'php')) {
      if (empty($this->view->date_info->arg_missing_default)) {
        $errors[] = calendar_errors('missing_argument_default');      
      }
      $this->view->date_info->arg_missing_default = TRUE;
    }
    return $errors;
  }

Now I'm able to use the following php code to provide a default value:

if ('' == arg(1) || 'heute' == arg(1) || !date_is_valid(arg(1), DATE_DATETIME, array('year', 'month'))) { 
  return date_format(date_now(), 'Y-m');
}
return substr(arg(1), 0, 7);

The date argument is the first one (after the view name).
Example: when I' viewing the web page http://cyber4kids.de/kalender or http://cyber4kids.de/kalender/heute (heute = today) I get the mini calendar for the current month when I'm viewing http://cyber4kids.de/kalender/2009-03-29 I get the calendar for 2009-03.

agentrickard’s picture

rismondo’s picture

I would also like to have the ability to specify a default (either by using PHP or a fixed string) for the calendar.

If I change the code in the manner described in this ticket (or the one linked above), I find that the default works, but then the mini calendar block disappears from all full node pages (the ones with an address like "/node/nnn"), even though it shows normally on the administration pages or the front page.

So this change may be insufficient.

osopolar’s picture

Issue summary: View changes

Recently I had similar problem on a different D6 site (not sure how much has changed for D7, but it might be useful): Instead of using php in views as in #8 its better to use hook_views_pre_view() to provide the argument for the mini calendar.

/**
 * Implementation of hook_views_pre_view().
 */
function MYMODULE_views_pre_view(&$view, &$display_id, &$args) {
  if ('events' == $view->name &&  'calendar_block_1' == $view->current_display) {
    $arg = arg(1);
    $arg_parts = array();

    module_load_include('inc', 'date_api', 'date_api_sql');

    // Get date argument from URL and convert it to YYYY-mm
    // see also Views-Date-Argument-Handler date_api_argument_handler.inc.
    $handler = new date_sql_handler();
    $handler->construct();
    $arg_parts = $handler->arg_parts($arg);

    if (isset($arg_parts[0]['date'])) {
      $arg_parts = $arg_parts[0]['date'];
      $value = $handler->complete_date($arg_parts, 'min');
      $date = date_make_date($value, date_default_timezone_name(), DATE_ISO);
      $arg = date_format($date, 'Y-m');
    }
    else {
      $arg = date('Y-m');
    }

    $view->set_arguments(array($arg));
  }
}
Neslee Canil Pinto’s picture

Status: Active » Closed (outdated)

The D6 branch is no longer supported so we're closing this issue. If you think this issue still exists in D7 you can open a new one.