Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mfb’s picture

Title: Token replacement not working because *.token.inc files are not included » Token replacement not working because *.tokens.inc files are not included
Dave Reid’s picture

Component: base system » token system

Re-test of tokens.patch from comment @comment was requested by aspilicious.

arhak’s picture

regarding this issue, think about its "backport", which would consist only in some documentation #681938: document proper practice for mymodule.token.inc files

Dave Reid’s picture

Status: Needs review » Fixed

I can't duplicate this since it works just fine for me. This shouldn't be necessary since module_implements() should auto-include the .tokens.inc files. Please re-open if you can re-confirm with latest HEAD code.

mfb’s picture

Status: Fixed » Postponed (maintainer needs more info)

It looks to me like I'm somehow getting an empty hook_info cache when bootstrap mode causes a module list without system module to be built (the token hook_info is provided by system module). I'll see if I can figure out how this is happening -- not sure if it's a particular configuration or something I broke on this site..

mfb’s picture

Title: Token replacement not working because *.tokens.inc files are not included » Token replacement not working if second language is enabled
Status: Postponed (maintainer needs more info) » Needs work

OK I'm not crazy, you should be able to reproduce this if you enable a second language.

The empty hook_info array is getting cached during module_invoke_all('language_init', $types) in drupal_language_initialize().

mfb’s picture

Component: token system » language system

Probably an issue in language or base system.

Dave Reid’s picture

Dave Reid’s picture

Oh wow, yeah you're right. Enabled a second language and *poof* there went tokens. So the problem is when we have multiple languages enabled, the call to module_invoke_all calls module_implements before we have a full bootstrap, add all modules loaded. So its caching the wrong information.

Dave Reid’s picture

Title: Token replacement not working if second language is enabled » hook_language_init is a bootstrap hook and needs bootstrap_invoke_all()
Status: Needs work » Needs review
FileSize
1.72 KB

Ok got this figured out. Since its called before we have a full bootstrap, we need to convert this to bootstrap_invoke_all() so that hook implementations aren't cached too early.

Tested the attached patch and confirmed that we get the correct results from module_hook_info() and tokens worked.

Dave Reid’s picture

Priority: Normal » Critical

Upgrading to critical as it breaks functionality completely if more than one language is enabled.

mfb’s picture

OK had to disable/enable a module to get the bootstrap_hooks() to refresh.

You changed the input for hook_language_init() implementations to a nested array.
Without patch:
Array ( [0] => language [1] => language_interface [2] => language_url )
With patch:
Array ( [1] => Array ( [0] => language [1] => language_interface [2] => language_url ) )

Dave Reid’s picture

Ack, yeah. Give this one a try. It uses the same format as module_invoke_all().

mfb’s picture

Ideally we could avoid cufa() altogether (for speed), if we have a defined set of bootstrap hooks with at most one argument.

sun’s picture

Status: Needs review » Reviewed & tested by the community
mfb’s picture

Status: Reviewed & tested by the community » Needs work

This should invoke all rather than returning while iterating thru the modules.

Dave Reid’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
1.78 KB

Fixed. Back to RTBC.

jurgenhaas’s picture

I'd love to test and review this patch but it is outdated and can't be applied to the current D7 dev release. Could you please re-roll the patch?

Dave Reid’s picture

jurgenhaas’s picture

The patch is for bootstrap.inc revision 1.352 but the current file is of revision 1.362 and the file has changed a bit since.

greggles’s picture

The patch still applies fine. Here it is re-rolled to remove some offsets.

sun’s picture

Status: Reviewed & tested by the community » Needs work

Some other patch got mixed into that one.

greggles’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
1.99 KB

Thanks for catching that.

moshe weitzman’s picture

code looks good to me. nice detective work

jurgenhaas’s picture

Works fine here too.

Dries’s picture

I'm confused. I searched core for language_init and didn't came up with any results.

drupal-cvs dries$ grep -r "language_init(" *

Dave Reid’s picture

There aren't any core implementations of it. It's merely for contrib I'm guessing. But the fact is it causes major problems with module_implements() caching.

mfb’s picture

@Dries hook_language_init() is a hook that can be used by contrib modules; it's not used by core.

The problem is an empty hook_info array is getting cached during module_invoke_all('language_init', $types) because most modules are not yet loaded at this point in bootstrap. by calling bootstrap_invoke_all() instead, you avoid generating the cache.

Dries’s picture

I'd like to better understand that hook then. Is there a reason that hook should be called language_init? Why can't those modules use _boot() ? It sounds to me like this warrants some code comments.

mfb’s picture

There's an open issue here #593746: Prepare Drupal core for dynamic data translation where this undocumented hook is supposed to be documented..

Dries’s picture

I was asking about the name of the hook because other modules might want a similar hook? I'm not sure other use cases exist. If they are other use cases for a similar hook, we should probably go with a more generic name?

