how to implement hook_views_data() and add a field?
Hi, All I want is just return a number, which comes from a sql query count of my custom table. I want to represent that as a field so I can adjust it's position in the views ui. It doesn't sounds like very hard, right? I've looked into the views api 2, but there's really no useful information... Anybody can help? Regards, Yi Yang
On Wed, Jan 7, 2009 at 12:41 PM, yi yang <yang_yi_cn@yahoo.com> wrote:
Hi,
All I want is just return a number, which comes from a sql query count of my custom table. I want to represent that as a field so I can adjust it's position in the views ui. It doesn't sounds like very hard, right?
I've looked into the views api 2, but there's really no useful information...
Anybody can help?
Regards, Yi Yang
The best place to look is at the code that views provides to add support for core. Look in views/modules. andrew
yi yang wrote:
Hi,
All I want is just return a number, which comes from a sql query count of my custom table. I want to represent that as a field so I can adjust it's position in the views ui. It doesn't sounds like very hard, right?
Views doesn't support doing things like COUNT() in normal operation yet.
All I need is just a placeholder. Say, how can I implement a hook to return a static number as a field? Is it possible? Then I can theme it to whatever I want. --- On Wed, 1/7/09, Earl Miles <merlin@logrus.com> wrote:
From: Earl Miles <merlin@logrus.com> Subject: Re: [development] how to implement hook_views_data() and add a field? To: development@drupal.org, yang_yi_cn@yahoo.com Date: Wednesday, January 7, 2009, 2:07 PM yi yang wrote:
Hi,
All I want is just return a number, which comes from a sql query count of my custom table. I want to represent that as a field so I can adjust it's position in the views ui. It doesn't sounds like very hard, right?
Views doesn't support doing things like COUNT() in normal operation yet.
I think you want a custom field handler. Check the handlers section of the Views API. See, for example, http://drupal.org/node/349178 /me stops pimping his patch now. On Wed, Jan 7, 2009 at 5:55 PM, yi yang <yang_yi_cn@yahoo.com> wrote:
All I need is just a placeholder. Say, how can I implement a hook to return a static number as a field? Is it possible? Then I can theme it to whatever I want.
--- On Wed, 1/7/09, Earl Miles <merlin@logrus.com> wrote:
From: Earl Miles <merlin@logrus.com> Subject: Re: [development] how to implement hook_views_data() and add a field? To: development@drupal.org, yang_yi_cn@yahoo.com Date: Wednesday, January 7, 2009, 2:07 PM yi yang wrote:
Hi,
All I want is just return a number, which comes from a sql query count of my custom table. I want to represent that as a field so I can adjust it's position in the views ui. It doesn't sounds like very hard, right?
Views doesn't support doing things like COUNT() in normal operation yet.
-- Ken Rickard agentrickard@gmail.com http://ken.therickards.com
Aha, I find a solution myself. First, I learned some syntax from the user_relationships module. Then, in my hook_views_data(), I defined my 'table' with no 'join'. After that, define a fake 'field', in the details of the fake field settings array, I wrote a subquery in the 'real field', which does the COUNT(*). It works fine now! --- On Wed, 1/7/09, Ken Rickard <agentrickard@gmail.com> wrote:
From: Ken Rickard <agentrickard@gmail.com> Subject: Re: [development] how to implement hook_views_data() and add a field? To: development@drupal.org, yang_yi_cn@yahoo.com Date: Wednesday, January 7, 2009, 3:25 PM I think you want a custom field handler. Check the handlers section of the Views API.
See, for example, http://drupal.org/node/349178
/me stops pimping his patch now.
On Wed, Jan 7, 2009 at 5:55 PM, yi yang <yang_yi_cn@yahoo.com> wrote:
All I need is just a placeholder. Say, how can I implement a hook to return a static number as a field? Is it possible? Then I can theme it to whatever I want.
--- On Wed, 1/7/09, Earl Miles <merlin@logrus.com> wrote:
From: Earl Miles <merlin@logrus.com> Subject: Re: [development] how to implement hook_views_data() and add a field? To: development@drupal.org, yang_yi_cn@yahoo.com Date: Wednesday, January 7, 2009, 2:07 PM yi yang wrote:
Hi,
All I want is just return a number, which comes from a sql query count of my custom table. I want to represent that as a field so I can adjust it's position in the views ui. It doesn't sounds like very hard, right?
Views doesn't support doing things like COUNT() in normal operation yet.
-- Ken Rickard agentrickard@gmail.com http://ken.therickards.com
participants (4)
-
andrew morton -
Earl Miles -
Ken Rickard -
yi yang