TripalBundleController.inc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * The Controller for Tripal data type entities
  4. */
  5. class TripalBundleController extends EntityAPIControllerExportable {
  6. public function __construct($entityType) {
  7. parent::__construct($entityType);
  8. // The 'bundle of' property is usually set in the hook_entity_info()
  9. // function for the "entity type" entity. This allows the Entity API
  10. // to provide the user interface for managing fields attached to the
  11. // bundle. But, we are using the same controller classes for
  12. // all entity types and we do not want new links for every
  13. // entity type (vocabulary) on the Administration >> Structure menu.
  14. // We just want one menu item. So to support one menu item that
  15. // can handle all of the Tripal entity types, we have to set the
  16. // 'bundle of' property here rather than in the hook_entity_info() function.
  17. $bundle_of = $entityType;
  18. $bundle_of = preg_replace('/_bundle/', '', $bundle_of);
  19. $info = entity_get_info($bundle_of);
  20. $this->bundleKey = $info['bundle keys']['bundle'];
  21. $this->entityInfo['bundle of'] = $bundle_of;
  22. }
  23. /**
  24. * Create a type - we first set up the values that are specific
  25. * to our type schema but then also go through the EntityAPIController
  26. * function.
  27. *
  28. * @param $type
  29. * The machine-readable type of the tripal data entity.
  30. *
  31. * @return
  32. * A type object with all default fields initialized.
  33. */
  34. public function create(array $values = array()) {
  35. // Add values that are specific to our entity
  36. $values += array(
  37. 'id' => '',
  38. 'is_new' => TRUE,
  39. 'data' => '',
  40. );
  41. return parent::create($values);
  42. }
  43. }