You are here

public function PurgeOptionsForm::buildForm in Fastly 8.3

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/PurgeOptionsForm.php, line 83

Class

PurgeOptionsForm
Class PurgeOptionsForm.

Namespace

Drupal\fastly\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('fastly.settings');
  $key_length = (int) $config
    ->get('cache_tag_hash_length') ?: CacheTagsHashInterface::CACHE_TAG_HASH_LENGTH;
  $form['cache_tag_hash_length'] = [
    '#type' => 'number',
    '#min' => 4,
    '#max' => 10,
    '#title' => $this
      ->t('Cache tag hash length'),
    '#description' => $this
      ->t('For sites with more content, it may be necessary to increase the length of the hashed cache tags that are used for the <code>Surrogate-Key</code> header and when purging content. This is due to <a href=":hash_collisions">hash collisions</a> which will result in excessive purging of content if the key length is too short. The current key length of <strong>%key_length</strong> can provide %hash_total unique cache keys. Note that this number should not be as large as the total number of cache tags in your site, just high enough to avoid most collisions during purging. Also you can override this with environment variable <code>FASTLY_CACHE_TAG_HASH_LENGTH</code>.', [
      ':hash_collisions' => 'https://en.wikipedia.org/wiki/Hash_table#Collision_resolution',
      '%key_length' => $key_length,
      '%hash_total' => pow(64, $key_length),
    ]),
    '#default_value' => $key_length,
  ];
  $form['purge_method'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Purge method'),
    '#description' => $this
      ->t("Switch between Fastly's Instant-Purge and Soft-Purge methods."),
    '#default_value' => $config
      ->get('purge_method') ?: self::FASTLY_INSTANT_PURGE,
    '#options' => [
      self::FASTLY_INSTANT_PURGE => $this
        ->t('Use instant purge'),
      self::FASTLY_SOFT_PURGE => $this
        ->t('Use soft purge'),
    ],
  ];
  $form['purge_logging'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable logging for purges'),
    '#description' => $this
      ->t("Add a log entry whenever a purge is successful."),
    '#default_value' => $config
      ->get('purge_logging'),
  ];
  return parent::buildForm($form, $form_state);
}