commit 5863bc1803c724f84586ebd761f58020347a80c5 Author: Raphaƫl Droz Date: Mon Dec 10 00:21:02 2012 +0100 and Enable/Disable field translation. diff --git a/entity_translation.drush.inc b/entity_translation.drush.inc new file mode 100644 index 0000000..1c9339b --- /dev/null +++ b/entity_translation.drush.inc @@ -0,0 +1,112 @@ + 'Enable Field translation.', + 'drupal dependencies' => array('entity_translation'), + //'callback' => '_specific_function', + //'options' => array('opt' => 'description'), + //'aliases' => array('X'), + 'arguments' => array( + 'fields' => 'One or more space-separated field names for field translation must be enabled.', + ), + 'examples' => array( + 'drush ET-enable-FT title' => 'Enable field translation for the field named title.', + ), + ); + + $items['ET-disable-FT'] = array( + 'description' => 'Disable Field translation.', + 'drupal dependencies' => array('entity_translation'), + 'arguments' => array( + 'fields' => 'One or more space-separated field names for field translation must be disabled.', + ), + 'examples' => array( + 'drush ET-disable-FT title' => 'Disable field translation for the field named title.', + ), + ); + + $items['ET-upgrade'] = array( + 'description' => 'Upgrade from content type translation to field translation. This could be run only once per node-type.', + 'drupal dependencies' => array('entity_translation_upgrade'), + 'arguments' => array( + 'types' => 'One or more space-separated node types.', + ), + + ); + + return $items; +} + +function drush_entity_translation_ET_enable_FT() { + module_load_include('inc', 'entity_translation', 'entity_translation.admin'); + $args = func_get_args(); + if (empty($args)) { + return drush_set_error('', 'No field supplied.'); + } + + $pseudoform = array(); + foreach($args as $field_name) { + $field = field_info_field($field_name); + $pseudoform['values']['translatable'] = $field['translatable']; + $pseudoform['field']['field_name'] = $field_name; + entity_translation_translatable_form_submit(array(), $pseudoform); + } +} + +// same as above ... +function drush_entity_translation_ET_disable_FT() { + $args = func_get_args(); + if (empty($args)) { + return drush_set_error('', 'No field supplied.'); + } + + module_load_include('inc', 'entity_translation', 'entity_translation.admin'); + $pseudoform = array(); + foreach($args as $field_name) { + $field = field_info_field($field_name); + $pseudoform['values']['translatable'] = $field['translatable']; + $pseudoform['field']['field_name'] = $field_name; + entity_translation_translatable_form_submit(array(), $pseudoform); + } +} + +function drush_entity_translation_ET_upgrade() { + $args = func_get_args(); + if (empty($args)) { + $types = array();; + foreach (node_type_get_types() as $type) + $types[] = $type->type . "\t(" . $type->name . ')'; + $types = implode("\n", $types); + return drush_set_error('', "Please select one or more node types among those available:\n" . $types); + } + + $pseudoform = array(); + $pseudoform['values']['types'] = $args; + // we send 0 => $type , instead of checkboxes scheme: $type => $type + // but this may work anyway + entity_translation_upgrade_submit(array(), $pseudoform); +}