I have a custom field with multiple values. I would like it to work with the Entity module. I need to create the correct property_callback in hook_field_info(). My field schema looks like this:

<?php
...
'ref' => array(
  'type' => 'varchar',
  'length' => 32, 
  'not null' => TRUE,
),
'title' => array(
  'type' => 'varchar',
  'length' => 255,
  'not null' => TRUE,
  'default' => '',
),
'description' => array(
  'type' => 'text',
  'not null' => TRUE,
  'size' => 'big',
),
'weight' => array(
  'type' => 'int',
  'unsigned' => TRUE,
  'not null' => TRUE,
  'default' => 0,
),
'status' => array(
  'type' => 'int',
  'unsigned' => TRUE,
  'not null' => TRUE,
  'default' => 1,
),
...
?>

Any guidance would be greatly appreciated.

Comments

tce’s picture

I ended up with the following. Seems to work.

<?php
/**
 * Implements hook_field_info().
 */
function MYMODULE_field_info() {
  return array(
    'my_field' => array(
      ...
      'property_type' => 'my_field',
      'property_callbacks' => array('my_field_property_info_callback'),
    ), 
  );
}

function my_field_property_info_callback(&$info, $entity_type, $field, $instance, $field_type) {
  $property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$field['field_name']];

  $property['getter callback'] = 'entity_metadata_field_verbatim_get';
  $property['setter callback'] = 'entity_metadata_field_verbatim_set';
  unset($property['query callback']);

  $property['property info']['field'] = array(
    'type' => 'text',
    'label' => t('Field'),
    'description' => 'blah blah',
    'setter callback' => 'entity_property_verbatim_set',
    'required' => TRUE,
  );
  $property['property info']['title'] = array(
    'type' => 'text',
    'label' => t('Title'),
    'description' => 'blah blah',
    'setter callback' => 'entity_property_verbatim_set',
    'required' => TRUE,
  );
  $property['property info']['description'] = array(
    'type' => 'text',
    'label' => t('Description'),
    'description' => 'blah blah',
    'setter callback' => 'entity_property_verbatim_set',
  );
  $property['property info']['weight'] = array(
    'type' => 'integer',
    'label' => t('Weight'),
    'description' => 'Weight of the category to decide position.',
    'setter callback' => 'entity_property_verbatim_set',
    'required' => TRUE,
  );
  $property['property info']['status'] = array(
    'type' => 'integer',
    'label' => t('Status'),
    'description' => 'blah blah.',
    'setter callback' => 'entity_property_verbatim_set',
    'required' => TRUE,
  );
}
?>

I'd be grateful is someone can explain this part:

<?php
  $property['getter callback'] = 'entity_metadata_field_verbatim_get';
  $property['setter callback'] = 'entity_metadata_field_verbatim_set';
  unset($property['query callback']);
?>