You are here

SelectSettingType.php in UI Patterns Settings 8

Same filename and directory in other branches
  1. 8.2 src/Plugin/UiPatterns/SettingType/SelectSettingType.php

File

src/Plugin/UiPatterns/SettingType/SelectSettingType.php
View source
<?php

namespace Drupal\ui_patterns_settings\Plugin\UIPatterns\SettingType;

use Drupal\ui_patterns_settings\Definition\PatternDefinitionSetting;
use Drupal\ui_patterns_settings\Plugin\PatternSettingTypeBase;

/**
 * Select setting type.
 *
 * @UiPatternsSettingType(
 *   id = "select",
 *   label = @Translation("Select")
 * )
 */
class SelectSettingType extends PatternSettingTypeBase {

  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, $value, PatternDefinitionSetting $def) {
    $options = [
      "" => $this
        ->t("Please select"),
    ];
    $options += $def
      ->getOptions();
    $form[$def
      ->getName()] = [
      '#type' => 'select',
      '#title' => $def
        ->getLabel(),
      '#description' => $def
        ->getDescription(),
      '#default_value' => $this
        ->getValue($value),
      '#required' => $def
        ->getRequired(),
      '#options' => $options,
    ];
    return $form;
  }

}

Classes

Namesort descending Description
SelectSettingType Select setting type.