entity_example.install 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * @file
  4. * Install for a basic entity - need to create the base table for our entity.
  5. * This table can have as many columns as you need to keep track of
  6. * entity-specific data that will not be added via attached fields.
  7. * The minimum information for the entity to work is an id and an entity name.
  8. */
  9. /**
  10. * Implements hook_schema().
  11. *
  12. * @ingroup entity_example
  13. */
  14. function entity_example_schema() {
  15. $schema = array();
  16. // The name of the table can be any name we choose. However, namespacing the
  17. // table with the module name is best practice.
  18. $schema['entity_example_basic'] = array(
  19. 'description' => 'The base table for our basic entity.',
  20. 'fields' => array(
  21. 'basic_id' => array(
  22. 'description' => 'Primary key of the basic entity.',
  23. 'type' => 'serial',
  24. 'unsigned' => TRUE,
  25. 'not null' => TRUE,
  26. ),
  27. // If we allow multiple bundles, then the schema must handle that;
  28. // We'll put it in the 'bundle_type' field to avoid confusion with the
  29. // entity type.
  30. 'bundle_type' => array(
  31. 'description' => 'The bundle type',
  32. 'type' => 'text',
  33. 'size' => 'medium',
  34. 'not null' => TRUE,
  35. ),
  36. // Additional properties are just things that are common to all
  37. // entities and don't require field storage.
  38. 'item_description' => array(
  39. 'description' => 'A description of the item',
  40. 'type' => 'varchar',
  41. 'length' => 255,
  42. 'not null' => TRUE,
  43. 'default' => '',
  44. ),
  45. 'created' => array(
  46. 'description' => 'The Unix timestamp of the entity creation time.',
  47. 'type' => 'int',
  48. 'not null' => TRUE,
  49. 'default' => 0,
  50. ),
  51. ),
  52. 'primary key' => array('basic_id'),
  53. );
  54. return $schema;
  55. }
  56. /**
  57. * Implements hook_uninstall().
  58. *
  59. * At uninstall time we'll notify field.module that the entity was deleted
  60. * so that attached fields can be cleaned up.
  61. *
  62. * @ingroup entity_example
  63. */
  64. function entity_example_uninstall() {
  65. field_attach_delete_bundle('entity_example_basic', 'first_example_bundle');
  66. }