Drupal : 6.15
PHP : 5.2
I have a custom node type module which I wanted to integrate with Views. By following the advanced help I was able to add my field to an example view. The preview looks OK, I can see the field values stored in my table in a node listing but as soon as I save the view, the GUI reports my added field as broken/missing and my values don't show up any more. My views group also disappears from the menus. This is probably intended since there is no valid fields any more. My group reappears when I remove my broken field from the example view and clear the Views cache.
Here is the code in my custom_module.views.inc file (I gutted is as much as possible for debugging) :
function custom_module_views_data() {
// Basic table information.
$data = array();
$data['my_node_table']['table']['group'] = t('Custom');
$data['my_node_table']['table']['join'] = array(
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
);
$data['my_node_table']['my_numeric_field'] = array(
'title' => t('My custom field'),
'help' => t('Some help message'),
'field' => array(
'handler' => 'views_handler_field_numeric',
// 'click sortable' => TRUE,
),
);
return $data;
}
This should be simple and straightforward so any theories about why my field becomes broken after working in Preview?
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | node_example.zip | 4.42 KB | pembeci |
Comments
Comment #1
merlinofchaos commentedThe only thing that comes to mind is if, for some reason, your module's hook_views_data is disappearing during the cache rebuild, so that the fields actually go away completely. One test for that might be to see...when you see the view in this broken state, are your fields available to be added?
Comment #2
pembeci commentedMore information:
* If I clear the cache without removing my broken reported field from the view and then visit the view's page I can see my field's values as nothing wrong happened. If I edit my view after all these, same thing happens (saving the view breaks my field). This began to look like a bug to me, so I am changing the issue category.
* To make sure my example view wasn't the problem I cloned the tracker view and added my field to it and same thing happened. Preview works after adding my custom field. It continues to work if I add one of the existing fields (Node: New comments) or a filter (Node: type) . When I save the view, my field becomes broken:missing handler.
* I am not changing anything on the customize form while I am adding my field.
* I turned on PHP notice messages at custom.inc and after the save there were no PHP messages reported related to views. When I try to view my view I get this one :
which is normal I guess:
Comment #3
pembeci commentedwhen you see the view in this broken state, are your fields available to be added
No, that's what I meant by "my views group also disappears from the menus". My fields become unavailable.
Your post came when I was preparing #2, thanks for the quick reply. Do you think this is a bug or result of my own settings? What can cause "hook_views_data is disappearing during the cache rebuild"?
Comment #4
pembeci commentedThis is emberrasing. After checking that node_example module in the API integrates OK with Views 2 at my system I became sure that it was something in my custom module's coding. Finally, I noticed that I put the hook_views_api function into another theme function (I was working on the views.inc file so never checked my .module file). Moving that out solved the problem. Since it was inside that function I guess sometimes it was available but not during view saving.
I am attaching the example module with Views 2 API integration for future reference. So at least some good can come through of my hours spent on this.
merlin, thanks for the support.