I have created simple entity and trying to output data with Views.
There is a property with 'integer' type.

function test_entity_api_entity_property_info() {
  $info = array();
  $properties = &$info['test_entity']['properties'];

  $properties = array(
    'test_option' => array(
      'label' => t('Test Option'),
      'description' => t('Test Option.'),
      'type'  => 'integer',
      'schema field' => 'test_option',
      'options list' => 'test_entity_api_test_option_options_list',
    ),
  );
  return $info;
}

function test_entity_api_test_option_options_list() {
  return array(t('Pending'), t('Accepted'), t('Declined'));
}

Works like a charm!
I can use fields and set up filters. Options list works great here.

But now I would like to output value from option list using options list callback.
There is a problem. Views simply doesn't see properties with 'list' type.

'test_option' => array(
  'label' => t('Test Option'),
  'description' => t('Test Option.'),
  'type'  => 'list', // this is not working...
  'schema field' => 'test_option',
  'options list' => 'test_entity_api_test_option_options_list',
)

May be I doing something wrong?
Thanks for any help!

Comments

haggins’s picture

I have the same problem. My property is of type list<int>. In general, it contains just a serialized array of numbers.

But it's not available in views. Did I use the list<> type wrong or did I miss anything?
Unfortunately, I found no example for implementing list properties for comparison.

Its setter and getter callback are as follows:

function mymodule_set_numbers(&$data, $name, $value, $langcode, $type, $info) {
  $name = isset($info['schema field']) ? $info['schema field'] : $name;
  if (is_array($data) || (is_object($data) && $data instanceof ArrayAccess)) {
    $data[$name] = serialize($value);
  }
  elseif (is_object($data)) {
    $data->$name = serialize($value);
  }
}
function mymodule_get_numbers($data, array $options, $name, $type, $info) {
  $name = isset($info['schema field']) ? $info['schema field'] : $name;
  if ((is_array($data) || (is_object($data) && $data instanceof ArrayAccess)) && isset($data[$name])) {
    return unserialize($data[$name]);
  }
  elseif (is_object($data) && isset($data->$name)) {
    return unserialize($data->$name);
  }
  return NULL;
}
$numbers = array(5, 23, 30);

// set
$wrapper->numbers->set($numbers);

// get
$wrapper->numbers->value(); // returns the array
$wrapper->numbers[0]->value(); // returns 1st value
maen’s picture

Issue summary: View changes

For those who are as talented as me:
I made the first working by changing the optionlist.

function test_entity_api_entity_property_info() {
  $info = array();
  $properties = &$info['test_entity']['properties'];
  $properties = array(
    'test_option' => array(
      'label' => t('Test Option'),
      'description' => t('Test Option.'),
      'type'  => 'integer',
      'schema field' => 'test_option',
      'options list' => 'test_entity_api_test_option_options_list',
    ),
  );
  return $info;
}
function test_entity_api_test_option_options_list() {
  return array(0=>t('Pending'), 1=>t('Accepted'),2=> t('Declined'));
}

Views can see it.

milos.kroulik’s picture

I may be wrong, but I think, that it's because there is no Entity API alternative to views_handler_field_serialized field handler. So maybe it's really a feature request?