Hi there,
I have this notice on the site:

    Notice: Undefined index: type in locale_js_alter() (line 911 of /modules/locale/locale.module).
    Notice: Undefined index: type in locale_js_alter() (line 911 of /modules/locale/locale.module).

See the similar error (and solutions) in advagg module #2757527: Notice: Undefined index: type in advagg_js_alter()

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jasom created an issue. See original summary.

kamalrajsahu21’s picture

Assigned: Unassigned » kamalrajsahu21
kamalrajsahu21’s picture

Assigned: kamalrajsahu21 » Unassigned
Status: Active » Needs review
FileSize
1.03 KB

Here is the patch with condition added on locale_js_alter as well as in locale_css_alter.

hgoto’s picture

Status: Needs review » Active

Thank you for sharing the issue.

I think we need to identify the exact problem first. I guess that this notice message should be solved in a module which adds/alters the element in$javascript.

@jasom, could you please add more information? It's necessary for other people to know the exact steps to reproduce the state. Thank you.

jasom’s picture

After patch in #3 notice dissapeared.

@hgoto

Sure, which "more info" do you need?

See also this: #2760909: Undefined index: scope in drupal_get_js() (line 4372 of /includes/common.inc

hgoto’s picture

@jasom, thank you for the comment.

I see. Yes, surely the notice may disappear with the patch #3 (I haven't tested it) but it doesn't fix the root problem, I believe. What do you think?

As you may know, locale_js_alter() is a hook implementation for hook_js_alter() and such implementations expect the parameter $javascript to be index array. And each element of the array can have type index.

https://api.drupal.org/api/drupal/modules%21system%21system.api.php/func...

My question is that, "Can this notice message be reproduced with a new Drupal site without any condition? Or is there any condition?". You filed this issue as a bug not a support request and I thought other people need to know more information to address this issue. What you provided is the phenomenon. "Error message appears." It's not enough for other people to share the state you encountered, I believe. At least, steps to reproduce is needed, I think. In my experience, I haven't met this notice message with a new Drupal site and I'd like more information.

The following page may be useful. Please take a look.

- https://www.drupal.org/issue-summaries

yust22’s picture

Hello
I had a similar problem , which appeared when I modified a .js with hook_js_alter

function hook_js_alter(&$javascript){
$javascript['your_path/file.js']['data'] = drupal_get_path('module', 'module_name') . '/js/module_name.js';
}

I solved by adding the type and scope of javascript:

$javascript['your_path/file.js']['scope'] = 'header';
$javascript['your_path/file.js']['type'] = 'file';

I hope you find it useful

dunot’s picture

It's after installation of advagg 7.x-2.33.
Related issue
#3 removes the notice, kamalrajsahu21, thank you.

tanmayk’s picture

Agreed with @hgoto. The type must be present there. So instead of fixing in the core, we should fix in related module. Above patch will remove the notice but the js added by module won't be processed in locale_js_alter().

edurenye’s picture

'type' is not mandatory and should default to 'file' according to the documentation: https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_...

But Drupal never sets it to file, just always assume empty is file, so either we assume here that if type is not set, it should be file, or we change drupal_add_js to set it to file if empty.

For both solutions that patch is wrong.

Version: 7.44 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.