diff --git a/entity_translation.admin.inc b/entity_translation.admin.inc index 380560d..37c4c2e 100644 --- a/entity_translation.admin.inc +++ b/entity_translation.admin.inc @@ -426,7 +426,7 @@ function entity_translation_delete_confirm_submit($form, &$form_state) { $form_state['redirect'] = $handler->getTranslatePath(); } -/* +/** * Confirm form for changing field translatability. */ function entity_translation_translatable_form($form, &$form_state, $field_name) { @@ -497,19 +497,26 @@ function entity_translation_translatable_form_submit($form, $form_state) { return; } + entity_translation_translatable_batch_setup(!$translatable, $field_name, $copy_all_languages); +} + +/** + * Setup batch operation to convert field data to or from LANGUAGE_NONE. + */ +function entity_translation_translatable_batch_setup($translatable, $field_name, $copy_all_languages) { // If a field is untranslatable, it can have no data except under // LANGUAGE_NONE. Thus we need a field to be translatable before we convert // data to the entity language. Conversely we need to switch data back to // LANGUAGE_NONE before making a field untranslatable lest we lose // information. $operations = array( - array('entity_translation_translatable_batch', array(!$translatable, $field_name, $copy_all_languages)), - array('entity_translation_translatable_switch', array(!$translatable, $field_name)), + array('entity_translation_translatable_batch', array($translatable, $field_name, $copy_all_languages)), + array('entity_translation_translatable_switch', array($translatable, $field_name)), ); $operations = $translatable ? $operations : array_reverse($operations); $t_args = array('%field' => $field_name); - $title = !$translatable ? t('Enabling translation for the %field field', $t_args) : t('Disabling translation for the %field field', $t_args); + $title = $translatable ? t('Enabling translation for the %field field', $t_args) : t('Disabling translation for the %field field', $t_args); $batch = array( 'title' => $title, @@ -521,7 +528,7 @@ function entity_translation_translatable_form_submit($form, $form_state) { batch_set($batch); } -/* +/** * Toggle translatability of the given field. * * This is called from a batch operation, but should only run once per field. diff --git a/entity_translation.drush.inc b/entity_translation.drush.inc new file mode 100644 index 0000000..c6a48f5 --- /dev/null +++ b/entity_translation.drush.inc @@ -0,0 +1,41 @@ + 'Process translation for the given field. This means copying over data from LANGUAGE_NONE to the available languages of the entity the field data is part of', + 'arguments' => array( + 'field_name' => 'The machine name of the field for which to enable field translation', + ), + ); + + return $items; +} + +/** + * Process field translation + */ +function drush_entity_translation_process_field_translation($field_name) { + module_load_include('inc', 'entity_translation', 'entity_translation.admin'); + + // Configure the batch process + $translatable = 1; + $copy_all_languages = 1; + entity_translation_translatable_batch_setup($translatable, $field_name, $copy_all_languages); + + // Because we are doing this on the back-end, we set progressive to false. + $batch =& batch_get(); + $batch['progressive'] = FALSE; + + // Run the batch process + drush_backend_batch_process(); +}