Drupal-7.12 create node type

Source: Internet
Author: User
Drupal-7.12 create node type

Drupal site development

  1. Function examplenode_install (){
  2. // Updates the database cache of node types
  3. Node_types_rebuild ();
  4. $ Types = node_type_get_types ();
  5. // Add the body field to the node type
  6. Node_add_body_field ($ types ['job _ post']);
  7. // Load the instance definition for our content type's body
  8. $ Body_instance = field_info_instance ('node', 'body', 'job _ Post ');
  9. // Configure the body field
  10. $ Body_instance ['type'] = 'text _ summary_or_trimmed ';
  11. // Save our changes to the body field instance.
  12. Field_update_instance ($ body_instance );
  13. // Create all the fields we are adding to our content type.
  14. Foreach (_ job_post_installed_fields () as $ field ){
  15. Field_create_field ($ field );
  16. }
  17. // Create all the instances for our fields.
  18. Foreach (_ job_post_installed_instances () as $ instance ){
  19. $ Instance ['entity _ type'] = 'node ';
  20. $ Instance ['bundle'] = 'job _ post ';
  21. Field_create_instance ($ instance );
  22. }
  23. }
  24. /**
  25. * Return a structured array defining the fields created by this content type.
  26. * For the job post module there is only one additional field-the company name
  27. * Other fields cocould be added by defining them in this function as additional elements
  28. * In the array below
  29. */
  30. Function _ job_post_installed_fields (){
  31. $ T = get_t ();
  32. Return array (
  33. 'Job _ post_company '=> array (
  34. 'Field _ name' => 'job _ post_company ',
  35. 'Label' => $ t ('Company posting the job listing '),
  36. 'Type' => 'text ',
  37. ),
  38. );
  39. }
  40. /**
  41. * Return a structured array defining the field instances associated with this content type.
  42. */
  43. Function _ job_post_installed_instances (){
  44. $ T = get_t ();
  45. Return array (
  46. 'Job _ post_company '=> array (
  47. 'Field _ name' => 'job _ post_company ',
  48. 'Type' => 'text ',
  49. 'Label' => $ t ('Company posting the job listing '),
  50. 'Widget '=> array (
  51. 'Type' => 'text _ textfield ',
  52. ),
  53. 'Display' => array (
  54. 'Example _ node_list '=> array (
  55. 'Label' => $ t ('Company posting the job listing '),
  56. 'Type' => 'text ',
  57. ),
  58. ),
  59. ),
  60. );
  61. }
  62. /**
  63. * Implements hook_uninstall ().
  64. */
  65. Function examplenode_uninstall (){
  66. // Gather all the example content that might have been created while this
  67. // Module was enabled.
  68. $ SQL = 'SELECT nid FROM {node} n WHERE n. type =: type ';
  69. $ Result = db_query ($ SQL, array (': type' => 'job _ Post '));
  70. $ Nids = array ();
  71. Foreach ($ result as $ row ){
  72. $ Nids [] = $ row-> nid;
  73. }
  74. // Delete all the nodes at once
  75. Node_delete_multiple ($ nids );
  76. // Loop over each of the fields defined by this module and delete
  77. // All instances of the field, their data, and the field itself.
  78. Foreach (array_keys (_ job_post_installed_fields () as $ field ){
  79. Field_delete_field ($ field );
  80. }
  81. // Loop over any remaining field instances attached to the job_post
  82. // Content type (such as the body field) and delete them inpidually.
  83. $ Instances = field_info_instances ('node', 'job _ Post ');
  84. Foreach ($ instances as $ instance_name => $ instance ){
  85. Field_delete_instance ($ instance );
  86. }
  87. // Delete our content type
  88. Node_type_delete ('job _ Post ');
  89. // Purge all field infromation
  90. Field_purge_batch (1000 );
  91. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.