Am I missing something or is there no argument for the updated time of a node at the moment?

Also, is there a HOWTO anywhere yet that tells you how to make your own argument? I looked at the API docs, but don't have time to pick through it right now, so if anyone knows of a "Quick Start" style guide, that would be great. =)

Comments

merlinofchaos’s picture

Category: support » feature

What you see is what you get in the API docs, I'm afraid.

greg.harvey’s picture

Thanks - np. The API docs are great - I'll just need to allocate more time to understanding how it works. =)

merlinofchaos’s picture

I realize i didn't answer the first question -- no there isn't an argument for updated time.

The short version for what you need to do us use hook_views_data_alter() and assign the argument handler to the 'node' table similar to how created_yearmonth works. It should take very little actual code to do this.

greg.harvey’s picture

Status: Needs review » Active

As you said, this was relatively trivial to achieve. I realised, after I did it, that it didn't actually fully meet my use case, but it's a start! =)

Apologies for not creating a patch - using Microsoft TFS for source control here and it doesn't support creating patches. Anyway, here is the code to add it straight in to 'node.views.inc' (line 121) if you would like to:

  // changed field
  $data['node']['changed'] = array(
    'title' => t('Updated date'), // The item it appears as on the UI,
    'help' => t('The date the node was last updated.'), // The help that appears on the UI,
    'field' => array(
      'handler' => 'views_handler_field_date',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_date',
    ),
    'argument' => array(
      'field' => 'changed',
      'handler' => 'views_handler_argument_node_created_fulldate',
    ),
  );

Or, alternatively, replace the node.changed handlers in your own module:

/**
 * Implementation of hook_views_data_alter()
 */
function yourmodule_views_data_alter(&$data) {
  // changed field
  $data['node']['changed'] = array(
    'title' => t('Updated date'), // The item it appears as on the UI,
    'help' => t('The date the node was last updated.'), // The help that appears on the UI,
    'field' => array(
      'handler' => 'views_handler_field_date',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_date',
    ),
    'argument' => array(
      'field' => 'changed',
      'handler' => 'views_handler_argument_node_created_fulldate',
    ),
  );
}

I've taken the latter approach for now, to keep the Views core clean in case this is in the next release. =)

greg.harvey’s picture

Status: Active » Needs review

Oops. Changing status.

merlinofchaos’s picture

Status: Active » Fixed

Not quite a year later, I committed this with substantial improvement.

Status: Fixed » Closed (fixed)

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