You are here

public function SwaggerUIFormatter::settingsForm in Swagger UI Field Formatter 8

Returns a form to configure settings for the formatter.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form elements for the formatter settings.

Overrides FormatterBase::settingsForm

File

src/Plugin/Field/FieldFormatter/SwaggerUIFormatter.php, line 40

Class

SwaggerUIFormatter
Plugin implementation of the 'swagger_ui' formatter.

Namespace

Drupal\swagger_ui_formatter\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $form = parent::settingsForm($form, $form_state);
  $form['validator'] = [
    '#type' => 'select',
    '#title' => $this
      ->t("Validator"),
    '#description' => $this
      ->t("Default=Swagger.io's online validator, None= No validation, Custom=Provide a custom validator url"),
    '#default_value' => $this
      ->getSetting('validator'),
    '#options' => [
      'none' => $this
        ->t('None'),
      'default' => $this
        ->t('Default'),
      'custom' => $this
        ->t('Custom'),
    ],
  ];
  $form['validator_url'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t("Validator URL"),
    '#description' => $this
      ->t("The custom validator url to be used to validated the swagger files."),
    '#default_value' => $this
      ->getSetting('validator_url'),
    '#states' => [
      'visible' => [
        ':input[name="fields[' . $this->fieldDefinition
          ->getName() . '][settings_edit_form][settings][validator]"]' => [
          'value' => 'custom',
        ],
      ],
    ],
  ];
  $form['doc_expansion'] = [
    '#type' => 'select',
    '#title' => $this
      ->t("Doc Expansion"),
    '#description' => $this
      ->t("Controls how the API listing is displayed."),
    '#default_value' => $this
      ->getSetting('doc_expansion'),
    '#options' => [
      'none' => $this
        ->t('None - Expands nothing'),
      'list' => $this
        ->t('List - Expands only tags'),
      'full' => $this
        ->t('Full - Expands tags and operations'),
    ],
  ];
  $form['show_top_bar'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t("Show Top Bar"),
    '#description' => $this
      ->t("Controls whether the Swagger UI top bar should be displayed or not."),
    '#default_value' => $this
      ->getSetting('show_top_bar'),
  ];
  $form['sort_tags_by_name'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t("Sort tags by name"),
    '#description' => $this
      ->t("Controls whether the tag groups should be ordered alphabetically or not."),
    '#default_value' => $this
      ->getSetting('sort_tags_by_name'),
  ];
  $form['supported_submit_methods'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t("Try it out support for HTTP Methods"),
    '#description' => $this
      ->t("List of HTTP methods that have the Try it out feature enabled. Selecting none disables Try it out for all operations. This does not filter the operations from the display."),
    '#default_value' => $this
      ->getSetting('supported_submit_methods'),
    '#options' => [
      'get' => $this
        ->t('GET'),
      'put' => $this
        ->t('PUT'),
      'post' => $this
        ->t('POST'),
      'delete' => $this
        ->t('DELETE'),
      'options' => $this
        ->t('OPTIONS'),
      'head' => $this
        ->t('HEAD'),
      'patch' => $this
        ->t('PATCH'),
    ],
  ];
  return $form;
}