Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $node = entity_create('node', array('type' => 'MY-CONTENT-TYPE'));
- $entity = entity_metadata_wrapper('node', $node);
- $data = array('column_1'=>'value 1', 'column_2'=>'value 2', 'column_3'=>'value 3');
- $entity->field_custom_compound_field = $data;
- $entity->save();
- /**
- * Implements hook_field_info().
- *
- * Provides the description of the field.
- */
- function field_example_field_info() {
- return array(
- // We name our field as the associative name of the array.
- 'field_example_rgb' => array(
- 'label' => t('Example Color RGB'),
- 'description' => t('Demonstrates a field composed of an RGB color.'),
- 'default_widget' => 'field_example_3text',
- 'default_formatter' => 'field_example_simple_text',
- 'property_type' => 'field_example_rgb', // we add the propert type here
- 'property_callbacks' => array('field_example_rgb_property_info_callback'), // we add the callback
- ),
- );
- }
- function field_example_rgb_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']['rgb'] = array(
- 'type' => 'text',
- 'label' => t('RGB'),
- 'setter callback' => 'entity_property_verbatim_set',
- );
- $property['property info']['someothervalue'] = array(
- 'type' => 'text',
- 'label' => t('Some other value'),
- 'setter callback' => 'entity_property_verbatim_set',
- );
- }
- $node = entity_create('node', array('type' => 'MY-CONTENT-TYPE'));
- $entity = entity_metadata_wrapper('node', $node);
- $data = array('column_1'=>'value 1', 'column_2'=>'value 2', 'column_3'=>'value 3');
- $entity->field_custom_compound_field = $data;
- $entity->save();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement