There is tons of documentation about adding field handlers to specific fields, but for me it only works when handling specific fields.
In my case I want to add an advanced rendering (=rewrite results in UI) option that can apply to any field, similar the trim and ellipsis options in views_handler_field.inc.

Unfortunately I've been unable to get views to recognise my extensions of the views_handler or views_handler_field class. I've tried the following in mymodule.views.inc:

class mymodule_handler_field extends views_handler_field {

  function option_definition() {
etc.
class mymodule_handler_field extends views_handler {

  function option_definition() {
etc.

Neither get picked up. In the meanwhile the other field definitions in mymodule.views.inc work fine. Is there some special naming convention I need to use for my class extension, and/or in the hook_views_data implementation.

Comments

merlinofchaos’s picture

Status: Active » Fixed

You must be misunderstanding how object oriented programming works.

Simply extending a class isn't going to automatically replace all existing calls to that original base class with your class. That simply isn't going to work, and it can't work.

There isn't a way to do what you're suggesting. It is an artifact of using inheritance. This is probably why you can't find any documentation on doing it: you can't.

jurriaanroelofs’s picture

Title: Add a field handler option to _all fields_ in a custom module » Allow modules to add field handlers to the base field handler class to support field-agnostic display alters
Category: support » feature
Status: Fixed » Active

Well, since I have a use case for doing it I'll turn this into a feature request then.
I have an abbreviation function that I would like to be able to apply to any text field. Any suggestions on how to implement this?

merlinofchaos’s picture

Status: Active » Closed (works as designed)

You don't understand.

You can't do it. Sorry, but that is one of the artifacts of the design of the system. You can't do this.

merlinofchaos’s picture

The closest thing you can do is that you can identify fields you want to modify, use hook_views_data_alter() and change the 'handler' for each field to your new one.

jurriaanroelofs’s picture

ok, thanks for your time.