Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I just ran into a situation where I was exporting a large number of custom entities and I wanted to exclude one of the objects' properties from export so that it would be set upon import. The only way I found to do this was to overwrite EntityAPIControllerExportable in includes/entity.controller.inc and modify export to unset those properties
public function export($entity, $prefix = '') {
$vars = get_object_vars($entity);
unset($vars[$this->statusKey], $vars[$this->moduleKey], $vars['is_new'], $vars['my_specific_property'], $vars['my_specific_property_2']);
if ($this->nameKey != $this->idKey) {
unset($vars[$this->idKey]);
}
return entity_var_json_export($vars, $prefix);
}
It would be nice to be able to define those properties in hook_entity_info like so:
$return = array(
'salesforce_mapping_list' => array(
'label' => t('Salesforce List Mapping'),
'controller class' => 'SalesforceMappingListControllerExportable',
'entity class' => 'SalesforceMappingList',
'base table' => 'salesforce_mapping_list',
'uri callback' => 'entity_class_uri',
'fieldable' => FALSE,
'exportable' => TRUE,
'skip export' => array('last_sync', 'hypothetical', 'etc'),
Attached is a patch that does just that - in case you agree with me.
Comment | File | Size | Author |
---|---|---|---|
entity_controller_exportable-skip_vars.patch | 730 bytes | markisatacomputer | |