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.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | number-form-undefined-element-1732906-7.patch | 579 bytes | peterpoe |
Comments
Comment #1
Ken Ficara commentedHmm. I cannot reproduce this on a clean install. It may be an OpenPublish issue.
Comment #2
marcingy commentedComment #3
neRok commentedClosing postponed issue as per advice in #1.
Comment #4
Anonymous (not verified) commentedFrom PHP Manual
To see it you should enable error reporting for all possible levels, and you will get that Notice.
Comment #5
forestgardener commentedI 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.
Comment #6
eesquibel commentedI 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
Comment #7
peterpoe commentedWhen display type is "number_unformatted" (or in general, not "number_decimal" or "number_integer"), $elements is never instantiated.
Comment #8
minax.de commentedEasy fix for obvious bug or at least bad code style, so RTBC.
Comment #9
stefan.r commentedLooks good to me! Marking for commit.
Comment #10
David_Rothstein commentedHm, '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!