Perhaps I am missing something very basic (and I'd appreciate some enlightenment if so), but I'm working on a view this morning that uses numeric fields, and getting constant errors on line 262 of this function, saying that $element is an undefined variable. And looking at the code it does, indeed, seem to be undefined. just adding an initialization of the variable at the top of the function solved the problem:

function number_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
$element = array(); 

I'll post a patch later when I finish working on this view, but it's so basic I want to make sure I'm not overlooking the obvious. Thanks.

Comments

Ken Ficara’s picture

Hmm. I cannot reproduce this on a clean install. It may be an OpenPublish issue.

marcingy’s picture

Status: Active » Postponed (maintainer needs more info)
neRok’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Closing postponed issue as per advice in #1.

Anonymous’s picture

Version: 7.15 » 7.22
Status: Closed (cannot reproduce) » Active

From PHP Manual

Relying on the default value of an uninitialized variable is problematic in the case of including one file into another which uses the same variable name. It is also a major security risk with register_globals turned on. E_NOTICE level error is issued in case of working with uninitialized variables, however not in the case of appending elements to the uninitialized array. isset() language construct can be used to detect if a variable has been already initialized.

To see it you should enable error reporting for all possible levels, and you will get that Notice.

forestgardener’s picture

I can confirm that I receive the same notice as Ken describes on a Drupal 7.23 installation when Dev module is activated and I am working on a view that uses numeric fields.
I can also confirm that the addition of the line
$element = array();
to the function that Ken cites fixes the issue.

eesquibel’s picture

Issue summary: View changes

I can confirm I get this bug on 7.29 when I use the field_extrawidgets module to make a Read-Only Integer field and set the Formatter to "Unformatted"

number_field_formatter_settings_form should always return an array, even if empty

peterpoe’s picture

Version: 7.22 » 7.x-dev
Component: field system » number.module
Status: Active » Needs review
StatusFileSize
new579 bytes

When display type is "number_unformatted" (or in general, not "number_decimal" or "number_integer"), $elements is never instantiated.

minax.de’s picture

Status: Needs review » Reviewed & tested by the community

Easy fix for obvious bug or at least bad code style, so RTBC.

stefan.r’s picture

Issue tags: +Pending Drupal 7 commit

Looks good to me! Marking for commit.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Pending Drupal 7 commit

Hm, 'number_unformatted' doesn't have settings so the settings form shouldn't ever be displayed for it.

But I can imagine some contrib module reusing or altering this in a way that does trigger the bug, and some of the comments above seem to indicate that's actually happening. Plus as noted above the current code is really just bad style (and inconsistent with how other examples of this hook do it, including the example at https://api.drupal.org/api/drupal/modules!field_ui!field_ui.api.php/func...).

So.. committed to 7.x. Thanks!

  • David_Rothstein committed 11dac6e on 7.x
    Issue #1732906 by peterpoe, Ken Ficara, forestgardener, eesquibel, minax...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.