Group has a sub module -- Group language.
/**
* Implements hook_language_negotiation_info().
*/
function group_language_language_negotiation_info() {
$providers = array();
$providers['group-language'] = array(
'callbacks' => array('language' => 'group_language_from_group_context'),
'weight' => -5,
'name' => t('Group'),
'description' => t("Follow the Group context's language preference."),
'file' => drupal_get_path('module', 'group_language') .'/group_language.module',
);
return $providers;
}
/**
* Identify language from Group context.
*
* @param $languages
* An array of valid language objects.
*
* @return
* A valid language code on success, FALSE otherwise.
*/
function group_language_from_group_context($languages) {
// We need a full bootstrap in order to get the group context.
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
if ($group = group_context()) {
// ... Group' own logic.
}
}
The drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
causes:
# Notice: Trying to get property of non-object in drupal_lookup_path() (line 74 of /var/www/d7_dev/includes/path.inc).
# Notice: Trying to get property of non-object in entity_get_info() (line 6359 of /var/www/d7_dev/includes/common.inc).
# Notice: Trying to get property of non-object in entity_get_info() (line 6359 of /var/www/d7_dev/includes/common.inc).
# Notice: Trying to get property of non-object in locale_init() (line 267 of /var/www/d7_dev/modules/locale/locale.module).
# Notice: Trying to get property of non-object in admin_menu_init() (line 143 of /var/www/d7_dev/sites/all/modules/admin_menu/admin_menu.module).
# Notice: Trying to get property of non-object in entity_get_info() (line 6359 of /var/www/d7_dev/includes/common.inc)
I assume the problem seems to be that the $language object should to be determined, by my negotation callback hasn't returned anything yet, so $language isn't set yet.
Comments
Comment #1
damien tournoud commentedTo load an entity, you have to know the content language, so you cannot possibly load an entity to determine the language.
I doubt there are a lot of ways around this.
Comment #2
amitaibuHere's a first stab. It might be a "naive" patch, as I still don't fully gork the bootstrapping process.
The patch adds a fallback language default.
Comment #4
amitaibu@DamZ,
Apart of the failing test, is this approach right?
Comment #5
plachWeird failure. Retesting.
Actually I think this might work, but I'd prefer someone more into the bootstrap process give his/her feedback.
"callback"
Powered by Dreditor.
Comment #6
amitaibuFix typo. Indeed, it seems the tests are now green.
Comment #7
catchPatch looks reasonable at first glance. @Damien - why do you need to know the content language to load an entity? Language negotiation is done during view rather than load with translatable fields.
Comment #8
amitaibuBump, as og_language will need this. @DamZ, can you please have a look?
Comment #9
andypostIf you loading node by ID so language is attribute so it's possible.
Suppose when you loading a node (entity) fields so _field_language_suggestion() should help
Comment #10
plachNode language is a fixed value held in the
$node->languagefield, but the value in$language_contentis computed at runtime and cannot help to load a node by its language.Comment #11
amitaibu#6: 818418-default-language-6.patch queued for re-testing.
Comment #12
amitaibuhmm, tests are still green.
@Damz,
> I doubt there are a lot of ways around this.
Does the patch overcome the doubts you had?
Comment #13
damien tournoud commentedOk. I'm still not very convinced that loading an entity before changing the language is really a good idea, but this patch makes sense. We should not actively prevent people from trying this.
Comment #14
webchickI'm not sure I totally follow why this is necessary, but the resulting code is a lot easier to read. Sounds like everyone is in agreement that this is either a good idea or it shouldn't be actively blocked.
Committed to HEAD. Thanks!