I am simply trying to set a default value in a select form field on a Drupal 8 block configuration form. Here are the relevant parts of my code:
$options = array( 'test' => 'value', 'random' => 'string', 'kiwi' => 'pear', ); $form['menu_selected'] = array( '#type' => 'select', '#title' => 'Test Title', '#description' => 'Test Description', '#options' => $options, '#default_value' => 'random', );
The $form then gets returned as per usual in a block build. Everything else works in the form; The options populate, the description and title display. The only thing that doesn't work is the default value. I have tried using keys and values. I even saw a comment that said to use '#value' instead of '#default_value' and still it didn't work. Can someone please tell me what I'm doing wrong? I can provide more code if needed.