You are here

function themekey_abstract_rule_chain_form in ThemeKey 7.3

3 calls to themekey_abstract_rule_chain_form()
themekey_css_rule_chain_form in themekey_css/themekey_css_admin.inc
Form builder for the rule chain.
themekey_redirect_rule_chain_form in themekey_redirect/themekey_redirect_admin.inc
Form builder for the rule chain.
themekey_rule_chain_form in ./themekey_admin.inc
Form builder for the rule chain.

File

./themekey_admin.inc, line 39

Code

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

    // first call of this form ever
    themekey_rebuild();
    $properties = variable_get('themekey_properties', array());
  }
  $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 = $options['load_rules_callback']();
  }
  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' => $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' => 200,
      '#default_value' => $item['weight'],
    );
    $form['old_items'][$item['id']]['delete'] = array(
      '#markup' => $static ? '' : l(t('delete'), $options['rule_delete_path'] . $item['id']),
    );
    $form['old_items'][$item['id']]['module'] = array(
      '#type' => 'hidden',
      '#default_value' => $item['module'],
    );

    // Extend form with [old_items] additional fields.
    if (isset($options['additional_fields'])) {
      foreach ($options['additional_fields'] as $field_name => $field_definition) {
        $form['old_items'][$item['id']][$field_name] = $field_definition;
        $form['old_items'][$item['id']][$field_name]['#default_value'] = $item[$field_name];
      }
    }
  }
  $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']) ? html_entity_decode(filter_xss($_GET['value'])) : '',
    '#size' => 25,
    '#maxlength' => 255,
  );
  $form['new_item']['theme'] = array(
    '#type' => 'select',
    '#default_value' => 'default',
    '#options' => $options['themes'],
  );
  $form['new_item']['enabled'] = array(
    '#type' => 'checkbox',
    '#default_value' => TRUE,
  );
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );

  // Extend form with [new_item] additional fields.
  if (isset($options['additional_fields'])) {
    foreach ($options['additional_fields'] as $field_name => $field_definition) {
      $form['new_item'][$field_name] = $field_definition;
    }
  }
  return $form;
}