Trying to override a views field handler with another. Doing it with the node field handler just to test, the sole visible change expected is the help text on the link to node option should be different. Have read the advanced help, hooks docs, code, etc., but am missing something. 1. Created a module directory with typical .info file, which modules finds and is happy with. In particular, it contains: files[] = my.module files[] = my_views.inc files[] = my_handler_field_node.inc 2. In my.module (which has a weight of 11) function my_views_handlers() { return array('my_handler_field_node'); } 3. my_views.inc is the same as node_views.inc except the function names are changed from node_views to my_views in my_views_handlers() the handler for field node is changed to my_handler_field_node in $data['node']['title'] the handler name is changed to my_handler_field_node 4. my_handler_field_node.inc is the same as views_handler_field_node.inc except the class name was changed and the help text for the link to node form item in the options for is changed and....yup, of course, no change.
Realized I was missing a hook, but adding it hasn't helped. I'm going to paste the code here, since it's short. sites/all/modules/my/my.info ; $Id: name = Test Handler description = Overrides a view handler package = My modules files[] = my.module files[] = my_views.inc files[] = my_handler_field_node.inc version = "7.x-1.0" core = "7.x" php = 5.2 sites/all/modules/my/my.module <?php /** * Implements hook_views_handlers(). */ function my_views_handlers() { return array( 'my_handler_field_node'); } /** * Implements hook_views_api(). */ function my_views_api() { return array( 'api' => 2, ); } sites/all/modules/my/my.views.inc /** * Implements hook_views_data_alter() */ function my_views_data_alter(&$data) { $data['node']['title']['field']['handler'] = 'my_handler_field_node'; return $data; } /** * Implements hook_views_handlers() to register all of the basic handlers * views uses. */ function my_views_handlers() { return array( 'handlers' => array( 'my_handler_field_node' => array( 'parent' => 'views_handler_field_node', ), ), ); } sites/all/modules/my/my_handler_field_node.inc class my_handler_field_node extends views_handler_field { function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); $form['link_to_node'] = array( '#title' => t('Link this field to its node'), '#description' => t('This is different text.'), '#type' => 'checkbox', '#default_value' => !empty($this->options['link_to_node']), ); }
Jeff Under Views -> Tools there is a button to clear the views cache. I seem to recall you need to do that for views to see your changes. Nevets
Nevets, is that not covered by the cache clear button under performace? I've been using that one. Ayen Designs - quality software the first time, every time! -----Original Message----- From: Steve Ringwood <nevets@tds.net> Sender: development-bounces@drupal.org Date: Sun, 17 Oct 2010 23:30:14 To: <development@drupal.org> Reply-To: development@drupal.org, nevets@mailbag.com Subject: Re: [development] Views field handler being ignored Jeff Under Views -> Tools there is a button to clear the views cache. I seem to recall you need to do that for views to see your changes. Nevets
Jeff Not sure if is covered by cache clear button under performance, I use the one under views > tools. Nevets
Voila, but not without some weirdness. In the code I posted yesterday, you might notice I have the hook_views_handlers appearing twice, in the .modules file and in the views.inc file. Of course, both cannot be active at the same time. The interesting thing is that the occurrence in the .module file implements the hook in the same way that it is in the code being overridden. That doesn't work. The occurrence in the views.inc file does work. sites/all/modules/my/my.info
sites/all/modules/my/my.module ... function my_views_handlers() { return array( 'my_handler_field_node'); }
sites/all/modules/my/my.views.inc function my_views_handlers() { return array( 'handlers' => array( 'my_handler_field_node' => array( 'parent' => 'views_handler_field_node', ), ), ); }
On 10/18/2010 10:21 AM, jeff@ayendesigns.com wrote:
function my_views_handlers() { return array( 'my_handler_field_node'); }
This clearly doesn't work, since handlers need to be keys to an array. I think you're mistaken that any part of Views implements hook_views_handlers() like this.
You're correct sir, of course. That's not what's in the code. I'm not sure where that came from...most likely an edit of mine gone bad. Sorry about the unintended slander. On the positive side, when I'm mistaken, I err in an unambiguous manner :-) Jeff On 10/19/2010 01:08 PM, Earl Miles wrote:
On 10/18/2010 10:21 AM, jeff@ayendesigns.com wrote:
function my_views_handlers() { return array( 'my_handler_field_node'); }
This clearly doesn't work, since handlers need to be keys to an array. I think you're mistaken that any part of Views implements hook_views_handlers() like this.
On 10/17/2010 7:45 PM, jeff@ayendesigns.com wrote:
3. my_views.inc is the same as node_views.inc except the function names are changed from node_views to my_views in my_views_handlers() the handler for field node is changed to my_handler_field_node in $data['node']['title'] the handler name is changed to my_handler_field_node
What happens when both 'node' and your 'myviews' return $data['node']. When you look at $data['node'] which do you get? This is why you must use hook_views_data_alter() to modify tables owned by other modules rather than hook_views_data(), otherwise you get undefined results when PHP tries to figure out which one of you wins the collision.
Definitely. That occurred to me between the two messages. I might need to reinstall the module, as I changed a file name? Also, does it matter that my test changes the option form text, not the render? Its the form that hasn't changed yet. Ayen Designs - quality software the first time, every time! -----Original Message----- From: Earl Miles <merlin@logrus.com> Sender: development-bounces@drupal.org Date: Sun, 17 Oct 2010 21:41:32 To: <development@drupal.org> Reply-To: development@drupal.org Subject: Re: [development] Views field handler being ignored On 10/17/2010 7:45 PM, jeff@ayendesigns.com wrote:
3. my_views.inc is the same as node_views.inc except the function names are changed from node_views to my_views in my_views_handlers() the handler for field node is changed to my_handler_field_node in $data['node']['title'] the handler name is changed to my_handler_field_node
What happens when both 'node' and your 'myviews' return $data['node']. When you look at $data['node'] which do you get? This is why you must use hook_views_data_alter() to modify tables owned by other modules rather than hook_views_data(), otherwise you get undefined results when PHP tries to figure out which one of you wins the collision.
participants (3)
-
Earl Miles -
jeff@ayendesigns.com -
Steve Ringwood