File
  - 
              src/Form/OperationsForm.php, line 123
    
   
Class
  
  
    - OperationsForm
- Configure advagg settings for this site.
Namespace
  Drupal\advagg\Form
Code
public function buildForm(array $form, FormStateInterface $form_state) {
    $form = [];
    
    $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>",
    ];
    
    
    $form['smart_flush'] = [
        '#type' => 'fieldset',
        '#title' => $this->t('Smart Cache Flush'),
        '#description' => $this->t('Scan all files referenced in aggregated files. If any of them have changed, clear that cache so the changes will go out.'),
    ];
    $form['smart_flush']['advagg_flush'] = [
        '#type' => 'submit',
        '#value' => $this->t('Flush AdvAgg Cache'),
        '#submit' => [
            '::flushCache',
        ],
        '#ajax' => [
            'callback' => '::tasksAjax',
            'wrapper' => 'operations-wrapper',
        ],
    ];
    
    $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' => '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',
        ],
    ];
    
    $form['#attached']['drupalSettings']['advagg'] = [
        'key' => Crypt::hashBase64($this->privateKey
            ->get()),
    ];
    $form['#attached']['library'][] = 'advagg/admin.operations';
    
    $form['cron'] = [
        '#type' => 'fieldset',
        '#title' => $this->t('Cron Maintenance Tasks'),
        'description' => [
            '#markup' => $this->t('The following 3 operations are ran on cron but you can run them manually here.'),
        ],
    ];
    $form['cron']['wrapper'] = [
        '#prefix' => "<div id='cron-wrapper'>",
        '#suffix' => "</div>",
    ];
    $form['cron']['smart_file_flush'] = [
        '#type' => 'details',
        '#title' => $this->t('Clear All Stale Files'),
        '#description' => $this->t('Remove all stale files. Scan all files in the advagg_css/js directories and remove the ones that have not been accessed in the last 30 days.'),
    ];
    $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',
        ],
    ];
    $form['cron']['remove_missing_files'] = [
        '#type' => 'details',
        '#title' => $this->t('Clear Missing Files From Database'),
        '#description' => $this->t('Scan for missing files and remove the associated entries from the database.'),
    ];
    $form['cron']['remove_missing_files']['advagg_remove_missing_files_from_db'] = [
        '#type' => 'submit',
        '#value' => $this->t('Clear Missing Files From Database'),
        '#submit' => [
            '::clearMissingFiles',
        ],
        '#ajax' => [
            'callback' => '::cronTasksAjax',
            'wrapper' => 'cron-wrapper',
        ],
    ];
    $form['cron']['remove_old_aggregates'] = [
        '#type' => 'details',
        '#title' => $this->t('Delete Unused Aggregates From Database'),
        '#description' => $this->t('Delete aggregates that have not been accessed in the last 6 weeks.'),
    ];
    $form['cron']['remove_old_aggregates']['advagg_remove_old_unused_aggregates'] = [
        '#type' => 'submit',
        '#value' => $this->t('Delete Unused Aggregates From Database'),
        '#submit' => [
            '::clearOldUnusedAggregates',
        ],
        '#ajax' => [
            'callback' => '::cronTasksAjax',
            'wrapper' => 'cron-wrapper',
        ],
    ];
    
    $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' => 'details',
        '#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' => [
            '::clearAll',
        ],
        '#ajax' => [
            'callback' => '::drasticTasksAjax',
            'wrapper' => 'drastic-measures-wrapper',
        ],
    ];
    $form['drastic_measures']['dumb_file_flush'] = [
        '#type' => 'details',
        '#title' => $this->t('Clear All Files'),
        '#description' => $this->t('Remove all generated files. Useful if you think some of the generated files got corrupted and thus need to be deleted.'),
    ];
    $form['drastic_measures']['dumb_file_flush']['advagg_flush_all_files'] = [
        '#type' => 'submit',
        '#value' => $this->t('Remove All Generated Files'),
        '#submit' => [
            '::clearAggregates',
        ],
        '#ajax' => [
            'callback' => '::drasticTasksAjax',
            'wrapper' => 'drastic-measures-wrapper',
        ],
    ];
    $form['drastic_measures']['force_change'] = [
        '#type' => 'details',
        '#title' => $this->t('Force new aggregates'),
        '#description' => $this->t('Force the creation of all new aggregates by incrementing a global counter. Current value of counter: %value. This is useful if a CDN has cached an aggregate incorrectly as it will force new ones to be used even if nothing else has changed.', [
            '%value' => advagg_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);
}