You are here

function acquia_purge_manualpurge_form_full in Acquia Purge 7

UX rich form that lets administrative users purge paths manually.

1 string reference to 'acquia_purge_manualpurge_form_full'
acquia_purge_menu in ./acquia_purge.module
Implements hook_menu().

File

./acquia_purge.admin.inc, line 89
Admin page callbacks and theme functions for the Acquia Purge module.

Code

function acquia_purge_manualpurge_form_full($form, &$form_state) {
  $service = _acquia_purge_service();
  $diagnostics = $service
    ->diagnostics();

  // Do not render the full form if error conditions are found.
  if ($diagnostics
    ->isSystemBlocked()) {
    include_once DRUPAL_ROOT . '/includes/install.inc';
    return array(
      'status' => array(
        '#type' => 'item',
        '#title' => t("We're sorry, but due to a critical error condition it is not possible to use this form. Please contact your administrator."),
        '#markup' => theme('status_report', array(
          'requirements' => $diagnostics
            ->get(ACQUIA_PURGE_SEVLEVEL_ERROR),
        )),
      ),
    );
  }

  // Retrieve the base form and register our validation and submit callbacks.
  _acquia_purge_manualpurge_base($form, $form_state);
  $form['#validate'] = array(
    '_acquia_purge_manualpurge_validate',
  );
  $form['#submit'] = array(
    '_acquia_purge_manualpurge_submit',
  );
  unset($form['submits']['page']);

  // Start adding on-screen documentation.
  $form['paths']['#prefix'] .= '<h3>' . t('Paths to be purged:') . '</h3>';
  $form['description'] = array(
    '#markup' => t('<p>This form allows you to purge one or more paths from your
    Acquia Cloud load balancers. This form is not intended for day-to-day use
    and only meant for site administrators, for instance in emergency cases when
    a outdated copy of a page remains being served. It is highly recommended to
    automate these purges using rules so editorial users can rely on a fully
    fresh site instead of relying on this form.</p>'),
  );

  // Define a list of example paths so users know what they can/should purge.
  $examples = array(
    '&lt;front&gt;',
    '&lt;front&gt;?page=0',
    '&lt;front&gt;/',
    'node/1',
    'node/1/',
    'news?page=0',
  );
  if (_acquia_purge_variable('acquia_purge_variations')) {
    $examples = array(
      '&lt;front&gt;',
      'node/1',
      'news',
    );
  }

  // Build up table rows with domains on the left and examples on the right.
  $domains = $service
    ->hostingInfo()
    ->getDomains();
  $rows = array();
  $rowsc = count($domains);
  if (count($examples) > count($domains)) {
    $rowsc = count($examples);
  }
  for ($i = 0; $i < $rowsc; $i++) {
    $row = array();
    $row[0] = isset($domains[$i]) ? $domains[$i] : '';
    $row[1] = isset($examples[$i]) ? $examples[$i] : '';
    $rows[] = $row;
  }
  $form['guidancetable'] = array(
    '#theme' => 'table',
    '#header' => array(
      t('Domains to purge paths on'),
      t('Example paths'),
    ),
    '#rows' => $rows,
    '#empty' => '',
  );

  // Decorate the textfields and prepend URL's as helpful guide.
  $schemes = $service
    ->hostingInfo()
    ->getSchemes();
  $base_path = _acquia_purge_variable('acquia_purge_base_path');
  $prefix = sprintf('<b>%s://%s%s</b>', $schemes[0], $domains[0], $base_path);
  foreach ($form['paths']['path'] as $i => $item) {
    $form['paths']['path'][$i]['#field_prefix'] = $prefix;
    $form['paths']['path'][$i]['#size'] = 30;
    $form['paths']['path'][$i]['#maxlength'] = 2000;
  }
  return $form;
}