You are here

function tracking_code_edit_form in Tracking Code 7

Form for editing codeblocks (admin/structure/tracking_code/%/edit).

Parameters

(int) $delta: the array index of the codeblock to edit

Return value

array a renderable Form API array

1 string reference to 'tracking_code_edit_form'
tracking_code_menu in ./tracking_code.module
Implements hook_menu().

File

./tracking_code.admin.inc, line 202
admin page callbacks and form handlers for the tracking code module

Code

function tracking_code_edit_form($form, &$form_state, $delta) {
  _tracking_code_set_breadcrumb();
  $snippet = _tracking_code_read($delta);

  // Don't show a blank edit form.
  if (!$snippet) {
    drupal_not_found();
    exit;
  }
  $form['delta'] = array(
    '#type' => 'hidden',
    '#value' => $delta,
  );
  $form['tracking_code_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#description' => t('Enter a name to describe this code block'),
    '#default_value' => $snippet['name'],
  );
  $form['tracking_code_status'] = array(
    '#type' => 'radios',
    '#title' => t('Enable Tracking Code'),
    '#description' => t("Tracking code snippets are disabled by default, so you won't accidentally make tracking code live if you didn't intend to."),
    '#default_value' => $snippet['status'],
    '#options' => array(
      1 => t('Active'),
      0 => t('Disabled'),
    ),
  );
  $form['tracking_code_code'] = array(
    '#type' => 'textarea',
    '#title' => t('Code'),
    '#description' => t('Enter your tracking code snippet here'),
    '#default_value' => $snippet['code'],
  );
  if (module_exists('token')) {
    $form['tokens'] = array(
      '#theme' => 'token_tree',
      '#token_types' => array(
        'node',
      ),
      '#global_types' => TRUE,
      '#click_insert' => TRUE,
    );
  }
  $form['tracking_code_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Visibility Settings'),
    '#collapsible' => TRUE,
  );
  $form['tracking_code_options']['tracking_code_region'] = array(
    '#type' => 'radios',
    '#title' => t('Render this code:'),
    '#options' => array(
      'header' => t('Inside <HEAD>'),
      'page_top' => t('After <BODY>'),
      'page_bottom' => t('Before </BODY>'),
    ),
    '#default_value' => $snippet['region'],
  );
  $form['tracking_code_options']['tracking_code_visibility'] = array(
    '#type' => 'radios',
    '#title' => t('Invoke this tracking code on specific pages:'),
    '#options' => array(
      TRACKING_CODE_VISIBILITY_NOTLISTED => t('All pages except those listed'),
      TRACKING_CODE_VISIBILITY_LISTED => t('Only the listed pages'),
    ),
    '#default_value' => $snippet['visibility'],
  );
  $form['tracking_code_options']['tracking_code_pages'] = array(
    '#type' => 'textarea',
    '#title' => t('Pages'),
    '#description' => t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are blog for the blog page and blog/* for every personal blog. <front> is the front page."),
    '#default_value' => $snippet['pages'],
  );
  $form['tracking_code_options']['tracking_code_content_types'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Content Types'),
    '#options' => node_type_get_names(),
    '#default_value' => unserialize($snippet['content_types']),
    '#description' => t('Show this tracking code only on pages that display content of the given type(s). If you select no types, there will be no type-specific limitation.'),
  );
  $form['tracking_code_options']['tracking_code_roles'] = array(
    '#type' => 'checkboxes',
    '#title' => t('User Roles'),
    '#options' => user_roles(),
    '#description' => t('Show this tracking code only to users of a specific Drupal role. If you select no roles, this snippet will be shown for all roles.'),
  );
  if (isset($snippet['roles'])) {
    $form['tracking_code_options']['tracking_code_roles']['#default_value'] = unserialize($snippet['roles']);
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save Snippet'),
  );
  return $form;
}