Adding to existing arrays?

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
robertDouglass's picture

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.

Comments

Sadly no

merlinofchaos's picture

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

moshe weitzman's picture

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

+1 on this idea. I have

KarenS's picture

+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

merlinofchaos's picture

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

robertDouglass's picture

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: