You are here

public function ResourceWarmer::addMoreConfigurationFormElements in JSON:API Boost 8

Same name and namespace in other branches
  1. 2.x src/Plugin/warmer/ResourceWarmer.php \Drupal\jsonapi_boost\Plugin\warmer\ResourceWarmer::addMoreConfigurationFormElements()

Adds additional form elements to the configuration form.

Parameters

array $form: The configuration form to alter for the this plugin settings.

\Drupal\Core\Form\SubformStateInterface $form_state: The form state for the plugin settings.

Return value

array The form with additional elements.

Overrides WarmerInterface::addMoreConfigurationFormElements

File

src/Plugin/warmer/ResourceWarmer.php, line 175

Class

ResourceWarmer
Warms JSON:API resources.

Namespace

Drupal\jsonapi_boost\Plugin\warmer

Code

public function addMoreConfigurationFormElements(array $form, SubformStateInterface $form_state) {
  $options = [];
  foreach ($this->resourceTypeRepository
    ->all() as $resource_type) {

    /** @var \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType $resource_type */
    $key = $resource_type
      ->getJsonapiResourceConfig()
      ->id();
    $options[$key] = $resource_type
      ->getPath();
  }
  $configuration = $this
    ->getConfiguration();
  $form['resource_types'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Resource Types'),
    '#description' => $this
      ->t('Enable the JSON:API resource types to warm asynchronously.'),
    '#options' => $options,
    '#default_value' => empty($configuration['resource_types']) ? [] : $configuration['resource_types'],
  ];
  return $form;
}