I am basically trying to customized story module with additional fields as a preliminary step towards understanding Drupal modules.
I have been reading through the documentation on drupaldocs.org (really very good stuff, by the way), and while I know little about the stuff, I can understand what I read ;p.
The story module was the simplest, so I changed all the 'story' references to 'setinfo' (appropriately), and if that's all I do, it works fine. However, the point is to add new custom fields to it. When I add something, it shows up in the submit/edit form, but when I preview the item or submit it, the extra info is not there. It doesn't get saved/parsed and I can't figure out why it doesn't.
Here is the code that seems to work:
/**
* Implementation of hook_form().
*/
function setinfo_form(&$node) {
$output = '';
if (function_exists('taxonomy_node_form')) {
$output .= implode('', taxonomy_node_form('setinfo', $node));
}
$output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, '', NULL, TRUE);
$output .= filter_form('format', $node->format);
return $output;
}
But if I steal the code from the book module (thought it would minimize the chance of my error), the extra 'log' info does not get saved:
/**
* Implementation of hook_form().
*/
function setinfo_form(&$node) {
$output = '';
if (function_exists('taxonomy_node_form')) {
$output .= implode('', taxonomy_node_form('setinfo', $node));
}
$output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, '', NULL, TRUE);
$output .= filter_form('format', $node->format);
$output .= form_textarea(t('Log message'), 'log', $node->log, 60, 5, t('An explanation of the additions or updates being made to help other authors understand your motivations.'));
return $output;
}
Any help, or direction to what I should read in the docs would be really appreciated, thank you! Even a name for this behavior would be helpful. :)
Oh, yes, and I do know about the flexinode module. Excellent stuff there too. I just thought I would try making my own before messing with flexinode to get the module to look how I want it to look.
Anisa.
Comments
Take this module as a sample
this is my resource.module, a story module with additional fields:
Of course you have to create a SQL table to store data.
hope it helps.
Matteo
Thank you for the code! It
Thank you for the code! It looks interesting. I'll have a more indepth look at it when I get home (at work now).
I do have a question though... In your module, your info is stored in a table. In the original story module, where is the info stored? There aren't any sql calls, and there isn't a story table (when I checked there wasn't, may have missed something). If there were, it would make sense that the additional fields were not being stored because there was no place to store them.
Thanks again for the help!
Anisa.
All data are stored in node table
Normally, all data are stored in node table.
To make modules independent from the base functionalities, all external data are stored in additional tables.
This also to avoid hacking base node table calls, which are in node.module.
I can guarantee you that, even it seems complicated, once you understand the logic, Drupall will be simpler to you !!!
Matteo
^.^
The documentation is so nice, it doesn't seem so bad at all. Themes seem more scary though. Your module is also a tremendous help.
I have a couple of questions, looking at your code (and probably more as I go through it more)... Hope you can bear with me.
Was the point of having node/add/resource retrieve the help instructions so that when a person submits the resource, they see the help instructions on the top of the screen?
Also...
As far as I can tell, this controls the display of the published content, you have it set so you can theme it. But there isn't a 'hook_content' (at least, not one that looks like this), is this something you made especially? How does it know whether or not to display the teaser or the full page? Is how a node displayed left all up to a theme, normally? (must read more about that later).
I also have questions about the db queries, but I will save them. ^.^
Thank you again for all your help. I wouldn't want to do this as a job, but it's fun to learn about.
Anisa.
アニサです。
content gets called from view
You're right, there is no content hook. There is, however, a view hook:
which also answers your question about the teaser - Drupal decides for you and passes the $page parameter in to the view hook.
I think you are very wise to learn how to write your own modules. When I started writing my own modules is when I started falling in love with Drupal. Up until then it was just something to download so I could have a blog. Now it is the only software I am interested in using for web applications of all natures.
- Robert Douglass
-----
www.robshouse.net
www.webs4.com
Thanks. I think I am
Thanks. I think I am blushing. ^.^
Right now it is spouting errors at me, though. I uninstalled a similarly named flexinode module, and the img assist module, and it started telling me that I was missing argument 2 from my access hook.
Pretty standard hook, I thought, and the 2nd argument is the *node*, so ... not sure where to go from there.
Anisa.
Check out flexinode
Check out the flexinode module. It allows arbitrary node types with admin-defined fields.
May not be the simplest way to learn, but is a powerful feature.
--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba
OK, getting access denied...
here is my module as I have it (please ignore all my notes ^.^;;):
I am getting access denied to the create new content page for my module. I used to get 'missing argument 2' for the access hook, but that no longer pops up.
I had removed a similarly named flexinode type and the image assist module before I started getting these errors.
Really not sure what is going on... As far as I can tell, the access things are pretty standard. I am logged in as the super user.
Anisa.
help making custom (story based) module - adding new fields
Thanks, for this excellent code!
I would like to add the following fields to code as follows:
field type: checkbox (multiple select)
field type: file
field type: image
field type: select (single select)
field type: textarea (done)
field type: textfield (done)
field type: timestamp
The single select option will be used to select list of countries, states and cities.
The checkbox option will be used to select multiple categories.
All comments greatly appreciated!
Thanks, Darly
Apache is bandwidth limited, PHP is CPU limited, and MySQL is memory limited.