Hello,

I do like this module very much and I find that's quite usefull. I couldn't work without it.
Nevertheless, I would like to mention that a little feature misses to be perfect:
I should be able to associate a special "node style" to a content type. So, when creating some content, it should select the associated item by default.
This is very usefull, because I need different "CSS-Includes" depending on the content type. But the problem is that it's quite difficult for some people to choose the right one.

Perhaps, this would be of interest of some other users ;-)

CommentFileSizeAuthor
#1 patch-node-style.txt3.29 KBgrandcat

Comments

grandcat’s picture

Status: Active » Needs review
StatusFileSize
new3.29 KB

So, I wrote a patch by myself which adds the feature mentioned above:

diff -u -r -N node_style_old/node_style.module node_style/node_style.module
--- node_style_old/node_style.module	2007-04-07 11:13:18.000000000 +0200
+++ node_style/node_style.module	2007-07-08 16:51:30.000000000 +0200
@@ -139,7 +139,16 @@
  */
 function node_style_form_alter($form_id, &$form) {
   if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && user_access('customise node styles')) {
+	
     $node = $form['#node'];
+	
+	//NEW Code added by Stefan S. (Grandcat @ Drupal)
+	if(empty($node->node_style)){
+	  //new node
+	  $node_type = _node_style_find_scheme(arg(2));
+	  if($node_type)
+	    $node->node_style = $node_type;
+	}
 
     $schemes = array('0' => t('None')) + _node_style_get_schemes();
 
@@ -147,7 +156,7 @@
       '#type' => 'fieldset',
       '#title' => t('Node style'),
       '#collapsible' => TRUE,
-      '#collapsed' => empty($node->node_style),
+      '#collapsed' => !empty($node->node_style), //<-- more useful
       '#weight' => 30
     );
     $form['node_style']['node_style_scheme'] = array(
@@ -314,7 +323,21 @@
     '#rows' => 6,
     '#resizable' => TRUE
   );
-
+  
+  //NEW Code added by Stefan S. (Grandcat @ Drupal)
+  $node_types['no_node_type'] = t('None');
+  foreach(node_get_types('types') as $n_type){
+    $node_types[$n_type->type] = $n_type->name;
+  }
+  
+  $form['misc']['node_type_dependency'] = array(
+    '#type' => 'select',
+	'#title' => t('When using the selected node type, this scheme will automatically be selected by default'),
+	'#description' => t('If a node type is chosen, this scheme will be automatically selected while adding some content with this node type.'),
+	'#default_value' => $scheme['variables']['misc']['node_type_dependency'],
+	'#options' => $node_types,
+  );
+  
   $form['submit'] = array('#type' => 'submit', '#value' => t('Save scheme'));
   $form['#base'] = 'node_style_scheme';
 
@@ -346,6 +369,8 @@
   $scheme['display']['page'] = array_keys($scheme['display']['page']);
   $scheme['misc']['theme'] = $form_values['misc']['theme'];
   $scheme['misc']['head'] = $form_values['misc']['head'];
+  //Code added by Stefan S. (Grandcat @ Drupal)
+  $scheme['misc']['node_type_dependency'] = $form_values['misc']['node_type_dependency'];
 
   if (isset($form_values['sid'])) {
     _node_style_update_scheme($form_values['sid'], $form_values['name'], $scheme);
@@ -502,6 +527,24 @@
 }
 
 /**
+* Find the right scheme depending on the node style - type -- following function added by Stefan S. (Grandcat @ Drupal)
+*/
+
+function _node_style_find_scheme($node_type) {
+  //Drupals Menu System makes a "-" out of a "_", so let's do a replace
+  
+  $result = db_query("SELECT sid, variables FROM {node_style_schemes}");
+  while($scheme_data = db_fetch_array($result)){
+    $scheme_data['variables'] = unserialize($scheme_data['variables']);
+	$scheme_data['variables']['misc']['node_type_dependency'] = str_replace("_", "-", $scheme_data['variables']['misc']['node_type_dependency']); //replace
+	if($scheme_data['variables']['misc']['node_type_dependency'] == $node_type)
+	  $scheme_id = $scheme_data['sid'];
+  }
+  
+  return isset($scheme_id) ? $scheme_id : FALSE;
+}
+
+/**
  * Return PHPTemplate variables array.
  */
 function _node_style_get_arrays() {
mlsamuelson’s picture

Status: Needs review » Closed (duplicate)
mlsamuelson’s picture

Meant to say the duplicate is http://drupal.org/node/142732 . :)