View source
<?php
$plugin = array(
'schema' => 'css_injector_rule',
'access' => 'administer css_injector',
'menu' => array(
'menu item' => 'css-injector',
'menu prefix' => 'admin/config/development',
'menu title' => 'CSS injector',
'menu description' => 'Settings for CSS injector rules. Allows for the insertion of arbitrary JavaScript on pages.',
),
'title singular' => t('rule'),
'title plural' => t('rules'),
'title singular proper' => t('CSS injector rule'),
'title plural proper' => t('CSS injector rules'),
'form' => array(
'settings' => 'css_injector_ctools_export_ui_form',
'validate' => 'css_injector_ctools_export_ui_form_validate',
'submit' => 'css_injector_ctools_export_ui_form_submit',
),
);
function css_injector_ctools_export_ui_form(&$form, &$form_state) {
$rule = $form_state['item'];
$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.');
$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['css'] = array(
'#type' => 'textarea',
'#title' => t('CSS code'),
'#description' => t('The actual CSS code goes in here.'),
'#rows' => 10,
'#default_value' => $rule->css,
'#required' => TRUE,
);
$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced options'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['advanced']['media'] = array(
'#type' => 'select',
'#title' => 'Media',
'#description' => t('Which media types is the CSS used.'),
'#options' => array(
'all' => t('All'),
'print' => t('Print'),
'screen' => t('Screen'),
),
'#default_value' => $rule->media,
);
$form['advanced']['preprocess'] = array(
'#type' => 'checkbox',
'#title' => t('Preprocess CSS'),
'#description' => t('If the CSS is preprocessed, and CSS 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['advanced']['inline'] = array(
'#type' => 'checkbox',
'#title' => t('Inline CSS'),
'#description' => t('The CSS file can also be inline on the page.'),
'#default_value' => $rule->inline,
'#states' => array(
'visible' => array(
'input[name="preprocess"]' => array(
'checked' => FALSE,
),
),
),
);
$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,
);
}
function css_injector_ctools_export_ui_form_validate($form, &$form_state) {
if ($form_state['values']['preprocess'] == 1) {
$form_state['values']['inline'] = 0;
}
if (preg_match('/[^A-Za-z0-9_\\-\\ ]+/', $form_state['values']['name'])) {
form_set_error('name', t('Illegal characters found in the friendly name, please remove them.'));
}
}
function css_injector_ctools_export_ui_form_submit($form, &$form_state) {
}