You are here

public function CacheControlForm::buildForm in Akamai 8.3

Same name and namespace in other branches
  1. 8 lib/Drupal/akamai/Form/CacheControlForm.php \Drupal\akamai\Form\CacheControlForm::buildForm()
  2. 8.2 src/Form/CacheControlForm.php \Drupal\akamai\Form\CacheControlForm::buildForm()

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 FormInterface::buildForm

File

src/Form/CacheControlForm.php, line 74

Class

CacheControlForm
A simple form for testing the Akamai integration, or doing manual clears.

Namespace

Drupal\akamai\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('akamai.settings');
  $version = $this->akamaiClient
    ->getPluginId();
  $settings_link = Url::fromRoute('akamai.settings');
  $settings_link = Link::fromTextAndUrl($settings_link
    ->getInternalPath(), $settings_link)
    ->toString();
  $paths_description = $this
    ->t('Enter one URL or CPCode per line. URL entries should be relative to the basepath
      (e.g. node/1, content/pretty-title, sites/default/files/some/image.png).
      Your basepath for Akamai is set as :basepath. If you would like to change
      it, you can do so at @settings.', [
    ':basepath' => $config
      ->get('basepath'),
    '@settings' => $settings_link,
  ]);
  $form['paths'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Paths/URLs/CPCodes'),
    '#description' => $paths_description,
    '#required' => TRUE,
    '#default_value' => $form_state
      ->get('paths'),
  ];
  $domain_override_default = $form_state
    ->get('domain_override') ?: key(array_filter($config
    ->get('domain')));
  $form['domain_override'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Domain'),
    '#options' => [
      'production' => $this
        ->t('Production'),
      'staging' => $this
        ->t('Staging'),
    ],
    '#default_value' => $domain_override_default,
    '#description' => $this
      ->t('The Akamai domain to use for cache clearing.  Defaults to the Domain setting from the settings page.'),
  ];
  $action_default = $form_state
    ->get('action') ?: $config
    ->get("action_{$version}");
  $actions = $this->akamaiClient
    ->validActions();
  $form['action'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Clearing Action Type'),
    '#options' => array_combine($actions, array_map(function ($action) {
      return Unicode::ucwords($action);
    }, $actions)),
    '#default_value' => key(array_filter($action_default)),
    '#description' => $this
      ->t('<b>Remove:</b> Purge the content from Akamai edge server caches. The next time the edge server receives a request for the content, it will retrieve the current version from the origin server. If it cannot retrieve a current version, it will follow instructions in your edge server configuration.<br/><br/><b>Invalidate:</b> Mark the cached content as invalid. The next time the Akamai edge server receives a request for the content, it will send an HTTP conditional get (If-Modified-Since) request to the origin. If the content has changed, the origin server will return a full fresh copy; otherwise, the origin normally will respond that the content has not changed, and Akamai can serve the already-cached content.<br/><br/><b>Note that <em>Remove</em> can increase the load on the origin more than <em>Invalidate</em>.</b> With <em>Invalidate</em>, objects are not removed from cache and full objects are not retrieved from the origin unless they are newer than the cached versions.'),
  ];
  $form['method'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Purge Method'),
    '#options' => [
      'url' => $this
        ->t('URL'),
      'cpcode' => $this
        ->t('Content Provider Code'),
    ],
    '#default_value' => $form_state
      ->get('method') ?: 'url',
    '#description' => $this
      ->t('The Akamai API method to use for cache purge requests.'),
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Start Refreshing Content'),
  ];
  return $form;
}