You are here

function google_tag_settings_form in GoogleTagManager 7.2

Same name and namespace in other branches
  1. 7 includes/admin.inc \google_tag_settings_form()

Form constructor for the container form.

See also

google_tag_settings_form_validate()

google_tag_settings_form_submit()

1 string reference to 'google_tag_settings_form'
_google_tag_menu in includes/info.inc
Implements hook_menu().

File

includes/form/settings.inc, line 18
Contains the settings form callbacks.

Code

function google_tag_settings_form($form, &$form_state) {
  module_load_include('inc', 'google_tag', 'includes/variable');

  // module_load_include('inc', 'ctools', 'includes/export');
  // Gather data.
  // @todo Set this on validation errors.
  $default_tab = !empty($form_state['default_tab']) ? $form_state['default_tab'] : '';

  // @todo always add default keys in case of no update hook being run.
  $config = \GTMSettings::getInstance();
  $export_type = EXPORT_IN_DATABASE;
  if (empty($config
    ->get('uri'))) {

    // @todo This appears somewhat circular as variables_get() uses
    // \GTMSettings::getInstance() for default values but does appeal to the
    // variable definition if settings object does not exist.
    $config = (object) GTMContainerExport::variables_get(TRUE);
    $export_type = NULL;
  }
  $form_state['item'] = $config;

  // Build form elements.
  // Module settings.
  $description = t('<br />After configuring the module settings and default properties for a new container, <strong>add a container</strong> on the <a href="!url">container management page</a>.', array(
    '!url' => url('admin/config/system/google_tag'),
  ));
  $form['instruction'] = array(
    '#type' => 'markup',
    '#markup' => $description,
  );
  $groups = array(
    'settings' => array(
      'title' => t('Module settings'),
      'description' => t('The settings that apply to all containers.'),
      'collapse' => FALSE,
    ),
  );
  foreach ($groups as $group => $items) {
    $form['settings'] = google_tag_fieldset($group, $items, $form_state['item']);
  }

  // Default container settings.
  $text = t('The default container settings that apply to a new container.');
  $suffix = '<div id="edit-default--description" class="description">' . $text . '</div>';
  $groups = array(
    // 'general' => array('title' => t('General'), 'collapse' => FALSE),
    'advanced' => array(
      'title' => t('Advanced'),
    ),
  );
  $form['default'] = array(
    '#type' => 'vertical_tabs',
    '#attributes' => array(
      'class' => array(
        'google-tag',
      ),
    ),
    '#prefix' => '<strong>' . t('Default container settings') . '</strong>',
    '#suffix' => $suffix,
  );
  foreach ($groups as $group => $items) {
    $form['default'][$group] = google_tag_fieldset($group, $items, $form_state['item']);
  }

  // Default insertion condition.
  $description = t('On this and the following tabs, specify the conditions on which the GTM JavaScript snippet will either be inserted on or omitted from the page response, thereby enabling or disabling tracking and other analytics. All conditions must be satisfied for the snippet to be inserted. The snippet will be omitted if any condition is not met.');
  $text = t('The default snippet insertion conditions that apply to a new container.');
  $suffix = '<div id="edit-default--description" class="description">' . $text . '</div>';
  $groups = array(
    'path' => array(
      'title' => t('Request path'),
      'description' => $description,
    ),
    'role' => array(
      'title' => t('User role'),
    ),
    'status' => array(
      'title' => t('Response status'),
    ),
  );

  // Use prefix and suffix as title and description are not rendered.
  $form['conditions'] = array(
    '#type' => 'vertical_tabs',
    '#title' => t('Default insertion conditions'),
    '#description' => t('The default snippet insertion conditions that apply to a new container.'),
    '#default_tab' => $default_tab ? $default_tab : 'edit-path',
    '#attributes' => array(
      'class' => array(
        'google-tag',
      ),
    ),
    '#attached' => array(
      'css' => array(
        drupal_get_path('module', 'google_tag') . '/css/google_tag.admin.css',
      ),
      'js' => array(
        drupal_get_path('module', 'google_tag') . '/js/google_tag.admin.js',
      ),
    ),
    '#prefix' => '<strong>' . t('Default insertion conditions') . '</strong>',
    '#suffix' => $suffix,
  );
  foreach ($groups as $group => $items) {
    $form['conditions'][$group] = google_tag_fieldset($group, $items, $form_state['item']);
  }
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  $form['export_type'] = array(
    '#type' => 'value',
    '#value' => $export_type,
  );
  return $form;
}