>  기사  >  백엔드 개발  >  Drupal-7.12 노드 유형 생성

Drupal-7.12 노드 유형 생성

WBOY
WBOY원래의
2016-07-25 09:05:041274검색

drupal 站点开发

  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 could 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 individually.
  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. }
复制代码


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.