Adding to existing arrays?

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by robertdouglass on April 18, 2006 at 2:08pm

Given this existing code:

function node_views_tables() {
$tables['node'] = array(
'name' => 'node',
'provider' => 'internal', // won't show up in external list.
'fields' => array(
'title' => array(
'name' => t('Node: Title'),
'handler' => array(
'views_handler_field_nodelink' => t('Normal'),
'views_handler_field_nodelink_with_mark' => t('With updated mark')
),
'sortable' => true,
'addlfields' => array('changed'),
'help' => t('Display the title of the node.'),
),

Can I do this?

function my_mod_views_tables() {
$tables['node']['fields']['title']['handler']['my_title_handler'] = t('Special sauce');
}

This would be so groovy because then we could add to what has already been built.

Categories:

Comments

Sadly no

Posted by merlinofchaos on April 18, 2006 at 2:29pm

But it's a really good idea to be able to do that. I'll have to ponder how to do it right.

views_form_alter

Posted by moshe weitzman on May 1, 2006 at 6:08am

heh. this comes from the form_alter() family. nice idea.

+1 on this idea. I have

Posted by karens on May 18, 2006 at 2:26pm

+1 on this idea. I have places I'd like to use it.

Wouldn't it just be a matter of changing the way you build the tables array? Currently you load in the whole array for each table, which obviously wipes out anything anyone else has tried to do with that table. If you just added to instead of replaced the array, a module could add some additional elements to one or more of the arrays without overwriting whatever else has already been defined.

I wanted to define some additional items for the node table. I got far enough to be able to add my own table arrays, but I wiped out any existing data in that table's array when I did it :-(

Unfortunately because it's

Posted by merlinofchaos on May 20, 2006 at 12:34am

Unfortunately because it's using nested arrays of basically arbitrary depth, simple array merges doesn't work. The alter hook is the only real solution.

Agree

Posted by robertdouglass on May 20, 2006 at 8:00am

No automated way to do this. The views_alter hook, however, would be golden.

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /