You are here

function css_injector_edit in CSS Injector 7.2

Same name and namespace in other branches
  1. 6 css_injector.admin.inc \css_injector_edit()
  2. 7 css_injector.admin.inc \css_injector_edit()

Form builder function for the CSS rule edit form.

File

./css_injector.admin.inc, line 100
css_injector.admin.inc Administrative interface for CSS Injector.

Code

function css_injector_edit($form, $form_state, $crid = NULL) {
  if (isset($crid)) {
    $rule = _css_injector_load_rule($crid, TRUE);
    $path = _css_injector_rule_path($rule['crid']);
    if (file_exists($path)) {
      $rule['css_text'] = file_get_contents($path);
    }
    else {
      $rule['css_text'] = '';
    }
  }
  else {
    $rule = array(
      'title' => '',
      'rule_type' => css_injector_PAGES_NOTLISTED,
      'rule_conditions' => '',
      'media' => 'all',
      'preprocess' => 1,
      'css_text' => '',
    );
  }
  if (isset($crid)) {
    $form['crid'] = array(
      '#type' => 'value',
      '#value' => $crid,
    );
  }
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => $rule['title'],
    '#required' => TRUE,
  );
  $form['css_text'] = array(
    '#type' => 'textarea',
    '#title' => t('CSS code'),
    '#rows' => 10,
    '#default_value' => $rule['css_text'],
    '#required' => TRUE,
  );

  // Shamelessly ripped from block.module. Who doesn't use this snippet
  // of code, really?
  $php_access = user_access('use PHP for settings') && module_exists('php');
  $options = array(
    css_injector_PAGES_NOTLISTED => t('Add on every page except the listed pages.'),
    css_injector_PAGES_LISTED => t('Add on only the listed pages.'),
  );
  $description = t("Enter one page per line as Drupal paths. 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>',
  ));
  if ($php_access) {
    $options[css_injector_PHP] = t('Add if the following PHP code outputs a nonzero value (PHP-mode, experts only).');
    $description .= ' ' . t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array(
      '%php' => '<?php ?>',
    ));
  }
  $form['conditional']['rule_type'] = array(
    '#type' => 'radios',
    '#title' => t('Add the CSS on specific pages'),
    '#options' => $options,
    '#default_value' => $rule['rule_type'],
  );
  $form['conditional']['rule_conditions'] = array(
    '#type' => 'textarea',
    '#title' => t('Pages'),
    '#default_value' => $rule['rule_conditions'],
    '#description' => $description,
  );
  $form['media'] = array(
    '#type' => 'select',
    '#title' => t('Media'),
    '#options' => array(
      'all' => t('All'),
      'screen' => t('Screen'),
      'print' => t('Print'),
    ),
    '#default_value' => $rule['media'],
  );
  $form['preprocess'] = array(
    '#type' => 'checkbox',
    '#title' => t('Preprocess CSS'),
    '#default_value' => $rule['preprocess'],
  );
  $form['buttons']['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#submit' => array(
      'css_injector_edit_save',
    ),
  );
  $form['buttons']['save_and_continue'] = array(
    '#type' => 'submit',
    '#value' => t('Save and Continue Editing'),
    '#submit' => array(
      'css_injector_edit_save_and_continue',
    ),
  );
  if (!empty($rule['crid'])) {
    $form['buttons']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      '#crid' => $rule['crid'],
      '#submit' => array(
        'css_injector_admin_delete_button',
      ),
    );
  }
  return $form;
}