I need my field themes and formatters to know exactly which delta value of a multiple value field they are processing. With multiple date values, you often want to display only a selected date value, but the current themes (both in D5 and D6) provide no way to know which item you are handling.

It should be fairly easy to do (although I haven't tried to figure out exactly how to do it yet). The challenge might be in views fields since we'll have to make sure we have the delta value in the views results (maybe we already do, not sure).

Any objections to doing this in both D5 and D6? It's an addition, not a change, so it shouldn't break any existing code. And it might be useful to other field modules that want to do special processing of individual multiple value items. Plus, since we are letting people control the order of those values, custom themes might want that info, too.

Comments

yched’s picture

Why not, I guess.

Should be as simple as adding '#delta' in the render array built in content_nodeapi('view') :

$node->content['field_foo'] = array(
  '#type' => 'content_field',
  '#title' => 'label'
  '#field_name' => 'field_name',
  '#node' => $node,
  'items' =>
    0 => array(
      '#item' => $items[0],
      '#theme' => $theme,
      '#field_name' => 'field_name',
      '#type_name' => $node->type,
      '#formatter' => $formatter_name,
      '#delta' => 0, // <----
    ),
    1 => array(
      '#item' => $items[1],
      '#theme' => $theme,
      '#field_name' => 'field_name',
      '#type_name' => $node->type,
      '#formatter' => $formatter_name,
      '#delta' => 1, // <----
    ),
);

We'd also need to alter content_format() so that it accepts $delta as a param.

I don't think Views-retrieved field always come with delta information currently.
We do retrieve the delta when using the 'group multiple values' option, but not with 'do not group...'.
Maybe it's just a matter of adding 'delta' to the list of ''additional fields''.

This is only D6 version, of course. Code for D5 will probably be different (You really need that for D5 ? :-) )

KarenS’s picture

Status: Active » Fixed

I've committed fixes to add the delta as another column in views' additional columns, added #delta to the node elements, and allowed for content_format to pass on $item['#delta'] to the formatter if provided.

This should make it possible for any formatter that wants to know which element it is handling to deal with it intelligently.

KarenS’s picture

BTW, I committed fixes for this to both D5 and D6.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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