Despite reading around in code + documentation + examples, and quite a few attempts, I am unable to use the 'getter callback' for new data types in a proper way.

Situation: I want to use a custom function for retrieving a property for a custom data type. Kind of like this.

/**
 * Defines info for the properties of the views_display data structure.
 */
function _rb_views_views_display_info() {
  return array(
    'field' => array(
      'type' => 'list<views_field>',
      'label' => t('Fields'),
      'getter callback' => 'my_custom_function',
    ),
  );
}

Problem: Every time I add the 'getter callback' entry, I get fatal errors on my site. (White screen, no messages shown. I should turn on my error messages, by the way.)

Wanted: A description of how to use 'getter callback', and 'setter callback'. I suspect that there may be problems if the object they act on has internal callbacks, but I'm not sure.

Comments

itangalo’s picture

Component: Rules Core » Rules Engine

Ok, error output now turned on.

Fatal error: Call to undefined function my_custom_functoin() in …/sites/all/modules/entity/includes/entity.wrapper.inc on line 444

It seems weird that I should have to do an explicit exclude of the file with the function – it is the same file declaring the properties of the custom data type. (rb_views.rules.inc)

I'll keep on looking…

itangalo’s picture

Status: Active » Fixed

Ok. Moving the callback function to the main .module file does the trick.

Still curious about how/if I can add files to include for a particular data type, but I'll pass that question for now. Case closed!

charlie-s’s picture

I believe you need to include the reference to the include in your module.info file so that it's loaded during bootstrap, e.g.:

name = Entity API
description = Enables modules to work with any entity type and to provide entities.
core = 7.x
files[] = views/plugins/entity_plugin_row_entity_view.inc
files[] = includes/entity.controller.inc

...

itangalo’s picture

Ah, smart. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

gollyg’s picture

Component: Rules Engine » Rules Core

So the typo my_custom_functoin was not contributing to the issue?

charlie-s’s picture

Good catch. That was probably a problem, too, but OP has likely fixed.