You are here

public function EntityWarmer::addMoreConfigurationFormElements in Warmer 8

Same name and namespace in other branches
  1. 2.x modules/warmer_entity/src/Plugin/warmer/EntityWarmer.php \Drupal\warmer_entity\Plugin\warmer\EntityWarmer::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

modules/warmer_entity/src/Plugin/warmer/EntityWarmer.php, line 164

Class

EntityWarmer
The cache warmer for the built-in entity cache.

Namespace

Drupal\warmer_entity\Plugin\warmer

Code

public function addMoreConfigurationFormElements(array $form, SubformStateInterface $form_state) {

  /** @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface $bundle_info */
  $bundle_info = \Drupal::service('entity_type.bundle.info');
  $options = [];
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type) {
    $bundles = $bundle_info
      ->getBundleInfo($entity_type
      ->id());
    $label = (string) $entity_type
      ->getLabel();
    $entity_type_id = $entity_type
      ->id();
    $options[$label] = [];
    foreach ($bundles as $bundle_id => $bundle_data) {
      $options[$label][sprintf('%s:%s', $entity_type_id, $bundle_id)] = $bundle_data['label'];
    }
  }
  $configuration = $this
    ->getConfiguration();
  $form['entity_types'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Entity Types'),
    '#description' => $this
      ->t('Enable the entity types to warm asynchronously.'),
    '#options' => $options,
    '#default_value' => empty($configuration['entity_types']) ? [] : $configuration['entity_types'],
    '#multiple' => TRUE,
    '#attributes' => [
      'style' => 'min-height: 60em;',
    ],
  ];
  return $form;
}