- Issue created by @wetbadger
- πΊπΈUnited States segovia94You need to use '#type' => 'select'. Your code is set to'#type' => 'textfield'.
- Status changed to Closed: works as designedabout 1 year ago 1:10pm 12 September 2024
buildConfigurationForm '#options' element shows up as a textfield rather than a dropdown.
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;
  }
}
Closed: works as designed
2.0
Code
You need to use '#type' => 'select'. Your code is set to '#type' => 'textfield'.