Drupal-7.12 创建节点类型

php中文网
发布: 2016-07-25 09:05:04
原创
1542人浏览过

drupal 站点开发

造点AI
造点AI

夸克 · 造点AI

造点AI 325
查看详情 造点AI
  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. }
复制代码


最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号