Need to change weight of title and taxonomy using CCK

abloodworth - December 31, 2007 - 20:13

I'm creating a fairly long form using CCK and need to use all the weights available (-10 to 10) to me to order the fields properly. I'd like the "title" field to be at the top of the form, but it has been given a default value of -5 which for some inexplicable reason I can't change! I also can't change the weight for taxonomy, which I think I may need to do in the future (for now I just deleted the link from the category to my custom content type so it doesn't appear in the form at all, and instead used CCK Taxonomy to create a custom field for it...but I'm not sure what affect this may have later if I want to create a view which uses those values). Why can't these weights be changed, and is there a way around this problem?

Thanks!
Allison

Me too

rvinne - January 12, 2008 - 11:27

Hi Allison
I would like to do the same. Did you find any solution.

Thank you.
Rolf

Using Automatic Nodetitles

rakisisesindekibalik - January 12, 2008 - 11:42

Use Automatic Nodetitles to overcome this. It's not the best solution but enough for now I gues

1- Create a text filed for node title
2- Use Automatic Nodetitles to syncronize node title with created text field. And chose to unpublish default title field

her is the link for the module: http://drupal.org/project/auto_nodetitle

Me too

Aar0n - February 11, 2008 - 21:12

Im also interested in this..

The taxonomy fields assigned to this node type should be treated just like normal fields allowing for the weight and group to be changed.
Any ideas anyone?

I agree!

MikeSchinkel - February 14, 2008 - 03:51

I agree! I'd really like to have control of the order of title, body, and taxonomy. Why has the order been fixed?!?

Me to.

nandou - February 14, 2008 - 09:40

I cant really understand why title and taxonomy weights are fixed...

As I mentioned above you can

rakisisesindekibalik - February 14, 2008 - 15:40

As I mentioned above you can change title filed by automatic node titles and taxonomy by CCK taxonomy (Deactivate default taxonomy field & activate CCK taxonomy & store it as taxonomy). For body field just disable body area and add a CCK text area but this will screw search since new pseudo body field is not indexed. I haven't tried but using CCK field thief may work in a someway like automatic node titles. But all of these have an impact on speed. So we need this feature to be implemented into core. Or do we need hacking core?

good work-arounds, but...

jfall - February 24, 2008 - 02:21

... always great to have work-arounds - sometimes it;s the only way...
But the question remains - why? why are the weights for these fields fixed and not under admin control?

Personally, I think overriding the title and body fields is not a great solution (these are used by other parts of the system for a variety of purposes, no?), and needing to install 2 additional modules just to control the weight of the title seems onerous.

I'm learning there are always 10 ways to do something in Drupal - I'm sure there is a better way... I just can't help at this point, so I'll watch this, cause I have the same issue!

I guess

rakisisesindekibalik - February 25, 2008 - 10:14

But the question remains - why? why are the weights for these fields fixed and not under admin control?

I haven't looked at code but I guess this is about CCK status. I mean its not a core module so it stores all data without altering existing db tables? (This is proper way for me). So it's normal that CCK does not touch core fields (body&title) and give default weight to them. I guess there won't be such problem with Drupal 7 since there are people saying "CCK should be core module" and if it happens normally we should have control among those fields too.

The Better Way!

MGParisi - February 29, 2008 - 08:45

There is a much "Better" way.... Gives you much more control, and is not dependent on any changes of modules. Here is the code. It also allows for custom theming of the form and others. Basically (I guess) the node form is made up of "widgets" and these widgets plug into content (which is not CCK). They are given default weights, and CCK doesnt want to over-ride!

So If you print_r($form) you will see the entire contents of the $form element. If you capture this element BEFORE it is put into the drupal_render form, then you can change every value as you see fit! (if you want to change titles, descriptions, or anything that a translation could handle, I would recommend coping the english translation, making it your default, and then go in and change the fields in their. You can EVEN add HTML (can we say Images!)

put this in your template.php

<?php
function phptemplate_node_form($form) {
 
$return = '';

  if (
file_exists(path_to_theme() . '/forms/node-form-' . $form['#node']->type . '.tpl.php'))
  {
   
$return = _phptemplate_callback('node-form', array('form' => $form), array('forms/node-form-' . $form['#node']->type));
  }

  if (
$return) {
    return
$return;
  }
  else {
    return
drupal_render($form);
  }
}
?>

then create a directory in your theme folder called "forms"

Then create a file called node-form-story.tpl.php

add the following lines of code (there is allot of little things in there that are different depending on your needs, so you WILL want to edit this.

<?php
global $user;
if (
$user->uid != 1) unset($form['log']);                                       //removes the revision log field for all but admin
$form['title']['#weight'] = -9;                                                       //Makes weight of Title to -9!  WOOPIE!
$form['taxonomy']['#weight'] = -7;                                            //taxonomy weight is now -7! WOOPIE!
$form['og_nodeapi']['#weight'] = -1;                                         //Moves Organic Groups Audience Widget above body
$form['og_nodeapi']['#prefix'] = '<div class="audience">';     //Adds a special div wraper to the Audience Widget
$form['og_nodeapi']['#suffix'] = '</div>';

//print_r($form);
print drupal_render($form);
?>

Thanks!...But.

skassam - March 27, 2008 - 00:45

Thanks for the snippet. It works great. But how do you override the node edit form as well? The node edit for the content type looks unaltered.

TIA,
Shinan

Wow, this is awesome, thanks!

MikeSchinkel - May 10, 2008 - 12:01

Wow, this is awesome, thanks! I'll check it out soon.

How can the same be done

tkgafs - March 31, 2008 - 22:12

How can the same be done when the node is being edited after it has been submitted ?

Tkgafs

This is what I discovered

skassam - April 22, 2008 - 17:30

Are you using the Diff module by any chance? There is apparently a conflict with diff module and custom form theming. I disabled the diff module and my create and edit forms were perfect.

Note: I just found this thread that is even better than just disabling diff. I have not actually tried this though.

http://drupal.org/node/200217

HTH,
Shinan

Changed weight in database to -4,5

borgo - April 18, 2008 - 10:17

Well this may be the weirdest solution possible, but seems to work fine : ) Though I haven't tested it fully.

I changed the weight value in the database, in table node_field_instance. I set weight for my cck created field "subtitle" to -4,5. That way I got it to display after the title (-5) and before the body (-4) field.

There is one bug I found so far. For some reason the user has to have "administer nodes" permission to see the fields in desired order. I have no idea why...

You can change it in node.module

anzoone - May 6, 2008 - 19:39

Not the best solution but i changed it in modules>node>node.module, and changed the title weight from -5 to -10 .If you want to change it this way, make sure to remember this after every upgrade, because node.module is a core module and will automatically be updated.

or in taxonomy only

arnulphe - May 29, 2008 - 11:07

For sure it is not pretty but you can do the same In modules>node>taxonomy.module. If your form is not too long, you don't need to change the node module to get the following order, for example: title [-5], body [0], taxonomy [1 instead of -3] and then the ckk fields and groups.
The line to modify is $form['taxonomy']['#weight'] = ;

 
 

Drupal is a registered trademark of Dries Buytaert.