You are here

function cacheflush_cron_form_cacheflush_form_alter in CacheFlush 7.3

Implements hook_form_FORM_ID_alter().

File

modules/cacheflush_cron/cacheflush_cron.module, line 13
Cacheflush cron job.

Code

function cacheflush_cron_form_cacheflush_form_alter(&$form, &$form_state) {

  // Cron fieldset.
  $form['cron_fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Cron'),
    '#weight' => 2,
  );

  // Set cron checkbox.
  $form['cron_fieldset']['cacheflush_cron_sett'] = array(
    '#type' => "checkbox",
    '#title' => t('Cron job'),
    '#weight' => 1,
    '#default_value' => isset($form_state['cacheflush']->cron) && $form_state['cacheflush']->cron ? 1 : 0,
    '#description' => t('Enable cron job for this preset.'),
  );
  if (isset($form_state['cacheflush']->cron_rule) && $form_state['cacheflush']->cron_rule) {

    // Cron Settings Page link container.
    $form['cron_fieldset']['cacheflush_cron_link'] = array(
      '#type' => 'container',
      '#weight' => 3,
      '#states' => array(
        'invisible' => array(
          ':input[name="cacheflush_cron_sett"]' => array(
            'checked' => FALSE,
          ),
        ),
      ),
    );

    // Cron Settings Page link.
    $form['cron_fieldset']['cacheflush_cron_link']['markup'] = array(
      '#markup' => l(t('Cron Settings'), 'admin/config/system/cron'),
    );
  }
  else {

    // Cron rule.
    $form['cron_fieldset']['cacheflush_cron_rule'] = array(
      '#type' => "textfield",
      '#title' => t('Cron job rule'),
      '#weight' => 2,
      '#default_value' => isset($form_state['cacheflush']->cron_rule) && $form_state['cacheflush']->cron_rule ? $form_state['cacheflush']->cron_rule : '* * * * *',
      '#description' => t('Cron job rule example ("*/5 * * * *") // Every 5 minutes.'),
      '#states' => array(
        'invisible' => array(
          ':input[name="cacheflush_cron_sett"]' => array(
            'checked' => FALSE,
          ),
        ),
      ),
    );
  }
  $form['#validate'][] = 'cacheflush_cron_validate';
}