Commit bb618586 authored by catch's avatar catch

Issue #78292 by BrockBoland, chx, Traverus, thoufek, patrickd, sun: Fixed...

Issue #78292 by BrockBoland, chx, Traverus, thoufek, patrickd, sun: Fixed Select element with empty options triggers PHP warning.
parent 1c92546e
......@@ -2730,6 +2730,9 @@ function theme_select($variables) {
*/
function form_select_options($element, $choices = NULL) {
if (!isset($choices)) {
if (empty($element['#options'])) {
return '';
}
$choices = $element['#options'];
}
// array_key_exists() accommodates the rare event where $element['#value'] is NULL.
......
......@@ -352,6 +352,15 @@ function testSelect() {
}
}
/**
* Tests a select element when #options is not set.
*/
function testEmptySelect() {
$this->drupalGet('form-test/empty-select');
$this->assertFieldByXPath("//select[1]", NULL, 'Select element found.');
$this->assertNoFieldByXPath("//select[1]/option", NULL, 'No option element found.');
}
/**
* Tests validation of #type 'number' and 'range' elements.
*/
......
......@@ -475,6 +475,7 @@ function system_element_info() {
'#process' => array('form_process_select', 'ajax_process_form'),
'#theme' => 'select',
'#theme_wrappers' => array('form_element'),
'#options' => array(),
);
$types['language_select'] = array(
'#input' => TRUE,
......
......@@ -142,6 +142,12 @@ function form_test_menu() {
'page arguments' => array('form_test_select'),
'access callback' => TRUE,
);
$items['form-test/empty-select'] = array(
'title' => 'Empty Select Element',
'page callback' => 'drupal_get_form',
'page arguments' => array('form_test_empty_select'),
'access callback' => TRUE,
);
$items['form-test/language_select'] = array(
'title' => t('Language Select'),
'page callback' => 'drupal_get_form',
......@@ -1290,6 +1296,19 @@ function form_test_select($form, &$form_state) {
return $form;
}
/**
* Builds a form to test select elements when #options is not an array.
*/
function form_test_empty_select($form, &$form_state) {
$form['empty_select'] = array(
'#type' => 'select',
'#title' => t('Empty Select'),
'#multiple' => FALSE,
'#options' => NULL,
);
return $form;
}
/**
* Builds a form to test the language select form element.
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment