You are here

function themekey_rule_chain_form in ThemeKey 7

Same name and namespace in other branches
  1. 6.4 themekey_admin.inc \themekey_rule_chain_form()
  2. 6.2 themekey_admin.inc \themekey_rule_chain_form()
  3. 6.3 themekey_admin.inc \themekey_rule_chain_form()
  4. 7.3 themekey_admin.inc \themekey_rule_chain_form()
  5. 7.2 themekey_admin.inc \themekey_rule_chain_form()

Form builder for the rule chain.

The form will not be validated. All changes will be saved immediately. Validation will happen when the form displays the stored configuration. Otherwise all the drag'n'drop stuff will not work.

See also

themekey_form_alter()

themekey_rule_chain_form_submit()

themekey_rule_chain_form_set_error()

1 string reference to 'themekey_rule_chain_form'
themekey_menu in ./themekey.module
Implements hook_menu().

File

./themekey_admin.inc, line 31

Code

function themekey_rule_chain_form($form, &$form_state) {
  $properties = variable_get('themekey_properties', array());
  if (empty($properties)) {

    // first call of this form ever
    themekey_rebuild();
    $properties = variable_get('themekey_properties', array());
  }
  $themes = themekey_theme_options(TRUE, TRUE);
  $attributes = variable_get('themekey_attributes', array());
  $operators = array(
    '=' => '=',
    '!' => '!',
    '*' => '*',
    '!*' => '!*',
    '<' => '<',
    '<=' => '<=',
    '>' => '>',
    '>=' => '>=',
    '~' => '~',
    '!~' => '!~',
  );
  $form = array(
    '#tree' => TRUE,
  );
  $items = array();
  $fix_depth = FALSE;
  if (empty($form_state['input']['old_items'])) {
    $items = themekey_load_rules();
  }
  else {
    $items = $form_state['input']['old_items'];
    $fix_depth = TRUE;
  }
  $parent_options = array_merge(array(
    0,
  ), array_keys($items));
  $parent_options = array_combine($parent_options, $parent_options);
  foreach ($items as $item) {
    if ($fix_depth) {
      if (!empty($item['parent'])) {
        $item['depth'] = $items[$item['parent']]['depth'] + 1;
      }
      else {
        $item['depth'] = 0;
      }
    }
    $form['old_items'][$item['id']]['depth'] = array(
      '#type' => 'hidden',
      '#value' => $item['depth'],
    );
    $form['old_items'][$item['id']]['id'] = array(
      '#type' => 'hidden',
      '#value' => $item['id'],
    );
    $property = $item['property'];
    $wildcard = '';
    $static = FALSE;
    if (!in_array($property, $properties)) {
      if (!empty($attributes[$property]['static'])) {
        $static = TRUE;
        $form['old_items'][$item['id']]['property'] = array(
          '#type' => 'hidden',
          '#default_value' => $property,
          '#value' => $property,
          '#prefix' => '<span class="themekey-fadeable">' . $property . '</span>',
        );
        $form['old_items'][$item['id']]['operator'] = array(
          '#type' => 'hidden',
          '#default_value' => '=',
          '#value' => '=',
        );
        $form['old_items'][$item['id']]['value'] = array(
          '#type' => 'hidden',
          '#default_value' => 'static',
          '#value' => 'static',
        );
        $form['old_items'][$item['id']]['theme'] = array(
          '#type' => 'select',
          '#default_value' => 'default',
          '#options' => array(
            'default' => t('Triggered'),
          ),
        );
      }
      else {
        $property = 'drupal:path:wildcard';
        $wildcard = $item['property'];
      }
    }
    if (!isset($form['old_items'][$item['id']]['property'])) {
      $form['old_items'][$item['id']]['property'] = array(
        '#type' => 'select',
        '#default_value' => $property,
        '#options' => $properties,
      );
    }
    $form['old_items'][$item['id']]['wildcard'] = array(
      '#type' => 'textfield',
      '#default_value' => $wildcard,
      '#size' => 10,
      '#maxlength' => 255,
    );
    if (!isset($form['old_items'][$item['id']]['operator'])) {
      $form['old_items'][$item['id']]['operator'] = array(
        '#type' => 'select',
        '#default_value' => $item['operator'],
        '#options' => $operators,
      );
    }
    if (!isset($form['old_items'][$item['id']]['value'])) {
      $form['old_items'][$item['id']]['value'] = array(
        '#type' => 'textfield',
        '#default_value' => $item['value'],
        '#size' => 20,
        '#maxlength' => 255,
      );
    }
    $form['old_items'][$item['id']]['parent'] = array(
      '#type' => 'select',
      '#default_value' => $item['parent'],
      '#options' => $parent_options,
    );
    if (!isset($form['old_items'][$item['id']]['theme'])) {
      $form['old_items'][$item['id']]['theme'] = array(
        '#type' => 'select',
        '#default_value' => $item['theme'],
        '#options' => $themes,
      );
    }
    $form['old_items'][$item['id']]['enabled'] = array(
      '#type' => 'checkbox',
      '#default_value' => isset($item['enabled']) ? $item['enabled'] : FALSE,
    );
    $form['old_items'][$item['id']]['weight'] = array(
      '#type' => 'weight',
      '#delta' => 50,
      '#default_value' => $item['weight'],
    );
    $form['old_items'][$item['id']]['delete'] = array(
      '#markup' => $static ? '' : l(t('delete'), 'admin/config/user-interface/themekey/properties/delete/' . $item['id']),
    );
  }
  $form['new_item']['property'] = array(
    '#type' => 'select',
    '#default_value' => !empty($_GET['property']) ? check_plain($_GET['property']) : '',
    '#options' => $properties,
  );
  $form['new_item']['wildcard'] = array(
    '#type' => 'textfield',
    '#default_value' => '',
    '#size' => 10,
    '#maxlength' => 255,
  );
  $form['new_item']['operator'] = array(
    '#type' => 'select',
    '#default_value' => '=',
    '#options' => $operators,
  );
  $form['new_item']['value'] = array(
    '#type' => 'textfield',
    '#default_value' => !empty($_GET['value']) ? check_plain($_GET['value']) : '',
    '#size' => 25,
    '#maxlength' => 255,
  );
  $form['new_item']['theme'] = array(
    '#type' => 'select',
    '#default_value' => 'default',
    '#options' => $themes,
  );
  $form['new_item']['enabled'] = array(
    '#type' => 'checkbox',
    '#default_value' => TRUE,
  );
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}