diff --git a/sources/entity/tmgmt_entity.source.test b/sources/entity/tmgmt_entity.source.test index 3db881b..437e385 100644 --- a/sources/entity/tmgmt_entity.source.test +++ b/sources/entity/tmgmt_entity.source.test @@ -54,7 +54,7 @@ class TMGMTEntitySourceTestCase extends TMGMTEntityTestCaseUtility { $node = $this->createNode('article'); // Create a job item for this node and add it to the job. $item = $job->addItem('entity', 'node', $node->nid); - $this->assertEqual(t('@type (@bundle)', array('@type' => t('Content'), '@bundle' => 'Article')), $item->getSourceType()); + $this->assertEqual(t('@type (@bundle)', array('@type' => t('Node'), '@bundle' => 'Article')), $item->getSourceType()); } // Translate the job. @@ -90,7 +90,7 @@ class TMGMTEntitySourceTestCase extends TMGMTEntityTestCaseUtility { $term = $this->createTaxonomyTerm($this->vocabulary); // Create the item and assign it to the job. $item = $job->addItem('entity', 'taxonomy_term', $term->tid); - $this->assertEqual(t('@type (@bundle)', array('@type' => t('Term'), '@bundle' => $this->vocabulary->name)), $item->getSourceType()); + $this->assertEqual(t('@type (@bundle)', array('@type' => t('Taxonomy term'), '@bundle' => $this->vocabulary->name)), $item->getSourceType()); } // Request the translation and accept it. $job->requestTranslation(); diff --git a/sources/i18n_string/tmgmt_i18n_string.module b/sources/i18n_string/tmgmt_i18n_string.module index 85d2de7..4a54f6f 100644 --- a/sources/i18n_string/tmgmt_i18n_string.module +++ b/sources/i18n_string/tmgmt_i18n_string.module @@ -70,27 +70,6 @@ function tmgmt_i18n_string_get_strings($type, $search_label = NULL, $limit = 20) } /** - * Gets wrapper class name for given textgoup and type. - * - * This does not work for block as it does not provide the - * $object_info['string translation']['type'] property. - * - * @param string $textgroup - * @param string $type - * - * @return string - */ -function tmgmt_i18n_string_source_get_object_wrapper($textgroup, $type) { - foreach (i18n_object_info() as $object_type => $object_info) { - if (isset($object_info['string translation']['textgroup']) && $object_info['string translation']['textgroup'] == $textgroup) { - if ((isset($object_info['string translation']['type']) && $object_info['string translation']['type'] == $type) || (!isset($object_info['string translation']['type']) && $object_type == $type)) { - return $object_type; - } - } - } -} - -/** * Implements hook_form_ID_alter(). * * Adds request translation capabilities into i18n translate tab. @@ -160,7 +139,7 @@ function tmgmt_i18n_string_translate_form_validate($form, &$form_state) { function tmgmt_i18n_string_translate_form_submit($form, &$form_state) { $items = array_filter($form_state['values']['languages']); - $type = 'i18n_string'; + $type = $form_state['values']['object']->get_type(); $source_lang = variable_get_value('i18n_string_source_language'); $jobs = array(); diff --git a/sources/i18n_string/tmgmt_i18n_string.plugin.inc b/sources/i18n_string/tmgmt_i18n_string.plugin.inc index e983b55..f1c025e 100644 --- a/sources/i18n_string/tmgmt_i18n_string.plugin.inc +++ b/sources/i18n_string/tmgmt_i18n_string.plugin.inc @@ -14,17 +14,17 @@ class TMGMTI18nStringSourcePluginController extends TMGMTDefaultSourcePluginCont * Overrides TMGMTDefaultSourcePluginController::getData(). */ public function getData(TMGMTJobItem $job_item) { - - $identifiers = $this->getI18nObjectIdentifiers($job_item); - $i18n_strings = $this->getI18nObjectWrapper($job_item)->get_strings(); - - $structure = array('#label' => 'i18n Strings: ' . $identifiers['type']); - foreach ($i18n_strings as $string_id => $string) { - $structure[$string_id] = array( - '#label' => $string->title, - '#text' => $string->string, - '#translate' => TRUE - ); + $i18n_object = $this->getI18nObjectWrapper($job_item); + $structure = array('#label' => t('i18n Strings: @title', array('@title' => $i18n_object->get_title()))); + if ($i18n_object instanceof i18n_string_object_wrapper) { + $i18n_strings = $i18n_object->get_strings(); + foreach ($i18n_strings as $string_id => $string) { + $structure[$string_id] = array( + '#label' => $string->title, + '#text' => $string->string, + '#translate' => TRUE + ); + } } return $structure; } @@ -50,12 +50,8 @@ class TMGMTI18nStringSourcePluginController extends TMGMTDefaultSourcePluginCont * Implements TMGMTSourcePluginControllerInterface::getLabel(). */ public function getLabel(TMGMTJobItem $job_item) { - $data = $job_item->getData(); - - if (!empty($data) && $keys = element_children($data)) { - $key = reset($keys); - $item = $data[$key]; - return strip_tags(drupal_substr($item['#text'], 0, 64)) . ' (' . $job_item->item_id . ')'; + if ($i18n_object = $this->getI18nObjectWrapper($job_item)) { + return strip_tags(drupal_substr($i18n_object->get_title(), 0, 64)) . ' (' . $job_item->item_id . ')'; } return parent::getLabel($job_item); } @@ -64,26 +60,19 @@ class TMGMTI18nStringSourcePluginController extends TMGMTDefaultSourcePluginCont * Implements TMGMTSourcePluginControllerInterface::getUri(). */ public function getUri(TMGMTJobItem $job_item) { - $wrapper = $this->getI18nObjectWrapper($job_item); - return array( - 'path' => $wrapper->get_path(), - 'options' => array(), - ); + if ($wrapper = $this->getI18nObjectWrapper($job_item)) { + return array( + 'path' => $wrapper->get_path(), + 'options' => array(), + ); + } } /** * Implements TMGMTEntitySourcePluginControllerInterface::getType(). */ public function getType(TMGMTJobItem $job_item) { - $identifiers = $this->getI18nObjectIdentifiers($job_item); - // @todo: Improve this, use item_type? - if ($label = $this->getItemTypeLabel($identifiers['textgroup'])) { - return $label; - } - if ($label = $this->getItemTypeLabel($identifiers['textgroup'] . '_' . $identifiers['type'])) { - return $label; - } - if ($label = $this->getItemTypeLabel($identifiers['type'])) { + if ($label = $this->getItemTypeLabel($job_item->item_type)) { return $label; } return parent::getType($job_item); @@ -93,17 +82,13 @@ class TMGMTI18nStringSourcePluginController extends TMGMTDefaultSourcePluginCont /** * Helper function to get i18n_object_wrapper for given job item. * - * This is critical part that does not work for all i18n string types. - * For example this will give fatal error for rules_config. - * * @param TMGMTJobItem $job_item * * @return i18n_string_object_wrapper */ protected function getI18nObjectWrapper(TMGMTJobItem $job_item) { $identifiers = $this->getI18nObjectIdentifiers($job_item); - $type = tmgmt_i18n_string_source_get_object_wrapper($identifiers['textgroup'], $identifiers['type']); - return i18n_get_object($type, $identifiers['id']); + return i18n_get_object($job_item->item_type, $identifiers['id']); } /** diff --git a/sources/i18n_string/tmgmt_i18n_string.test b/sources/i18n_string/tmgmt_i18n_string.test index 9340cb7..6c3d0e7 100644 --- a/sources/i18n_string/tmgmt_i18n_string.test +++ b/sources/i18n_string/tmgmt_i18n_string.test @@ -45,7 +45,7 @@ class TMGMTI18nStringSourceTestCase extends TMGMTBaseTestCase { $job->settings = array(); $job->save(); - $item1 = $job->addItem('i18n_string', 'i18n_string', $string_object_name); + $item1 = $job->addItem('i18n_string', 'taxonomy_vocabulary', $string_object_name); $this->assertEqual(t('Vocabulary'), $item1->getSourceType()); $job->requestTranslation(); @@ -79,8 +79,8 @@ class TMGMTI18nStringSourceTestCase extends TMGMTBaseTestCase { $job->settings = array(); $job->save(); - $item1 = $job->addItem('i18n_string', 'i18n_string', $string_object_name); - $this->assertEqual(t('Term'), $item1->getSourceType()); + $item1 = $job->addItem('i18n_string', 'taxonomy_term', $string_object_name); + $this->assertEqual(t('Taxonomy term'), $item1->getSourceType()); $job->requestTranslation(); foreach ($job->getItems() as $item) { @@ -103,6 +103,8 @@ class TMGMTI18nStringSourceTestCase extends TMGMTBaseTestCase { // Enabling this here as enabling it with tmgmt_ui results in missing views // handlers errors. Not sure why, but this way it at least works. module_enable(array('i18n_menu')); + drupal_static_reset('_tmgmt_plugin_info'); + drupal_static_reset('_tmgmt_plugin_controller'); // Test translation of a menu. ///////////////////////////////////// @@ -123,7 +125,7 @@ class TMGMTI18nStringSourceTestCase extends TMGMTBaseTestCase { $job->translator = $this->translator->name; $job->settings = array(); - $item1 = $job->addItem('i18n_string', 'i18n_string', $string_name); + $item1 = $job->addItem('i18n_string', 'menu', $string_name); $this->assertEqual(t('Menu'), $item1->getSourceType()); $job->requestTranslation(); foreach ($job->getItems() as $item) { @@ -143,15 +145,16 @@ class TMGMTI18nStringSourceTestCase extends TMGMTBaseTestCase { // Test translation of a menu item. ///////////////////////////////////// + $source_text = $this->randomName(); $menu_link = array( 'link_path' => '', - 'link_title' => 'home', + 'link_title' => $source_text, + // i18n_menu_link::get_title() uses the title, set that too. + 'title' => $source_text, 'menu_name' => $menu['menu_name'], 'customized' => TRUE, ); menu_link_save($menu_link); - - $source_text = $menu_link['link_title']; $string_name = 'menu:item:' . $menu_link['mlid']; // Create the new job and job item. @@ -159,7 +162,7 @@ class TMGMTI18nStringSourceTestCase extends TMGMTBaseTestCase { $job->translator = $this->translator->name; $job->settings = array(); - $item1 = $job->addItem('i18n_string', 'i18n_string', $string_name); + $item1 = $job->addItem('i18n_string', 'menu_link', $string_name); $this->assertEqual(t('Menu link'), $item1->getSourceType()); $job->requestTranslation(); foreach ($job->getItems() as $item) { diff --git a/sources/i18n_string/tmgmt_i18n_string.ui.inc b/sources/i18n_string/tmgmt_i18n_string.ui.inc index 0796354..a97bee3 100644 --- a/sources/i18n_string/tmgmt_i18n_string.ui.inc +++ b/sources/i18n_string/tmgmt_i18n_string.ui.inc @@ -50,7 +50,7 @@ class TMGMTI18nStringDefaultSourceUIController extends TMGMTDefaultSourceUIContr $i18n_strings = tmgmt_i18n_string_get_strings($type, $search_data['label']); - foreach ($this->getTranslationData($i18n_strings) as $id => $data) { + foreach ($this->getTranslationData($i18n_strings, $form_state['item_type']) as $id => $data) { $form['items']['#options'][$id] = $this->overviewRow($type, $data); } @@ -64,16 +64,17 @@ class TMGMTI18nStringDefaultSourceUIController extends TMGMTDefaultSourceUIContr * * @param array $i18n_strings * Result of the search query returned by tmgmt_i18n_string_get_strings(). + * @param string $type + * I18n object type. * * @return array * Structured array with translation data. */ - protected function getTranslationData($i18n_strings) { + protected function getTranslationData($i18n_strings, $type) { $objects = array(); $source_language = variable_get_value('i18n_string_source_language'); foreach ($i18n_strings as $object) { - $type = tmgmt_i18n_string_source_get_object_wrapper($object->textgroup, $object->type); $wrapper = i18n_get_object($type, $object->objectid); if ($wrapper instanceof i18n_string_object_wrapper) { @@ -209,7 +210,7 @@ class TMGMTI18nStringDefaultSourceUIController extends TMGMTDefaultSourceUIContr // Handle search redirect. $this->overviewSearchFormRedirect($form, $form_state, $type); $items = array_filter($form_state['values']['items']); - $type = 'i18n_string'; + $type = $form_state['item_type']; $source_lang = variable_get_value('i18n_string_source_language'); diff --git a/ui/tmgmt_ui.module b/ui/tmgmt_ui.module index 3102ca5..ed7c944 100644 --- a/ui/tmgmt_ui.module +++ b/ui/tmgmt_ui.module @@ -176,6 +176,8 @@ function tmgmt_ui_embed_view($view, $display_id = NULL, array $args = array()) { */ function tmgmt_ui_source_overview_form($form, &$form_state, $plugin, $item_type = NULL) { $controller = tmgmt_source_ui_controller($plugin); + $form_state['plugin'] = $plugin; + $form_state['item_type'] = $item_type; return $controller->overviewForm($form, $form_state, $item_type); }