Drupal-7.12 create node type
|
Drupal site development
- Function examplenode_install (){
- // Updates the database cache of node types
- Node_types_rebuild ();
- $ Types = node_type_get_types ();
- // Add the body field to the node type
- Node_add_body_field ($ types ['job _ post']);
- // Load the instance definition for our content type's body
- $ Body_instance = field_info_instance ('node', 'body', 'job _ Post ');
- // Configure the body field
- $ Body_instance ['type'] = 'text _ summary_or_trimmed ';
- // Save our changes to the body field instance.
- Field_update_instance ($ body_instance );
- // Create all the fields we are adding to our content type.
- Foreach (_ job_post_installed_fields () as $ field ){
- Field_create_field ($ field );
- }
- // Create all the instances for our fields.
- Foreach (_ job_post_installed_instances () as $ instance ){
- $ Instance ['entity _ type'] = 'node ';
- $ Instance ['bundle'] = 'job _ post ';
- Field_create_instance ($ instance );
- }
- }
- /**
- * Return a structured array defining the fields created by this content type.
- * For the job post module there is only one additional field-the company name
- * Other fields cocould be added by defining them in this function as additional elements
- * In the array below
- */
- 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 ',
- ),
- );
- }
- /**
- * 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 ',
- ),
- ),
- ),
- );
- }
- /**
- * Implements hook_uninstall ().
- */
- Function examplenode_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' => 'job _ Post '));
- $ 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 module and delete
- // All instances of the field, their data, and the field itself.
- Foreach (array_keys (_ job_post_installed_fields () as $ field ){
- Field_delete_field ($ field );
- }
- // Loop over any remaining field instances attached to the job_post
- // Content type (such as the body field) and delete them inpidually.
- $ Instances = field_info_instances ('node', 'job _ Post ');
- Foreach ($ instances as $ instance_name => $ instance ){
- Field_delete_instance ($ instance );
- }
- // Delete our content type
- Node_type_delete ('job _ Post ');
- // Purge all field infromation
- Field_purge_batch (1000 );
- }
|