Maison développement back-end tutoriel php Drupal-7.12 创建节点类型

Drupal-7.12 创建节点类型

Jul 25, 2016 am 09:05 AM

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


Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

Article chaud

Repo: Comment relancer ses coéquipiers
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Combien de temps faut-il pour battre Split Fiction?
3 Il y a quelques semaines By DDD
R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
1 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: Comment obtenir des graines géantes
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌

Article chaud

Repo: Comment relancer ses coéquipiers
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Combien de temps faut-il pour battre Split Fiction?
3 Il y a quelques semaines By DDD
R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
1 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: Comment obtenir des graines géantes
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌

Tags d'article chaud

Bloc-notes++7.3.1

Bloc-notes++7.3.1

Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise

SublimeText3 version chinoise

Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1

Envoyer Studio 13.0.1

Puissant environnement de développement intégré PHP

Dreamweaver CS6

Dreamweaver CS6

Outils de développement Web visuel

SublimeText3 version Mac

SublimeText3 version Mac

Logiciel d'édition de code au niveau de Dieu (SublimeText3)

11 meilleurs scripts de raccourcissement d'URL PHP (gratuit et premium) 11 meilleurs scripts de raccourcissement d'URL PHP (gratuit et premium) Mar 03, 2025 am 10:49 AM

11 meilleurs scripts de raccourcissement d'URL PHP (gratuit et premium)

Introduction à l'API Instagram Introduction à l'API Instagram Mar 02, 2025 am 09:32 AM

Introduction à l'API Instagram

Travailler avec les données de session Flash dans Laravel Travailler avec les données de session Flash dans Laravel Mar 12, 2025 pm 05:08 PM

Travailler avec les données de session Flash dans Laravel

Construisez une application React avec un Laravel Back End: Partie 2, React Construisez une application React avec un Laravel Back End: Partie 2, React Mar 04, 2025 am 09:33 AM

Construisez une application React avec un Laravel Back End: Partie 2, React

Misque de réponse HTTP simplifié dans les tests Laravel Misque de réponse HTTP simplifié dans les tests Laravel Mar 12, 2025 pm 05:09 PM

Misque de réponse HTTP simplifié dans les tests Laravel

Curl dans PHP: Comment utiliser l'extension PHP Curl dans les API REST Curl dans PHP: Comment utiliser l'extension PHP Curl dans les API REST Mar 14, 2025 am 11:42 AM

Curl dans PHP: Comment utiliser l'extension PHP Curl dans les API REST

12 meilleurs scripts de chat PHP sur Codecanyon 12 meilleurs scripts de chat PHP sur Codecanyon Mar 13, 2025 pm 12:08 PM

12 meilleurs scripts de chat PHP sur Codecanyon

Notifications à Laravel Notifications à Laravel Mar 04, 2025 am 09:22 AM

Notifications à Laravel

See all articles