t("Property themekey_ui:node_triggers_theme could not be selected from the property drop down. You get this static property by activating !link. Afterwards you can move the property to any position in the rule chain. When done it triggers the switch to the theme assigned to the current node using ThemeKey UI.", array('!link' => l(t('Show theme option in create/edit node forms'), 'admin/settings/themekey/settings/ui'))), 'static' => TRUE, ); // Mapping functions $maps = array(); $maps[] = array('src' => 'node:nid', 'dst' => 'themekey_ui:node_triggers_theme', 'callback' => 'themekey_ui_nid2theme'); return array('attributes' => $attributes, 'maps' => $maps); } /** * This function implements the interface of a ThemeKey * mapping function but doesn't set a ThemeKey property's * value. It sets the global variable $custom_theme to a * theme directly which will cause ThemeKey to use this * theme. * * @param $nid * a node id, current value of ThemeKey property node:nid * * @return * string "static" if global custom theme has been set * or NULL if no theme has been assigned to the node */ function themekey_ui_nid2theme($nid) { global $custom_theme; if ($node = node_load($nid)) { if (!empty($node->theme) && themekey_check_theme_enabled($node->theme)) { $custom_theme = $node->theme; return 'static'; } } return NULL; } /** * Implements hook_theme(). */ function themekey_ui_theme() { return array( 'themekey_ui_table' => array( 'arguments' => array('form' => NULL), ) ); } /** * Implements hook_perm(). */ function themekey_ui_perm() { return array('assign node themes'); } /** * Implements hook_menu(). */ function themekey_ui_menu() { $items = array(); $items['admin/settings/themekey/settings/ui'] = array( 'title' => 'User Interface', 'access callback' => 'user_access', 'access arguments' => array('administer themekey settings'), 'file' => 'themekey_ui_admin.inc', 'page callback' => 'drupal_get_form', 'page arguments' => array('themekey_ui_settings_form'), 'type' => MENU_LOCAL_TASK, 'weight' => 1 ); return $items; } /** * Implements hook_form_alter(). */ function themekey_ui_form_alter(&$form, $form_state, $form_id) { // Node form if (variable_get('themekey_ui_nodeform', 0) && user_access('assign node themes')) { $type = isset($form['type']['#value']) ? $form['type']['#value'] : FALSE; if ($form_id == $type .'_node_form' && variable_get('themekey_ui_nodeform|'. $type, 1)) { require_once(drupal_get_path('module', 'themekey_ui') .'/themekey_ui_admin.inc'); themekey_ui_nodeform($form, $form_state); } } // Path aliases if ($form_id == 'path_admin_form' && variable_get('themekey_ui_pathalias', 0)) { require_once(drupal_get_path('module', 'themekey_ui') .'/themekey_ui_admin.inc'); themekey_ui_pathalias($form, $form_state); } // REVIEW seems to be dead code // // Views // if ($form_id == 'views_ui_edit_display_form' && $form_state['#section'] == 'page-path' // && variable_get('themekey_ui_views', 0) && user_access('administer views')) { // require_once(drupal_get_path('module', 'themekey_ui') .'/themekey_ui_admin.inc'); // _themekey_ui_views($form, $form_state); // } } /** * Implements hook_nodeapi(). */ function themekey_ui_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { switch ($op) { case 'load': if (variable_get('themekey_ui_nodeform', 0) && variable_get('themekey_ui_nodeform|'. $node->type, 1)) { if (!empty($node->vid)) { $theme = db_result(db_query('SELECT theme FROM {themekey_ui_node_theme} WHERE nid = %d AND vid = %d', $node->nid, $node->vid)); if ($theme) { $node->theme = $theme; } else { $node->theme = 'default'; } } } break; case 'insert': if (!empty($node->theme)) { $item = array('nid' => $node->nid, 'vid' => $node->vid, 'theme' => $node->theme); if (drupal_write_record('themekey_ui_node_theme', $item)) { $themes[$node->vid] = $node->theme; } } break; case 'update': if (!empty($node->theme)) { $item = array('nid' => $node->nid, 'vid' => $node->vid, 'theme' => $node->theme); if (drupal_write_record('themekey_ui_node_theme', $item, array('nid', 'vid'))) { $themes[$node->vid] = $node->theme; } } break; case 'delete': db_query('DELETE FROM {themekey_ui_node_theme} WHERE nid = %d', $node->nid); break; } }