Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If I add a file field to a webform and my mytheme_form_element()
checks for $element['#type']
to add some classes to specific types I get a notice
Notice: Undefined index: #type in mytheme_form_element_label() (line 430 of sites\all\themes\mytheme\theme.form.inc).
All other fields have the type defined.
Repro case:
- Create web form
- Add file field and press Add.
- Save
- Notice,
node/xxx/webform/components/y?destination=node/xx/webform
Repro case 2:
- Edit
- Notice,
node/xxx/webform/components/y?destination=node/xx/webform
I do not think that I need to expect that ['#type']
is undefined. Please make sure every form element has type defined.
Comment | File | Size | Author |
---|---|---|---|
#1 | 2013-06-26_233118.png | 36.16 KB | hass |
Comments
Comment #1
hass CreditAttribution: hass commentedComment #2
hass CreditAttribution: hass commentedComment #3
quicksketchThanks, yeah this element is kind of weird. It's not really worth making a real element via hook_element_info(), but it in itself is not an element by itself. Maybe we just make up a #type name? That seems like it might cause other problems. Maybe just setting #type = NULL would be the easiest fix, at least it would eliminate notices if checking #type.
Comment #4
hass CreditAttribution: hass commentedNo, we need to set a proper
#type
. For being able to inject classes via preprocess functions to the fields I need to know what form field type this is. At least this is the only reliable context that I have for adding classes to form fields.e.g.
#type = webform_file_extensions
Comment #5
hass CreditAttribution: hass commentedA code example may be of interest. Same type of code exist for core theme_form_element and tons of other form theme functions.
Comment #6
sonicthoughts CreditAttribution: sonicthoughts commented+1 for this error with artisteer generated theme.
Comment #6.0
sonicthoughts CreditAttribution: sonicthoughts commenteda
Comment #7
DanChadwick CreditAttribution: DanChadwick commentedI am going to close this for lack of activity. If there is still an issue with file components not having a #type, then please post a patch that you would like to see committed. Otherwise, I suggest you use isset to test before accessing it.
Comment #8
hass CreditAttribution: hass commentedThe bug seems not fixed and every element need to have a type with no exception.
Comment #9
DanChadwick CreditAttribution: DanChadwick commentedSee #3. Quicksketch is aware of this and won't be changing the design. Your isset workaround will have to do.
Comment #10
hass CreditAttribution: hass commentedNope, the bug need to be fixed in the module.
Comment #11
DanChadwick CreditAttribution: DanChadwick commentedPatches welcome.
Comment #12
hass CreditAttribution: hass commentedComment #14
DanChadwick CreditAttribution: DanChadwick commentedCommitted to 7.x-4.x and 8.x.