NULL)); } /** * Check if a module is registered as a translation handler for a given entity. * * If no handler is passed, simply check if there is any translation handler * enabled for the given entity type. * * @param $entity_type * The type of the entity whose fields are to be translated. * @param $handler * The name of the handler to be checked. * * @return * TRUE, if the handler is allowed to manage field translations. */ function field_multilingual_check_translation_handlers($entity_type, $handler = NULL) { $obj_info = entity_get_info($entity_type); if (isset($handler)) { return isset($obj_info['translation'][$handler]) && !empty($obj_info['translation'][$handler]); } elseif (isset($obj_info['translation'])) { foreach ($obj_info['translation'] as $handler_info) { // The translation handler must use a non-empty data structure. if (!empty($handler_info)) { return TRUE; } } } return FALSE; } /** * Helper function to ensure that a given language code is valid. * * Checks whether the given language is one of the enabled languages. Otherwise, * it returns the current, global language; or the site's default language, if * the additional parameter $default is TRUE. * * @param $langcode * The language code to validate. * @param $default * Whether to return the default language code or the current language code in * case $langcode is invalid. * @return * A valid language code. */ function field_multilingual_valid_language($langcode, $default = TRUE) { $enabled_languages = field_multilingual_content_languages(); if (in_array($langcode, $enabled_languages)) { return $langcode; } global $language; $langcode = $default ? language_default('language') : $language->language; if (in_array($langcode, $enabled_languages)) { return $langcode; } // @todo Throw a more specific exception. throw new FieldException('No valid content language could be found.'); }