I've created a custom entity and in the next step, I would like to use the Entity Translation module to make the entity translatable.
My entity is defined like this
/**
* Implements hook_entity_info().
*/
function MY_MODULE_entity_info() {
$info['custom_entity'] = array(
'label' => t('Custom Entity'),
'base table' => 'custom_entity',
'module' => 'MY_MODULE',
'uri callback' => 'custom_entity_basic_uri',
'controller class' => 'EntityCustomController',
'fieldable' => TRUE,
'entity keys' => array(
'id' => 'qid',
'label' => 'title',
),
'translation' => array(
'entity_translation' => array(
'default settings' => array(
'default_language' => 'de',
),
'base path' => 'my-path/%custom_entity',
'view path' => 'my-path/%custom_entity',
'edit path' => 'admin/my-path/%custom_entity/edit',
'translate path' => 'my-path/%custom_entity/translate',
'path wildcard' => '%custom_entity',
),
),
'static cache' => FALSE,
'bundles' => array(
'custom_entity' => array(
'label' => 'Custom bundle',
'admin' => array(
'path' => 'admin/structure/custom/manage',
'access arguments' => array('administer custom entities'),
),
),
),
'view modes' => array(
'full' => array(
'label' => t('Full'),
'custom settings' => FALSE,
),
),
);
return $info;
}
With this definition, my custom entity appears in the Entity Translation admin view (admin/config/regional/entity_translation
) and I can configure it. This seems to be correct, because in the 'manage field' tab, the language selector field appears and the 'translate' tab appears also in the edit form.
The only strange thing I found is that the language selector is not rendered in the edit form in any time. If I save the translation, the source entity is overriden with the changes, but no translation is added.
I thought the problem is my Controller class, but this seems to work correctly too:
class EntityCustomController extends EntityAPIControllerExportable {
public function create(array $values = array()) {
$values += array(
'created' => REQUEST_TIME,
'type' => 'custom_entity',
'qid' => 0,
'bundle_type' => 'custom_entity',
'title' => '',
);
return parent::create($values);
}
/**
* Save Task Type.
*/
public function save($entity, DatabaseTransaction $transaction = NULL) {
parent::save($entity, $transaction);
}
}
In my custom edit form, I use field_attach_form
function to render all the defined themes.
And, if it helps, this is my save handler:
/**
* Save entity by using the controller.
*/
function MY_MODULE_custom_entity_save(&$entity) {
return entity_get_controller('custom_entity')->save($entity);
}