1

I am using Drupal 7.x and have a created a custom entity. I am using the Entity API module to extend EntityDefaultMetadataController and override public function entityPropertyInfo() to add properties for displaying when my entity is viewed.

More information on hook_property_entity_info:

http://www.drupalcontrib.org/api/drupal/contributions!entity!entity.api.php/function/hook_entity_property_info/7

I understand how to return different types of properties such as 'text', 'int', 'list', 'entity', and so on, using callbacks. However, I have not been able to successfully return a type of 'struct'. My field is always empty when I try to display it.

Example code:

  $info['properties']['my-structure_property'] = array(
  'label' => t('My Structure Property'),  
  'type' => 'struct',
  'getter callback' => ?  // What should this return?
  'property info' => array(
    'sub_field1' => array(
      'type' => 'text', 
      'label' => t('Subfield 1'), 
      'getter callback' => 'entity_metadata_sub_field1_property_get', // Returns a text field
    ), 
    'sub_field2' => array(
      'type' => 'entity', 
      'label' => t('Subfield 1'), 
      'getter callback' => 'entity_metadata_sub_field2_property_get', // Returns an entity
    ), 
  ),
); 

What should I be returning in my callback? I have tried returning an object, an array...?

1 Answer 1

0

Based on entity_metadata_node_entity_property_info_alter() and entity_property_text_formatted_info(), I suppose the getter callback should be the most generic callback the entity API offers: entity_property_verbatim_get.

This should allow you to access the properties as: $custom_entity->structure_property->sub_field1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.