This is a quick defaut callback and handler for hook_views_arguments. I've tested it with nodereferences, but should work for most cck fields. There are other alternatives to doing it my way. 1) would be a new callback, or extending the data returned in the callbacks to make it easier to work with CCK, or 2) creating new callbacks.

I opted for something simple, general, and overrideable to get the ball rolling, and meet tomorrow's deadline. :)...

Comments

dopry’s picture

StatusFileSize
new2.53 KB

umm well I went to install that last patch on a site using the latest cvs-tar.gz.... and welp I'm not sure, but Im out of sync somewhere, so here is another patch.

karens’s picture

Glad to see someone is working on this, I was just going to make a feature request. I see you've given modules a way to add their own handler, which was another concern -- the date field in particular is going to need special handling. I'll give this a try later today.

yched’s picture

Thanks a lot for this patch dopry. I was in fact needing that just this morning :-)

One remark though :
Do you really have to append the fields labels in the $arguments table keys :

$arguments['field_'.$field['field_name'].'_'.$field['widget']['label']] = $argument;

- It makes the patch practically useless with views.module current limitation to 25 chars for arguments names
(I think I saw you posted an issue for views about that earlier today)
- The labels are plain text, they have spaces, commas, accents (I'm french), i'm not sure these "special" chars don't mess with the magic...

yched’s picture

Plus :
(same code line) isn't there a extraneous "field_" at the beginning of the key ?
$field['field_name'] already starts with "field_".

dopry’s picture

StatusFileSize
new2.57 KB

I was using the widget label to keep multiple instances of the same field seperate on the same content type seperate.... I'll figure a better way to do thie this evening. And maybe there is an extra field at the begining I can drop....

jonbob’s picture

Status: Needs review » Needs work

I don't think multiple instances of the same field *should* be separate, as far as Views is concerned. That's pretty much the whole point of having them be the same field. If they are semantically distinct, they should be different fields.

yched’s picture

JonBob: you're talking about different instances of a field in different content types - they should definitely be semantically equivalent, and thus treated the same way.

I think dopry was wondering about multiple-value fields (different "instances" in the same content type, although "instances" is probably an improper term in this case).
I'm not using multiple fields right now, so I'm not sure how this is to be managed.

(I guess I'm doing my - somewhat arrogant ? - mediator/interpretor number)

Anyway, i'm currently using dopry's patch with the incriminated line changed to

$arguments[$field['field_name']] = $argument;

and it works quite fine (once again, no multiple fields involved on my side, though...)

dopry’s picture

What happens if you create two node_reference fields on one content type? If what JobBob says is true I can drop the additional widget data. I would love it since it makes the code easier to follow. :). I justed wanted to know that I kept the proper field associated to the argument, and I was worried that value $field['field_name'] could be duplicated in a single content type, on different fields. Maybe I'm just overly paranoid, since I don't fully understand the work flow and data structures of content.module yet.

slowly grokking,
.darrel.

dopry’s picture

oh yeah, and multiple values of a single field aren't supported yet. I will implement them this evening when I have testing time. I need to see how data is stored, they may work automagically.

jonbob’s picture

"What happens if you create two node_reference fields on one content type? [...] I was worried that value $field['field_name'] could be duplicated in a single content type, on different fields."

Nope, this can't happen. If there are two node reference fields on one content type, they will have different field names. You should be perfectly safe using just the field name.

If you end up having to distinguish items in a multiple-value field, then the "delta" attribute is what you want.

yched’s picture

I think things work better when the following line in your patch (in function content_views_argument_handler) :

$query->add_where( $table .'.'. $column['column'] .' = '. $arg);

is replaced by

$query->add_where( $table .'.'. $column['column'] ." = '%s'", $arg);

But maybe this should be refined depending on the value type (%d or %f for number fields)
There's something similar in function content_field($op = 'insert')

Too late for me to propose a patch today, plus I don't want to steal dopry's credits :-)

jonbob’s picture

Status: Needs work » Fixed

A modified version has been committed. I added full summary view support, and changed the criterion for not using the default argument handling to a parameter in the database info hook. I think this is more robust, because we need to handle having more than one field defined in the same module, and they may have different argument requirements.

Ysched's comments are also incorporated.

Anonymous’s picture

Status: Fixed » Closed (fixed)