You are here

protected function RestUIForm::buildConfigurationFormForResourceGranularity in REST UI 8

Subform constructor when the selected granularity is 'resource'.

Parameters

\Drupal\rest\Plugin\ResourceInterface $plugin: The REST Resource plugin being configured.

array $authentication_providers: All available authentication providers, to use for #options.

array $format_options: All available formats, to use for #options.

array $config: The current configuration for the REST Resource config entity, or the empty array if it does not yet exist.

Return value

array The subform structure.

1 call to RestUIForm::buildConfigurationFormForResourceGranularity()
RestUIForm::buildForm in src/Form/RestUIForm.php

File

src/Form/RestUIForm.php, line 297

Class

RestUIForm
Provides a REST resource configuration form.

Namespace

Drupal\restui\Form

Code

protected function buildConfigurationFormForResourceGranularity(ResourceInterface $plugin, array $authentication_providers, array $format_options, array $config) {
  $methods = $plugin
    ->availableMethods();
  $method_options = array_combine($methods, $methods);
  $form = [];

  // Methods.
  $enabled_methods = [];
  foreach ($methods as $method) {
    if (isset($config['methods']) && in_array($method, $config['methods'])) {
      $enabled_methods[$method] = $method;
    }
  }
  $form['settings']['methods'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Methods'),
    '#options' => $method_options,
    '#default_value' => $enabled_methods,
  ];

  // Formats.
  $enabled_formats = [];
  if (isset($config['formats'])) {
    $enabled_formats = $config['formats'];
  }
  $form['settings']['formats'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Accepted request formats'),
    '#options' => $format_options,
    '#default_value' => $enabled_formats,
  ];

  // Authentication providers.
  $enabled_auth = [];
  if (isset($config['authentication'])) {
    $enabled_auth = $config['authentication'];
  }
  $form['settings']['authentication'] = [
    '#title' => $this
      ->t('Authentication providers'),
    '#type' => 'checkboxes',
    '#options' => $authentication_providers,
    '#default_value' => $enabled_auth,
  ];
  return $form;
}