mfb’s picture

I don't see any problem with the hook_language_init() name. Core has already staked a claim on hook_language_, see http://api.drupal.org/api/search/7/hook_language_ and the name generally makes sense given that it is invoked by drupal_language_initialize() during the DRUPAL_BOOTSTRAP_LANGUAGE phase of bootstrap.

plach’s picture

@Dries: hook_language_init() was introduced to have a safe method to translate configuration variables, translation that cannot rely on the method proposed in #593746: Prepare Drupal core for dynamic data translation; IIRC the _init suffix has been given because the hook invocation happens in the language initialization phase.

To generalize this approach we might want to introduce a bootstrap hook to alter the configuration variables (e.g. hook_configuration_alter()) at a proper bootstrap phase. This must happen after language initialization to be useful, though.

Dries’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for the explanations. That seems to make sense. Could we, at a minimum, at some minimal documentation so we don't end up scratching our heads 2 years from now?

plach’s picture

Status: Needs work » Needs review
FileSize
2.38 KB

Here is the hook documentation. I reverted the cufa change as the $types parameter was uneeded.

Status: Needs review » Needs work

The last submitted patch, language_init_bootstrap-642782-36.patch, failed testing.

plach’s picture

Status: Needs work » Needs review
FileSize
2.31 KB

rerolled

sun’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, thanks!

Dries’s picture

I'm still slightly puzzled for the need of this hook. Typically, variables are translated on output.

sun’s picture

@Dries: Actually, no. :) Variables are user-defined strings and therefore shouldn't be translated via t() at all, since the source string can change without notice and you'll lose any translation you had for it. The i18n module for D6 implemented a tt() function to translate arbitrary user-defined strings, but that didn't gain full momentum throughout Drupal. A couple of Internationalization team members are now working on new translation systems for D7 over in the http://drupal.org/project/translation project. Among those is #593746: Prepare Drupal core for dynamic data translation, which identified the need for a dedicated hook to translate variables, which runs as early as possible in the bootstrap (ie. directly after variables and the language system have been initialized).

Dries’s picture

Thanks for the explanation in #41. I think we could make the PHPdoc of the example code in the patch a bit more meaty by embedding some of that information into it. It would have avoided my questions.

plach’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
2.88 KB

meatier docs :)

plach’s picture

+++ modules/locale/locale.api.php	6 Apr 2010 22:39:56 -0000
@@ -25,6 +25,34 @@ function hook_locale($op = 'groups') {
+ * variables. ¶

trailing whitespace :(

Powered by Dreditor.

sun’s picture

Status: Needs review » Reviewed & tested by the community
Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

chx’s picture

Priority: Critical » Normal
Status: Fixed » Active
 /**
 * modules implementing hook_boot() should be aware that language initialization
 * did not happen yet and thus they cannot rely on translated variables.
 */
function hook_language_init() {

that's incorrect, either add it to hook_boot or change it to hook_language_init

greggles’s picture

Status: Active » Needs review
FileSize
980 bytes

So, something more like this?

sun’s picture

FileSize
4.26 KB

A good chance to clean a couple of things up.

plach’s picture

+++ modules/system/system.api.php	7 Apr 2010 20:10:54 -0000
@@ -864,31 +864,41 @@ function hook_forms($form_id, $args) {
- * For example, this hook is a typical place for modules to add CSS or JS
- * that should be present on every page. This hook is not run on cached
- * pages - though CSS or JS added this way will be present on a cached page.

Looks good. Just a question: why were the lines above removed?

Powered by Dreditor.

sun’s picture

No longer sure why I removed it. I guess because it sounds like we are suggesting that it is a good idea to globally and unconditionally add JS/CSS on all pages.

plach’s picture

IMO the comment above suggests that might exist cases in which makes sense adding JS/CSS on all pages. What about restoring it? ;)

plach’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Needs work
Issue tags: +Needs backport to D7
chx’s picture

Version: 8.x-dev » 7.x-dev
Status: Needs work » Active
Issue tags: -Needs backport to D7

hook_language_init is gone from 8.x

  • Dries committed 97c14a9 on 8.3.x
    - Patch #642782 by plach, Dave Reid, greggles, mfb: hook_language_init...

  • Dries committed 97c14a9 on 8.3.x
    - Patch #642782 by plach, Dave Reid, greggles, mfb: hook_language_init...

  • Dries committed 97c14a9 on 8.4.x
    - Patch #642782 by plach, Dave Reid, greggles, mfb: hook_language_init...

  • Dries committed 97c14a9 on 8.4.x
    - Patch #642782 by plach, Dave Reid, greggles, mfb: hook_language_init...

  • Dries committed 97c14a9 on 9.1.x
    - Patch #642782 by plach, Dave Reid, greggles, mfb: hook_language_init...