Same name in other branches
  1. 5.0.x src/Form/OperationsForm.php \Drupal\advagg\Form\OperationsForm::buildForm()
  2. 6.0.x src/Form/OperationsForm.php \Drupal\advagg\Form\OperationsForm::buildForm()
  3. 8.x-2.x src/Form/OperationsForm.php \Drupal\advagg\Form\OperationsForm::buildForm()
  4. 8.x-4.x src/Form/OperationsForm.php \Drupal\advagg\Form\OperationsForm::buildForm()

File

src/Form/OperationsForm.php, line 125

Class

OperationsForm
Configure advagg settings for this site.

Namespace

Drupal\advagg\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    // Explain what can be done on this page.
    $form['tip'] = [
        '#markup' => '<p>' . $this->t('This is a collection of commands to control the cache and to manage testing of this module. In general this page is useful when troubleshooting some aggregation issues. For normal operations, you do not need to do anything on this page below the Smart Cache Flush. There are no configuration options here.') . '</p>',
    ];
    $form['wrapper'] = [
        '#prefix' => "<div id='operations-wrapper'>",
        '#suffix' => "</div>",
    ];
    // Set/Remove Bypass Cookie.
    $form['bypass'] = [
        '#type' => 'fieldset',
        '#title' => $this->t('Aggregation Bypass Cookie'),
        '#description' => $this->t('This will set or remove a cookie that disables aggregation for a set period of time.'),
    ];
    $form['bypass']['timespan'] = [
        '#type' => 'select',
        '#title' => $this->t('Bypass length'),
        '#options' => [
            21600 => $this->t('6 hours'),
            43200 => $this->t('12 hours'),
            86400 => $this->t('1 day'),
            172800 => $this->t('2 days'),
            604800 => $this->t('1 week'),
            2592000 => $this->t('1 month'),
            31536000 => $this->t('1 year'),
        ],
    ];
    $form['bypass']['submit'] = [
        '#type' => 'submit',
        '#value' => $this->t('Toggle The "aggregation bypass cookie" For This Browser'),
        '#attributes' => [
            'onclick' => 'javascript:return advagg_toggle_cookie()',
        ],
        '#submit' => [
            '::toggleBypassCookie',
        ],
    ];
    // Add in aggregation bypass cookie javascript.
    $form['#attached']['drupalSettings']['advagg'] = [
        'key' => Crypt::hashBase64($this->privateKey
            ->get()),
    ];
    $form['#attached']['library'][] = 'advagg/admin.operations';
    // Tasks run by cron.
    $form['cron'] = [
        '#type' => 'details',
        '#open' => TRUE,
        '#title' => $this->t('Cron Maintenance Tasks'),
        'description' => [
            '#markup' => $this->t('The following operation is ran on cron but you can run it manually here.'),
        ],
    ];
    $form['cron']['wrapper'] = [
        '#prefix' => "<div id='cron-wrapper'>",
        '#suffix' => "</div>",
    ];
    $form['cron']['smart_file_flush'] = [
        '#type' => 'fieldset',
        '#title' => $this->t('Clear Stale Files'),
        '#description' => $this->t('Scan all files in the css/js optimized directories and remove outdated ones.'),
    ];
    $form['cron']['smart_file_flush']['advagg_flush_stale_files'] = [
        '#type' => 'submit',
        '#value' => $this->t('Remove All Stale Files'),
        '#submit' => [
            '::clearStaleAggregates',
        ],
        '#ajax' => [
            'callback' => '::cronTasksAjax',
            'wrapper' => 'cron-wrapper',
        ],
    ];
    // Hide drastic measures as they should not be done unless really needed.
    $form['drastic_measures'] = [
        '#type' => 'details',
        '#title' => $this->t('Drastic Measures'),
        '#description' => $this->t('The options below should normally never need to be done.'),
    ];
    $form['drastic_measures']['wrapper'] = [
        '#prefix' => "<div id='drastic-measures-wrapper'>",
        '#suffix' => "</div>",
    ];
    $form['drastic_measures']['dumb_cache_flush'] = [
        '#type' => 'fieldset',
        '#title' => $this->t('Clear All Caches'),
        '#description' => $this->t('Remove all entries from the advagg cache and file information stores. Useful if you suspect a cache is not getting cleared.'),
    ];
    $form['drastic_measures']['dumb_cache_flush']['advagg_flush_all_caches'] = [
        '#type' => 'submit',
        '#value' => $this->t('Clear All Caches & File Information'),
        '#submit' => [
            '::clearAggregates',
        ],
        '#ajax' => [
            'callback' => '::drasticTasksAjax',
            'wrapper' => 'drastic-measures-wrapper',
        ],
    ];
    $form['drastic_measures']['force_change'] = [
        '#type' => 'fieldset',
        '#title' => $this->t('Force new files'),
        '#description' => $this->t('Force the creation of all new optimized files by incrementing a global counter. Current value of counter: %value. This is useful if a CDN has cached a file incorrectly as it will force new ones to be used even if nothing else has changed.', [
            '%value' => $this->config('advagg.settings')
                ->get('global_counter'),
        ]),
    ];
    $form['drastic_measures']['force_change']['increment_global_counter'] = [
        '#type' => 'submit',
        '#value' => $this->t('Increment Global Counter'),
        '#submit' => [
            '::incrementCounter',
        ],
        '#ajax' => [
            'callback' => '::drasticTasksAjax',
            'wrapper' => 'drastic-measures-wrapper',
        ],
    ];
    return parent::buildForm($form, $form_state);
}