You are here

function js_injector_ctools_export_ui_form in JS injector 7.2

Define the preset add/edit form.

1 string reference to 'js_injector_ctools_export_ui_form'
js_injector_ctools_export_ui.inc in plugins/export_ui/js_injector_ctools_export_ui.inc

File

plugins/export_ui/js_injector_ctools_export_ui.inc, line 35

Code

function js_injector_ctools_export_ui_form(&$form, &$form_state) {
  $rule = $form_state['item'];

  // Alter the name field (this is set by the default export_ui class).
  $form['info']['name']['#title'] = t('Friendly name');
  $form['info']['name']['#description'] = t('This is the unique ID for this rule. Only alphanumeric characters, spaces, underscores and dashes are allowed.');

  // Alter the admin_description field (this is set by the default export_ui
  // class).
  $form['info']['admin_description']['#title'] = t('Description');
  $form['info']['admin_description']['#type'] = 'textfield';
  $form['info']['admin_description']['#description'] = t('The human readable description of this rule.');
  $form['info']['admin_description']['#required'] = TRUE;
  $form['js'] = array(
    '#type' => 'textarea',
    '#title' => t('JS code'),
    '#description' => t('The actual JavaScript code goes in here. There is no need to insert the <script> tags.'),
    '#rows' => 10,
    '#default_value' => $rule->js,
    '#required' => TRUE,
  );

  // placement options fieldset
  $form['placement'] = array(
    '#type' => 'fieldset',
    '#title' => t('Placement options'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['placement']['position'] = array(
    '#type' => 'select',
    '#title' => 'Position of the javascipt',
    '#description' => t('Where in the HTML will the JavaScript be placed.'),
    '#options' => array(
      'header' => t('Header'),
      'footer' => t('Footer'),
    ),
    '#default_value' => $rule->position,
  );
  $form['placement']['preprocess'] = array(
    '#type' => 'checkbox',
    '#title' => t('Preprocess JS'),
    '#description' => t('If the JavaScript is preprocessed, and JavaScript aggregation is enabled, the script file will be aggregated. Warning - this means you will require a theme cache clear in order to regenerate new aggregate files.'),
    '#default_value' => $rule->preprocess,
  );
  $form['placement']['inline'] = array(
    '#type' => 'checkbox',
    '#title' => t('Inline JS'),
    '#description' => t('The JavaScript file can also be inline on the page.'),
    '#default_value' => $rule->inline,
    '#states' => array(
      'visible' => array(
        'input[name="preprocess"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );

  // Region settings.
  $form['noscript'] = array(
    '#type' => 'fieldset',
    '#title' => t('Noscript settings'),
    '#collapsible' => FALSE,
    '#description' => t('Optionally inject code into a noscript tag.'),
    '#tree' => TRUE,
  );

  // copied from block config, only difference is that we list all regions, not just visible
  $form['noscript']['regions'] = array(
    '#type' => 'fieldset',
    '#title' => t('Region settings'),
    '#collapsible' => FALSE,
    '#description' => t('Specify in which themes and regions the noscript tag is injected. In most cases using the <em>Page bottom (default)</em> is recommended. In case this does not work with your theme you can select a different region'),
    '#tree' => TRUE,
  );
  $theme_default = variable_get('theme_default', 'bartik');
  $admin_theme = variable_get('admin_theme');
  $default_regions = array(
    'page_top' => t('Page top (default)'),
    'header' => t('Header (default)'),
    'sidebar_first' => t('Sidebar first (default)'),
    'content' => t('Content (default)'),
    'sidebar_second' => t('Sidebar second (default)'),
    'page_bottom' => t('Page bottom (default)'),
  );
  foreach (list_themes() as $key => $theme) {

    // Only display enabled themes
    if ($theme->status || $key == $theme_default || $key == $admin_theme) {

      // Use a meaningful title for the main site theme and administrative
      // theme.
      $theme_title = $theme->info['name'];
      if ($key == $theme_default) {
        $theme_title = t('!theme (default theme)', array(
          '!theme' => $theme_title,
        ));
      }
      elseif ($admin_theme && $key == $admin_theme) {
        $theme_title = t('!theme (administration theme)', array(
          '!theme' => $theme_title,
        ));
      }
      $region = isset($rule->noscript_regions, $rule->noscript_regions[$key]) && $rule->noscript_regions[$key] != -1 ? $rule->noscript_regions[$key] : NULL;
      $form['noscript']['regions'][$key] = array(
        '#type' => 'select',
        '#title' => $theme_title,
        '#default_value' => $region,
        '#empty_value' => BLOCK_REGION_NONE,
        '#options' => $default_regions + system_region_list($key),
        '#weight' => $key == $theme_default ? 9 : 10,
      );
    }
  }
  $form['noscript']['noscript'] = array(
    '#type' => 'textarea',
    '#title' => t('Noscript code'),
    '#description' => t('The noscript code goes in here. There is no need to insert the &lt;noscript&gt; tags.'),
    '#rows' => 10,
    '#default_value' => $rule->noscript,
  );

  // page visibility fieldset. Code ported from googleanalytics.module
  $form['pages'] = array(
    '#type' => 'fieldset',
    '#title' => t('Pages'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $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-wildcard for every personal blog. %front is the front page.", array(
    '%blog' => 'blog',
    '%blog-wildcard' => 'blog/*',
    '%front' => '<front>',
  ));
  $options = array(
    0 => t('Every page except the listed pages'),
    1 => t('The listed pages only'),
  );
  if (module_exists('php') && user_access('use PHP for settings')) {
    $options[] = t('Pages on which this PHP code returns <code>TRUE</code> (experts only)');
    $title = t('Pages or PHP code');
    $description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. Note that executing incorrect PHP code can break your Drupal site.', array(
      '%php' => '<?php ?>',
    ));
  }
  $form['pages']['page_visibility'] = array(
    '#type' => 'radios',
    '#title' => t('Add tracking to specific pages'),
    '#options' => $options,
    '#default_value' => $rule->page_visibility,
  );
  $form['pages']['page_visibility_pages'] = array(
    '#type' => 'textarea',
    '#title' => $title,
    '#title_display' => 'invisible',
    '#default_value' => $rule->page_visibility_pages,
    '#description' => $description,
    '#rows' => 10,
  );
}