You are here

function acquia_spi_form_acquia_agent_settings_form_alter in Acquia Connector 7.3

Same name and namespace in other branches
  1. 6.2 acquia_spi/acquia_spi.module \acquia_spi_form_acquia_agent_settings_form_alter()
  2. 6 acquia_spi/acquia_spi.module \acquia_spi_form_acquia_agent_settings_form_alter()
  3. 7 acquia_spi/acquia_spi.module \acquia_spi_form_acquia_agent_settings_form_alter()
  4. 7.2 acquia_spi/acquia_spi.module \acquia_spi_form_acquia_agent_settings_form_alter()

Implements hook_form_FORM_ID_alter().

File

acquia_spi/acquia_spi.module, line 188
Send site profile information (NSPI) and system data to Acquia Insight.

Code

function acquia_spi_form_acquia_agent_settings_form_alter(&$form) {
  $identifier = acquia_agent_settings('acquia_identifier');
  $key = acquia_agent_settings('acquia_key');
  $acquia_hosted = acquia_spi_check_acquia_hosted();
  if (empty($identifier) && empty($key)) {
    return;
  }

  // Help documentation is local unless the Help module is disabled.
  if (module_exists('help')) {
    $help_url = url('admin/help/acquia_agent');
  }
  else {
    $help_url = url('https://docs.acquia.com/acquia-cloud/insight/install/');
  }
  $ssl_available = in_array('ssl', stream_get_transports(), TRUE) && !defined('ACQUIA_DEVELOPMENT_NOSSL');
  $form['identification']['site'] = array(
    '#prefix' => '<div class="acquia-identification">',
    '#suffix' => '</div>',
    '#weight' => -2,
  );
  $form['identification']['#description'] = t('Provide a name for this site to uniquely identify it on Acquia Cloud.');

  // If the site is acquia hosted and doesn't have a name or machine name yet,
  // ask the user to provide them.
  if (!$acquia_hosted && (!variable_get('acquia_spi_site_machine_name') || !variable_get('acquia_spi_site_name'))) {
    $form['identification']['site']['explanation'] = array(
      '#markup' => t('<p><strong>Please note</strong>: Your site is not sending SPI data to Acquia, as it does not appear that this Drupal install is hosted on Acquia servers. If you wish to send SPI data to Acquia for this Drupal install, please provide a name for your site below. If you do not wish to send SPI data to Acquia for this Drupal install, no further action is necessary.</p>'),
    );
  }
  $form['identification']['site']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#maxlength' => 255,
    '#required' => TRUE,
    '#default_value' => variable_get('acquia_spi_site_name') ?: acquia_spi_get_acquia_hosted_name(),
  );
  if ($acquia_hosted) {
    $form['identification']['#description'] = t('Acquia hosted sites are automatically provided with a machine name.');
  }
  $form['identification']['site']['machine_name'] = array(
    '#type' => 'machine_name',
    '#title' => t('Machine name'),
    '#maxlength' => 255,
    '#required' => TRUE,
    '#machine_name' => array(
      'exists' => 'taxonomy_vocabulary_machine_name_load',
      'source' => array(
        'identification',
        'site',
        'name',
      ),
    ),
  );
  if ($acquia_hosted) {
    $form['identification']['site']['machine_name']['#default_value'] = variable_get('acquia_spi_site_machine_name') ?: acquia_spi_get_acquia_hosted_machine_name();
    $form['identification']['site']['machine_name']['#disabled'] = TRUE;
  }
  else {
    $form['identification']['site']['machine_name']['#default_value'] = variable_get('acquia_spi_site_machine_name');
  }
  $form['connection']['#description'] = t('Allow collection and examination of the following items. <a href="!url">Learn more</a>.', array(
    '!url' => $help_url,
  ));
  $form['connection']['spi'] = array(
    '#prefix' => '<div class="acquia-spi">',
    '#suffix' => '</div>',
    '#weight' => -1,
  );
  $form['connection']['spi']['admin_priv'] = array(
    '#type' => 'checkbox',
    '#title' => t('Admin privileges'),
    '#default_value' => variable_get('acquia_spi_admin_priv', 1),
  );
  $form['connection']['spi']['send_node_user'] = array(
    '#type' => 'checkbox',
    '#title' => t('Nodes and users'),
    '#default_value' => variable_get('acquia_spi_send_node_user', 1),
  );
  $form['connection']['spi']['send_watchdog'] = array(
    '#type' => 'checkbox',
    '#title' => t('Watchdog logs'),
    '#default_value' => variable_get('acquia_spi_send_watchdog', 1),
  );
  $form['connection']['alter_variables'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow Insight to update list of approved variables.'),
    '#default_value' => (int) variable_get('acquia_spi_set_variables_override', 0),
    '#description' => t('Insight can set variables on your site to recommended values at your approval, but only from a specific list of variables. Check this box to allow Insight to update the list of approved variables. <a href="!url">Learn more</a>.', array(
      '!url' => $help_url,
    )),
  );
  $use_cron = variable_get('acquia_spi_use_cron', 1);
  $form['connection']['spi_use_cron'] = array(
    '#type' => 'checkbox',
    '#title' => t('Send via Drupal cron'),
    '#default_value' => $use_cron,
  );
  $key = sha1(drupal_get_private_key());
  $url = url('system/acquia-spi-send', array(
    'query' => array(
      'key' => $key,
    ),
    'absolute' => TRUE,
  ));
  $form['connection']['spi_use_cron_url'] = array(
    '#type' => 'container',
    '#children' => t("<p>Enter the following URL in your server's crontab to send SPI data:<br/><em>!url</em></p>", array(
      '!url' => $url,
    )),
    '#states' => array(
      'visible' => array(
        ':input[name="spi_use_cron"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );
  if ($use_cron) {

    // If using cron hide the URL container with #states visible.
    $form['connection']['spi_use_cron_url']['#states'] = array(
      'visible' => array(
        ':input[name="spi_use_cron"]' => array(
          'checked' => FALSE,
        ),
      ),
    );
  }
  $form['actions']['submit']['#submit'][] = 'acquia_agent_spi_set_submit';
}