You are here

function _themekey_properties_form in ThemeKey 6

Function _themekey_properties_form().

1 string reference to '_themekey_properties_form'
themekey_menu in ./themekey.module
Implementation of hook_menu().

File

./themekey_admin.inc, line 120

Code

function _themekey_properties_form() {
  $form['properties'] = array(
    '#type' => 'fieldset',
    '#title' => t('Properties'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#description' => t('Here you can map themes to object properties, e.g. to node properties such as the NodeID (nid).
                         To add a new map entry to the table, select a property from the \'Property\' dropdown and enter
                         the value which you want to assign the theme to. For example: Property = \'nid\', Value = \'123\'
                         and Theme = \'Bluemarine\' switches the theme of node 123 to Bluemarine. You may also specify
                         \'Additional Conditions\' so that the theme only applies when all conditions are matched. \'Additional
                         Conditions\' must be provided using the following syntax: \'property=value;property2=value2;...\'.
                         Supported operators are \'=\' (equal), \'!\' (not equal), \'<\' (smaller) and \'>\' (greater).'),
  );
  $form['properties']['table'] = array(
    '#theme' => 'themekey_table',
    '#header' => array(
      t('Property'),
      t('Value'),
      t('Additional Conditions'),
      t('Theme'),
    ),
    '#tree' => TRUE,
  );
  $themes = _themekey_theme_options();
  $properties = array_keys(variable_get('themekey_properties', array()));
  if (count($properties)) {
    $config = array();
    foreach ($properties as $property) {
      $config[$property] = $property;
    }
    ksort($config);
    $properties = _themekey_load_properties(THEMEKEY_PAGER_LENGTH, FALSE);
    foreach ($properties as $property) {
      $form['properties']['table'][$property['id']]['property'] = array(
        '#type' => 'select',
        '#title' => '',
        '#default_value' => $property['property'],
        '#options' => $config,
      );
      $form['properties']['table'][$property['id']]['value'] = array(
        '#type' => 'textfield',
        '#default_value' => $property['value'],
        '#size' => 25,
        '#maxlength' => 255,
      );
      $form['properties']['table'][$property['id']]['conditions'] = array(
        '#type' => 'textfield',
        '#default_value' => $property['conditions'],
        '#size' => 35,
        '#maxlength' => 255,
      );
      $form['properties']['table'][$property['id']]['theme'] = array(
        '#type' => 'select',
        '#default_value' => $property['theme'],
        '#options' => $themes,
      );
    }
    if (count($properties)) {
      $form['properties']['pager'] = array(
        '#value' => theme('pager', array(), THEMEKEY_PAGER_LENGTH),
      );
    }
    $form['properties']['addtable'] = array(
      '#theme' => 'themekey_table',
      '#header' => array(
        t('Property'),
        t('Value'),
        t('Additional Conditions'),
        t('Theme'),
      ),
      '#tree' => TRUE,
    );
    $form['properties']['addtable']['add']['property'] = array(
      '#type' => 'select',
      '#title' => '',
      '#default_value' => '',
      '#options' => $config,
    );
    $form['properties']['addtable']['add']['value'] = array(
      '#type' => 'textfield',
      '#default_value' => '',
      '#size' => 25,
      '#maxlength' => 255,
    );
    $form['properties']['addtable']['add']['conditions'] = array(
      '#type' => 'textfield',
      '#default_value' => '',
      '#size' => 35,
      '#maxlength' => 255,
    );
    $form['properties']['addtable']['add']['theme'] = array(
      '#type' => 'select',
      '#title' => '',
      '#default_value' => 'default',
      '#options' => $themes,
    );
  }
  else {
    $message = t('Please visit the <a href="@url">ThemeKey settings</a> tab first and enable at least one
                  property for selection', array(
      '@url' => url('admin/settings/themekey/settings'),
    ));
    drupal_set_message($message, 'error');
  }
  return _themekey_admin_form($form, '_themekey_properties');
}