custom node type problem
dnorthcott - June 19, 2008 - 16:32
Ok, I've created a custom node type module, but here is what i want to do:
i want to strip out alot of the optional stuff that you can choose when creating a node type (eg. i automatically want tit to be full html, no choice, and then publishing options i want gone, ect.) and I want to be able to direct all attatched files to a custom directory, and insert a select menu into the form?
please, any suggestions
cheers

Use:
Use: hook_form_alter()
---
Yuriy Babenko
www.yubastudios.com
cool thanks, i can get it to
cool thanks, i can get it to display select boxes and such, but could you be a bit more specific as how to customise the directory where the attached files are upload to, and how to strip out all the 'standard' node options on the page where you write a node?
cheers
ok, when i display the value
ok, when i display the value of the select box ( $node->category ) i get a number (the selected index) is there an easier way of displaying the string value other than:
print $node->cat_options[$node->category];
?
cheers
Looks like it's giving you
Looks like it's giving you the actual value of the selected option, rather than the associated string. This makes sense...
Don't think there's going to be an easier way than what you've come up with...
---
Yuriy Babenko
www.yubastudios.com
I don't know how you would
I don't know how you would customize the directory bit. I know some image modules allow you to set this, but I'm not sure how it works for attachments. I think you're just limited to one directory by default...
Removing fields is easy, just use something like:
<?php$form['log'] = array();
?>
in the hook_form_alter().
---
Yuriy Babenko
www.yubastudios.com
You can alter the upload
You can alter the upload path but it's tricky and has limitations. In order to use the upload module, the path will have to live inside of your 'files' folder.
Write a module that implements hook_nodeapi and is weighted to be called before the upload module. When the 'validate' action for hook_nodeapi is called, modify $node->files['upload_xxx']['filename'] to your new path. It must be inside of your drupal public filesystem (usually 'files').
Awesome! thanks! i'm still
Awesome! thanks! i'm still learning php, so could you give me a quick example of how i would set the dir using $node->file[upload_xxx][filename] ?
cheers
yuriy: THANKS!!
I believe you'll have an
I believe you'll have an array element called 'upload_xxx' (xxx being a number) for each attachment being saved. So the first one would be like...
<?php// Prepend the filename with your own directory.
// This MUST be inside of Drupal's 'files' directory.
// The temp file gets moved there in the 'update' or 'insert' action using file_move().
$node->file['upload_0']['filename'] = 'files/mydir/' . $node->file['upload_0']['filename'];
?>
Thanks for the idea - I think I'm going to use this as my example in a talk on modifying module behavior at Drupalcamp Alberta.
Later,
Chris.
And...
And it's critical that your module's hooks are called before upload.module. To do this, see this link:
http://drupal.org/node/110238
You can do this in your .install file, or use the Module Weight module, or do it manually after you install.
wicked. thanks for your
wicked. thanks for your help!!
can you tell me how to automatically set the input format to be full html?
whats drupalcamp alberta? i live in calgary...
Hey you're relatively close
Hey you're relatively close to me. I'm in Montana.
http://www.drupalcampalberta.org/
To set the input format you can implement hook_form_alter, then change the input format to a 'value' type with the format index you need. Then it's hidden and can't be changed.
Here's an article on hook_form_alter
http://www.lullabot.com/articles/modifying-forms-5-and-6