Guest User

Untitled

a guest
Oct 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. <?php
  2. /**
  3. * Implements hook_install().
  4. */
  5. function gamecontenttype_install() {
  6. node_types_rebuild();
  7. $types = node_type_get_types();
  8. foreach(_gamecontenttype_fields() as $field) {
  9. field_create_field($field);
  10. }
  11.  
  12. foreach(_gamecontenttype_instances() as $fieldinstance) {
  13. $fieldinstance['entity_type'] = 'node';
  14. $fieldinstance['bundle'] = 'game';
  15. print_r($fieldinstance);
  16. field_create_instance($fieldinstance);
  17. }
  18. }
  19.  
  20.  
  21. /**
  22. * Implements hook_uninstall().
  23. */
  24. function gamecontenttype_uninstall() {
  25. $ournewtype = 'game';
  26. $sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
  27. $result = db_query($sql, array(':type' => $ournewtype));
  28. $nodeids = array();
  29. foreach ($result as $row) {
  30. $nodeids[] = $row->nid;
  31. }
  32. node_delete_multiple($nodeids);
  33. delete_game_fields();
  34. node_type_delete($ournewtype);
  35. field_purge_batch(500);
  36. }
  37.  
  38. function delete_game_fields() {
  39. foreach (array_keys(_gamecontenttype_fields()) as $field) {
  40. field_delete_field($field);
  41. }
  42. $instances = field_info_instances('node', 'game');
  43. foreach ($instances as $instance_name => $fieldinstance) {
  44. field_delete_instance($fieldinstance);
  45. }
  46. }
  47.  
  48.  
  49. function _gamecontenttype_fields() {
  50. $t = get_t();
  51. return array(
  52. 'game_player_1' => array(
  53. 'field_name' => 'game_player_1',
  54. 'label' => $t('Player one'),
  55. 'cardinality' => 1,
  56. 'type' => 'user_reference',
  57. 'entity_types' => array('node'),
  58. 'settings' => array(
  59. 'referenceable_status' => array(
  60. 0 => 0,
  61. 1 => '1',
  62. ),
  63. )
  64. ),
  65. 'game_player_2' => array(
  66. 'field_name' => 'game_player_2',
  67. 'label' => $t('Player two'),
  68. 'cardinality' => 1,
  69. 'type' => 'user_reference',
  70. 'entity_types' => array('node'),
  71. 'settings' => array(
  72. 'referenceable_status' => array(
  73. 0 => 0,
  74. 1 => '1',
  75. ),
  76. )
  77. ),
  78. 'game_winner' => array(
  79. 'field_name' => 'game_winner',
  80. 'label' => $t('Who is the winner?'),
  81. 'cardinality' => 1,
  82. 'type' => 'user_reference',
  83. 'entity_types' => array('node'),
  84. 'settings' => array(
  85. 'referenceable_status' => array(
  86. 0 => 0,
  87. 1 => '1',
  88. ),
  89. )
  90. ),
  91. );
  92. }
  93.  
  94.  
  95. function _gamecontenttype_instances() {
  96. $t = get_t();
  97. return array(
  98. 'game_player_1' => array(
  99. 'field_name' => 'game_player_1',
  100. 'entity_type' => array('node'),
  101. 'bundle' => 'game',
  102. 'label' => $t('Player One'),
  103. 'required' => TRUE,
  104. 'widget' => array(
  105. 'active' => 1,
  106. 'module' => 'options',
  107. 'settings' => array(
  108. 'apply_chosen' => '',
  109. ),
  110. 'type' => 'options_select',
  111. 'weight' => '40',
  112. ),
  113. 'display' => array(),
  114. ),
  115. 'game_player_2' => array(
  116. 'field_name' => 'game_player_2',
  117. 'entity_type' => array('node'),
  118. 'bundle' => 'game',
  119. 'label' => $t('Player Two'),
  120. 'required' => TRUE,
  121. 'widget' => array(
  122. 'active' => 1,
  123. 'module' => 'options',
  124. 'settings' => array(
  125. 'apply_chosen' => '',
  126. ),
  127. 'type' => 'options_select',
  128. 'weight' => '40',
  129. ),
  130. 'display' => array(),
  131. ),
  132. 'game_winner' => array(
  133. 'field_name' => 'game_winner',
  134. 'entity_type' => array('node'),
  135. 'bundle' => 'game',
  136. 'label' => $t('Game Winner'),
  137. 'required' => TRUE,
  138. 'widget' => array(
  139. 'active' => 1,
  140. 'module' => 'options',
  141. 'settings' => array(
  142. 'apply_chosen' => '',
  143. ),
  144. 'type' => 'options_select',
  145. 'weight' => '41',
  146. ),
  147. 'display' => array(),
  148. ),
  149. );
  150. }
Add Comment
Please, Sign In to add comment