cer_entity_settings.install 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * Implements hook_install().
  4. */
  5. function cer_entity_settings_install() {
  6. $fields = array();
  7. $fields[] = array(
  8. 'active' => 1,
  9. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  10. 'deleted' => 0,
  11. 'entity_types' => array(),
  12. 'field_name' => 'cer_settings',
  13. 'foreign keys' => array(
  14. 'cer_preset' => array(
  15. 'columns' => array(
  16. 'target_id' => 'pid',
  17. ),
  18. 'table' => 'cer_preset',
  19. ),
  20. ),
  21. 'indexes' => array(
  22. 'target_id' => array(
  23. 0 => 'target_id',
  24. ),
  25. ),
  26. 'locked' => TRUE,
  27. 'module' => 'entityreference',
  28. 'settings' => array(
  29. // This field uses a simple custom selection handler that selects CER
  30. // presets which apply to the given entity.
  31. 'handler' => 'cer',
  32. 'handler_settings' => array(
  33. 'behaviors' => array(
  34. 'views-select-list' => array(
  35. 'status' => 0,
  36. ),
  37. ),
  38. ),
  39. 'target_type' => 'cer',
  40. ),
  41. 'translatable' => 0,
  42. 'type' => 'entityreference',
  43. );
  44. $fields[] = array(
  45. 'active' => 1,
  46. 'cardinality' => 1,
  47. 'deleted' => 0,
  48. 'entity_types' => array(),
  49. 'field_name' => 'cer_store_settings',
  50. 'foreign keys' => array(),
  51. 'indexes' => array(
  52. 'value' => array(
  53. 0 => 'value',
  54. ),
  55. ),
  56. 'locked' => TRUE,
  57. 'module' => 'list',
  58. 'settings' => array(
  59. 'allowed_values' => array(
  60. 0 => 0,
  61. 1 => 1,
  62. ),
  63. 'allowed_values_function' => '',
  64. ),
  65. 'translatable' => 0,
  66. 'type' => 'list_boolean',
  67. );
  68. array_walk($fields, 'field_create_field');
  69. $query = new EntityFieldQuery();
  70. $result = $query->entityCondition('entity_type', 'cer')->execute();
  71. if (isset($result['cer'])) {
  72. foreach (entity_load('cer', array_keys($result['cer'])) as $preset) {
  73. cer_entity_settings_cer_update($preset);
  74. }
  75. }
  76. }
  77. /**
  78. * Implements hook_uninstall().
  79. */
  80. function cer_entity_settings_uninstall() {
  81. field_delete_field('cer_settings');
  82. field_delete_field('cer_store_settings');
  83. }
  84. /**
  85. * Implements hook_update_dependencies().
  86. */
  87. function cer_entity_settings_update_dependencies() {
  88. return array(
  89. 'cer_entity_settings' => array(
  90. 7001 => array(
  91. 'cer' => 7005,
  92. ),
  93. ),
  94. );
  95. }
  96. /**
  97. * Drops the cer_entity_settings database table.
  98. */
  99. function cer_entity_settings_update_7001() {
  100. db_drop_table('cer_entity_settings');
  101. cer_entity_settings_install();
  102. }