I¹m new to Drupal. A very experienced programmer, but new to Drupal. I have worked my way through Beginning Drupal 7 by Todd Tomlinson and Pro Drupal 7 Development by Todd Tomlinson and John K VanDyk. I¹ve watched some videos and online code examples.
Here¹s where I am in my project. The site is set up, contributed modules installed, base theme installed. I¹m beginning to add 13 custom content types. I want them to be added from modules, 1 for each type since there will be a cafeteria plan. There¹s much more, but I¹m stuck here.
In the books there was a example of adding one field to a new content type. All created in a module. The exercise worked great. However, when I try it with one of my modules that has multiple fields, things get screwed up.
- The fields are added to the database, but they do not appear on the form. - During uninstall, the field tables are not removed from the database. - I don¹t know how to set all of the properties of the data field or widget that I can when I am creating a custom content type using the administrative pages. - I want the fields to be contained in fieldsets upon installation. I can do this if I am creating a form from scratch with code, but how do I do this in a custom content type module.install script?
I¹ve screwed around with this so much now that I¹m not sure when what stopped working.
Here are some code snippets I¹ve tried.
---- function _job_post_installed_fields() { $t = get_t(); return array( 'job_post_company' => array( 'field_name' => 'job_post_company', 'label' => $t('Company posting the job listing'), 'type' => 'text', ), 'job_post_color' => array( 'field_name' => 'job_post_color', 'label' => $t('Job post color'), 'type' => 'text', ), ); } /** * return a structured array defining the field instances associated with this content type */ function _job_post_installed_instances() { $t = get_t(); return array( 'job_post_company' => array( 'field_name' => 'job_post_company', 'type' => 'text', 'label' => $t('Company posting the job listing'), 'widget' => array( 'type' => 'text_textfield', ), 'display' => array( 'example_node_list' => array( 'label' => $t('Company posting the job listing'), 'type' => 'text', ), ), ), 'job_post_color' => array( 'field_name' => 'job_post_color', 'type' => 'text', 'label' => $t('Job post color'), 'widget' => array( 'type' => 'text_textfield', ), 'display' => array( 'example_node_list' => array( 'label' => $t('Job post color'), 'type' => 'text', ), ), ), ); } ---- And ---- function _hawk_topic_installed_fields() { $t = get_t(); return array( 'hawk_topic_type' => array( 'field_name' => 'hawk_topic_type', 'label' => $t('hawk Topic Type'), 'type' => 'text', 'settings' => array( 'max_length' => 50, ), ), 'hawk_topic_color' => array( 'field_name' => 'hawk_topic_color', 'label' => $t('hawk Topic Color'), 'type' => 'text', 'settings' => array( 'max_length' => 20, ), ), ); } /** * return a structured array defining the field instances associated with this content type */ function _hawk_topic_installed_instances() { $t = get_t(); return array( 'hawk_topic_type' => array( 'field_name' => 'hawk_topic_type', 'type' => 'text', 'label' => $t('Type of topic'), 'widget' => array( 'type' => 'text_textfield', 'settings' => array('size' => 60), ), 'display' => array( 'example_node_list' => array( 'label' => $t('Type of topic'), 'type' => 'text', ), ), ), 'hawk_topic_color' => array( 'field_name' => 'hawk_topic_color', 'type' => 'text', 'label' => $t('Color of topic'), 'widget' => array( 'type' => 'text_textfield', 'settings' => array('size' => 20), ), 'display' => array( 'example_node_list' => array( 'label' => $t('Color of topic'), 'type' => 'text', ), ), ), ); } ---- The uninstall script seems to be right out of the book (pun intended). ---- function hawk_topic_uninstall() { // gather all the example content that might have been created while this // module was enabled $sql = 'SELECT nid FROM {node} n WHERE n.type = :type'; $result = db_query($sql, array(':type' => 'hawk_topic')); $nids = array (); foreach ($result as $row) { $nids[] = $row->nid; } // delete all the nodes at once node_delete_multiple($nids); // loop over each of the fields defined by this moduel and delete // all instance of the field, their data, and the field itself. foreach (array_keys(_hawk_topic_installed_fields()) as $field) { field_delete_field($field); } // loop over any remaining file instances attached to the hawk_topic // content type (such as body field) and delete them individually $instances = field_info_instances('node', 'hawk_topic'); foreach ($instances as $instance_name => $instance) { field_delete_instance($instance); } // delete our content type node_type_delete('hawk_topic'); // purge all field information field_purge_batch(1000); } ----
Any ideas? Probably a beginners mistake?
Thanks in advance,
Next question. How do you copy code out of Dreamweaver and have it come out looking right?