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.
Problem
When adding a form select via Form API in a custom module without #attributes set this error occurs.
Example:
$form['selected'] = array(
'#type' => 'select',
'#title' => t('Selected'),
'#options' => array(0 => t('No')),
'#description' => t('Set this to <em>Yes</em> if you would like this category to be selected by default.'),
);
Notice: Undefined index: #attributes in mothership_select() (line 480 of /www/devel/heggan/sites/default/themes/mothership/mothership/functions/form.php).
Recoverable fatal error: Argument 1 passed to drupal_attributes() must be an array, null given, called in /www/devel/heggan/sites/default/themes/mothership/mothership/functions/form.php on line 480 and defined in drupal_attributes() (line 2296 of /www/devel/heggan//includes/common.inc).
As #attributes it not required in the Form API itself it should not be required with mothership.
$form['selected'] = array(
'#type' => 'select',
'#title' => t('Selected'),
'#options' => array(0 => t('No')),
'#description' => t(''),
'#attributes' => array(),
);
Proposed resolution
Change row 480 in functions/form.php
From:
return '<select' . drupal_attributes($element['#attributes']) . '>' . form_select_options($element) . '</select>';
To:
return '<select' . (is_array($element['#attributes']) ? drupal_attributes($element['#attributes']) : null) . '>' . form_select_options($element) . '</select>';
Comment | File | Size | Author |
---|---|---|---|
#1 | 1717404-mothership-undefined-index-attributes-1.patch | 1.09 KB | Ferrari |
Comments
Comment #1
Ferrari CreditAttribution: Ferrari commentedCreated a patch for this.
Comment #2
jyraya CreditAttribution: jyraya commentedThe problem is still there with the version 7.x-2.10.
What is planned with this problem? The patch will be integrated in a future version or not?