function DependentDropdown::getSecondDropdownOptions

Same name in other branches
  1. 3.x modules/ajax_example/src/Form/DependentDropdown.php \Drupal\ajax_example\Form\DependentDropdown::getSecondDropdownOptions()
  2. 8.x-1.x ajax_example/src/Form/DependentDropdown.php \Drupal\ajax_example\Form\DependentDropdown::getSecondDropdownOptions()

Helper function to populate the second dropdown.

This would normally be pulling data from the database.

Parameters

string $key: This will determine which set of options is returned.

Return value

array Dropdown options

1 call to DependentDropdown::getSecondDropdownOptions()
DependentDropdown::buildForm in modules/ajax_example/src/Form/DependentDropdown.php
The $nojs parameter is specified as a path parameter on the route.

File

modules/ajax_example/src/Form/DependentDropdown.php, line 224

Class

DependentDropdown
Re-populate a dropdown based on form state.

Namespace

Drupal\ajax_example\Form

Code

public static function getSecondDropdownOptions($key = '') {
    switch ($key) {
        case 'String':
            $options = [
                'Violin' => 'Violin',
                'Viola' => 'Viola',
                'Cello' => 'Cello',
                'Double Bass' => 'Double Bass',
            ];
            break;
        case 'Woodwind':
            $options = [
                'Flute' => 'Flute',
                'Clarinet' => 'Clarinet',
                'Oboe' => 'Oboe',
                'Bassoon' => 'Bassoon',
            ];
            break;
        case 'Brass':
            $options = [
                'Trumpet' => 'Trumpet',
                'Trombone' => 'Trombone',
                'French Horn' => 'French Horn',
                'Euphonium' => 'Euphonium',
            ];
            break;
        case 'Percussion':
            $options = [
                'Bass Drum' => 'Bass Drum',
                'Timpani' => 'Timpani',
                'Snare Drum' => 'Snare Drum',
                'Tambourine' => 'Tambourine',
            ];
            break;
        default:
            $options = [
                'none' => 'none',
            ];
            break;
    }
    return $options;
}