$entity) { $queried_entities[$id] = i18n_translation_set_build($entity->type, $entity); } return parent::attachLoad($queried_entities, $revision_id); } } /** * Implements hook_entity_info(). */ function i18n_translation_entity_info() { $bundles = array(); foreach (i18n_translation_set_info() as $type => $info) { $bundles[$type] = array( 'label' => $info['title'], ); } $return = array( 'i18n_translation' => array( 'label' => t('Translation set'), 'controller class' => 'I18nTranslationSetController', 'base table' => 'i18n_translation_set', //'uri callback' => 'taxonomy_term_uri', 'fieldable' => FALSE, 'entity keys' => array( 'id' => 'tsid', 'bundle' => 'type', 'label' => 'title', ), 'bundle keys' => array( 'bundle' => 'type', ), 'bundles' => $bundles, ), ); return $return; } /** * Implements hook_menu() */ function i18n_translation_menu() { $items['admin/config/regional/i18n_translation'] = array( 'title' => 'Translation sets', 'description' => 'Translation sets overview.', 'page callback' => 'drupal_get_form', 'page arguments' => array('i18n_translation_set_overview'), 'access arguments' => array('administer site configuration'), 'file' => 'i18n_translation.admin.inc', 'weight' => 10, ); $items['admin/config/regional/i18n_translation/configure'] = array( 'title' => 'Translation sets', 'description' => 'Overview of existing translation sets.', 'type' => MENU_DEFAULT_LOCAL_TASK, ); return $items; } /** * Get list of translation modes */ function i18n_translation_options() { return array( I18N_MODE_NONE => t('None. No multilingual options.'), I18N_MODE_LOCALIZE => t('Localize. Items are common for all languages, but their name and description may be localized.'), I18N_MODE_TRANSLATE => t('Translate. Different items will be allowed for each language and they can be translated.'), I18N_MODE_LANGUAGE => t('Language. Items will have a global language and they will only show up for pages in that language.'), ); } /** * Build translation fieldset for object */ function i18n_translation_set_element($type, $object) { $element = array( '#type' => 'fieldset', '#title' => t('Translations'), ); if ($set = i18n_translation_object($type, $object)) { $element['values']['#markup'] = i18n_translation_format_items($set->item_list()); } else { $element['message']['#markup'] = t('No translations'); } return $element; } /** * Format translation set info as table */ function i18n_translation_format_items($translations) { foreach ($translations as $langcode => $item) { $rows[] = array(i18n_language_name($langcode), $item); } return !empty($rows) ? theme('table', array('rows' => $rows)) : ''; } /** * Get translation set for object */ function i18n_translation_object($type, $object, $create = FALSE) { $info = i18n_translation_set_info($type); if ($tsid = i18n_object_field($object, $info['translation set']['field'])) { return i18n_translation_set_load($tsid, $type); } elseif ($create) { $set = i18n_translation_set_build($type); if ($langcode = i18n_object_langcode($object)) { $set->add_item($object, $langcode); } return $set; } } /** * Get information about translation sets */ function i18n_translation_set_info($type = NULL) { if ($type) { if (($info = i18n_object_info($type)) && !empty($info['translation set'])) { return $info; } } else { $list = array(); foreach (i18n_object_info() as $type => $info) { if (!empty($info['translation set'])) { $list[$type] = $info; } } return $list; } } /** * Build a translation set from type, data */ function i18n_translation_set_build($type, $data = array()) { $info = i18n_translation_set_info($type); $class = isset($info['translation set']['class']) ? $info['translation set']['class'] : 'i18n_translation_set'; $set = new $class((array)$data); $set->type = $type; return $set; } /** * Create a new translation set */ function i18n_translation_set_create($type, $bundle = '', $translations = NULL, $master_id = 0) { $set = i18n_translation_set_build($type, array('type' => $type, 'bundle' => $bundle, 'master_id' => $master_id, 'translations' => $translations)); $set->insert(); return $set; } /** * Load single translation set */ function i18n_translation_set_load($tsid, $type = NULL) { $conditions['tsid'] = $tsid; if ($type) { $conditions['type'] = $type; } return reset(entity_load('i18n_translation', FALSE, $conditions)); } /** * Index objects in translation set by language */ function i18n_translation_set_index($translations) { $list = array(); foreach ($translations as $object) { if ($lang = i18n_object_langcode($object)) { $list[$lang] = $object; } } return $list; } /** * Translation set generic form */ function i18n_translation_set_overview($form, &$form_state, $type = NULL, $tsids = NULL) { module_load_include('admin.inc', 'i18n_translation'); return i18n_translation_admin_form($form, $form_state, $type); }