I have a view which should show all news articles of a certain year. It should take arguments or default to the current year. (The exported view is attached to this issue.)
The view works perfect with arguments in the url, but the default argument doesn't work.

First, I tried both a fixed entry (2009) and php code (return date('Y');) for the default argument. The validator was set to Basic validation. In both cases, the result is the 'Action to take if argument does not validate' as chosen in the Validator options fieldset. The query info in the live preview says "No query was run".

Next, I switched to PHP code validation and entered return TRUE; as validation code. Again, I tried both a fixed entry and php code. I still got empty results, the difference being that a query was run this time:

SELECT node.nid AS nid,
node.title AS node_title,
node.created AS node_created
FROM drupal_node node
WHERE (node.status <> 0) AND (node.type in ('news')) AND (EXTRACT(YEAR FROM((FROM_UNIXTIME(node.created) + INTERVAL 3600 SECOND))) = '')
ORDER BY node_created DESC

Note that the argument value is empty in this query.

It looks like a bug to me, but maybe I'm just doing something wrong. Thanks for helping!

CommentFileSizeAuthor
view.txt5.22 KBmarcvangend

Comments

marcvangend’s picture

I got my view working by using a "Date: Date Node: Post date" argument and setting the granularity to year. My problem is solved, but I'm leaving this issue open because I still think it's a bug that the Node: Created year argument suggests that it accepts a default argument, which doesn't work.

deshilachado’s picture

If you are using date 6.x-2.0 then this might be a bug in the date module and not in views.
There seem to be some problems with default arguments.

deshilachado’s picture

No, sorry, the Node created date doesn't have anything to do with the date module.

Andrew Schulman’s picture

Title: Default argument for 'Node: Created year' does not work » Default argument for date fields does not work

I confirm this problem. I have a custom date field and want to filter my view on date >= now. I choose Operator: is greater than or equal to; Default value: now. But this always fails:

  • If the date selector type is "Select", then I can leave all of the Absolute value selectors at their default values ("-Year", "-Month", etc.), but when the query is run it comes back with
    DATE_FORMAT(ADDTIME(node_data_field_date.field_date_value, SEC_TO_TIME(-18000)), '%Y-%m-%d') >= '2009-01-01'
    

    so that it seems to be treating the unselected date fields as 2009-01-01. (I also don't know where the -18000 sec. comes from, but I guess that's a fudge factor and a different issue.)

  • If the date selector type is "Popup", then I can leave the date field box empty, but I get the same result as with "Select", i.e. date >= 2009-01-01.
  • If the date selector type is "Text", then I can leave the date field box empty, but when I click on Update, today's date is always inserted in place of the empty value. So now the query becomes
    DATE_FORMAT(ADDTIME(node_data_field_date.field_date_value, SEC_TO_TIME(-18000)), '%Y-%m-%d') >= '2009-03-05'
    

    which is right today, but won't be right tomorrow.

So no matter how I try to enter it, some value always overrides the default. I've tried disabling Javascript and it didn't help.

I want to show coming events, and Views seems to offer the right options to do that, but at the moment I'm completely out of ideas as to how to make it work.

Thanks,
Andrew.

marcvangend’s picture

Andrew, can you post some of your view code (export the view and look for the $handler->override_option('arguments' part), to make sure we're talking about the same thing here?

In my case, this argument does process a default value correctly ('date_argument' type):

$handler->override_option('arguments', array(
  'date_argument' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => 'Headlines van %1',
    'default_argument_type' => 'date',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'date_fields' => array(
      'node.created' => 'node.created',
    ),
    'year_range' => '2000:2050',
    'date_method' => 'OR',
    'granularity' => 'year',
    'id' => 'date_argument',
    'table' => 'node',
    'field' => 'date_argument',
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'poll' => 0,
      'story' => 0,
      'news' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '4' => 0,
      '1' => 0,
      '5' => 0,
    ),
    'validate_argument_type' => 'tid',
    'user_argument_type' => '',
    'restrict_user_roles' => 0,
    'user_roles' => array(),
    'validate_argument_php' => '',
    'override' => array(
      'button' => 'Override',
    ),
  ),
));

While this one does not (created_year type):

$handler->override_option('arguments', array(
  'created_year' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'id' => 'created_year',
    'table' => 'node',
    'field' => 'created_year',
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '2009',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'poll' => 0,
      'story' => 0,
      'news' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '4' => 0,
      '1' => 0,
      '5' => 0,
    ),
    'validate_argument_type' => 'tid',
    'user_argument_type' => '',
    'restrict_user_roles' => 0,
    'user_roles' => array(),
    'validate_argument_php' => '',
  ),
));
Andrew Schulman’s picture

Strangely, there's no $handler->override('arguments') part of my view. Here's the part that seems to be relevant:

$handler->override_option('filters', array(
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'event' => 'event',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
  'status' => array(
    'operator' => '=',
    'value' => '1',
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
    'relationship' => 'none',
  ),
  'date_filter' => array(
    'operator' => 'between',
    'value' => array(
      'value' => '2009-03-05 00:00:00',
      'min' => array(
        'date' => '',
      ),
      'max' => array(
        'date' => '',
      ),
      'default_date' => 'now',
      'default_to_date' => 'now +7 days',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'date_fields' => array(
      'node_data_field_date.field_date_value' => 'node_data_field_date.field_date_value',
    ),
    'date_method' => 'OR',
    'granularity' => 'day',
    'form_type' => 'date_text',
    'default_date' => 'now',
    'default_to_date' => 'now +7 days',
    'year_range' => '-3:+3',
    'id' => 'date_filter',
    'table' => 'node',
    'field' => 'date_filter',
    'relationship' => 'none',
  ),
));
marcvangend’s picture

Title: Default argument for date fields does not work » Default argument for 'Node: Created year' does not work

OK, your bug concerns filters, mine is about arguments. They are both date-related, so they might share a common cause, but for now, I think it's better if you create a new issue for your problem. I'm changing back the title.

Andrew Schulman’s picture

OK. Following the instructions for reporting issues in Views, I went to report this at the Date module and found my issue already there: http://drupal.org/node/386406 , with lots of others suffering from it, and a fix already available in -dev.

Good luck with your issue.
Andrew.

marcvangend’s picture

Thanks andrew, good to see that you found the source of your problem (and that it's almost solved :-)).

David Stosik’s picture

Hello,
I'm experiencing a bug close to the description.
When using "fixed" or "PHP" to provide a default value for the argument "node: created year", it is not taken into account, and "the query is not executed".
I had this bug with 2.2, updated to 2.3 and the problem is still here. :)
I hope this will get corrected soon...

merlinofchaos’s picture

Status: Active » Closed (duplicate)
marcvangend’s picture

Thanks Earl, it's great to see yet another release with so many fixes and improvements. I can't imagine Drupal without Views anymore.

agenciadroopi’s picture

I have tried using the disable Archive view, enabling it and then change the Node: Created year/month to Node: Created Year, so I have found that I need to update the page display too, that was pretty silly error