We are using the entity_translation module in a large site, and we have 57 defined languages. We have some custom date fields in each locale, and we are using some custom code to only publish the locale when the current date is within the specified date range. However, one problem we are running into is that when an entity (node, taxonomy term) is created, the Published status for the default language (en-us
in our case, defined at admin/config/regional/entity_translation
) is automatically set to Published, which we don't want, so I need to override that value and set it to 0.
After delving into the module code, I found the hook_entity_translation_insert
hook, which is called from EntityTranslationDefaultHandler:saveTranslations()
:
foreach ($translations->hook as $langcode => $info) {
$translation = isset($translations->data[$langcode]) ? $translations->data[$langcode] : $langcode;
$data = isset($info['data']) ? $info['data'] : NULL;
module_invoke_all('entity_translation_' . $info['hook'], $this->entityType, $this->entity, $translation, $data);
// Provide Rules events integration if available.
if (module_exists('rules')) {
// Pass the entity as a wrapped one since rules can't do it for us
// when using the variable type 'entity'.
rules_invoke_event('entity_translation_' . $info['hook'], $this->entityType, entity_metadata_wrapper($this->entityType, $this->entity), $translation, $data);
}
}
where $op = 'insert'
. I tried implementing my hook like so:
function mymodule_entity_translation_insert($entity_type, $entity, $translation, $values = array()) {
// Set the publishing status for en-us to 0.
if ($translation['language'] == 'en-us') {
$translation['status'] = 0;
}
}
but that doesn't change the status that gets passed on. If I try passing $translation
in by reference:
function fluke_staging_entity_translation_insert($entity_type, $entity, &$translation, $values = array())
krumo gets into a huge recursive loop, and my computer maxes out the CPU.I can return a value like so:
function mymodule_entity_translation_insert($entity_type, $entity, $translation, $values = array()) {
// Set the publishing status for en-us to 0.
if ($translation['language'] == 'en-us') {
$translation['status'] = 0;
return ['translation' => $translation];
}
}
but that's worthless, too, because the hook invocation doesn't do anything with it:
module_invoke_all('entity_translation_' . $info['hook'], $this->entityType, $this->entity, $translation, $data);
as compared to
$new_data = module_invoke_all('entity_translation_' . $info['hook'], $this->entityType, $this->entity, $translation, $data);
or something like that.
So my question is, how can I override the translation status in this hook, since it doesn't seem that it's a) passable by reference, or 2) it accepts any data from the hook_entity_translation_insert
implementation?