buildConfigurationForm '#options' element shows up as a textfield rather than a dropdown.

Created on 18 July 2024, 5 months ago
Updated 12 September 2024, 3 months ago

Problem/Motivation

buildConfigurationForm '#options' element shows up as a textfield rather than a dropdown.

Steps to reproduce

Follow the tutorial video on a drupal 9+ site.

My function looks like this:

class BackgroundColor extends BlockStyleBase {

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return ['background' => 'block--blue'];
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $elements['background'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Background Color'),
      '#options' => [
        '' => $this->t('Default'),
        'block--blue' => $this->t('Blue'),
        'block--dark-blue' => $this->t('Dark Blue'),
      ],
      '#default_value' => $this->configuration['background'],
    ];

    return $elements;
  }

}
πŸ› Bug report
Status

Closed: works as designed

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024