TripalEntityController.inc

File

tripal/includes/TripalEntityController.inc
View source
  1. <?php
  2. /**
  3. * TripalEntityController extends DrupalDefaultEntityController.
  4. *
  5. * Our subclass of DrupalDefaultEntityController lets us add a few
  6. * important create, update, and delete methods.
  7. */
  8. class TripalEntityController extends EntityAPIController {
  9. public function __construct($entityType) {
  10. parent::__construct($entityType);
  11. }
  12. /**
  13. * Create a Tripal data entity
  14. *
  15. * We first set up the values that are specific
  16. * to our data schema but then also go through the EntityAPIController
  17. * function.
  18. *
  19. * @param $type
  20. * The machine-readable type of the entity.
  21. *
  22. * @return
  23. * An object with all default fields initialized.
  24. */
  25. public function create(array $values = array()) {
  26. // Add some items to the values array passed to the constructor
  27. global $user;
  28. $values['uid'] = $user->uid;
  29. $values['created'] = time();
  30. $values['changed'] = time();
  31. $values['title'] = '';
  32. $values['type'] = 'TripalEntity';
  33. $values['nid'] = '';
  34. $values['status'] = 1;
  35. // Call the parent constructor.
  36. $entity = parent::create($values);
  37. // Allow modules to make additions to the entity when it's created.
  38. $modules = module_implements('entity_create');
  39. foreach ($modules as $module) {
  40. $function = $module . '_entity_create';
  41. $function($entity, $values['type']);
  42. }
  43. return $entity;
  44. }
  45. /**
  46. * Overrides EntityAPIController::delete().
  47. *
  48. * @param array $ids
  49. * An array of the ids denoting which entities to delete.
  50. * @param DatabaseTransaction $transaction
  51. * Optionally a DatabaseTransaction object to use. Allows overrides to pass in
  52. * their transaction object.
  53. */
  54. public function delete($ids, $transaction = NULL) {
  55. if (!$transaction) {
  56. $transaction = db_transaction();
  57. }
  58. try {
  59. // First load the entity.
  60. $entities = entity_load('TripalEntity', $ids);
  61. // Then properly delete each one.
  62. foreach ($entities as $entity) {
  63. // Invoke hook_entity_delete().
  64. module_invoke_all('entity_delete', $entity, $entity->type);
  65. // Delete any field data for this entity.
  66. field_attach_delete('TripalEntity', $entity);
  67. // Delete the entity record from our base table.
  68. db_delete('tripal_entity')
  69. ->condition('id', $entity->id)
  70. ->execute();
  71. }
  72. }
  73. catch (Exception $e) {
  74. $transaction->rollback();
  75. watchdog_exception('tripal', $e);
  76. throw $e;
  77. return FALSE;
  78. }
  79. return TRUE;
  80. }
  81. /**
  82. * Sets the title for an entity.
  83. *
  84. * @param $entity
  85. * @param $title
  86. */
  87. public function setTitle($entity, $title = NULL) {
  88. // If no title was supplied then we should try to generate one using the
  89. // default format set by admins.
  90. if (!$title) {
  91. // Load the TripalBundle entity for this TripalEntity.
  92. // Get the format for the title based on the bundle of the entity.
  93. // And then replace all the tokens with values from the entity fields.
  94. $bundle_entity = tripal_load_bundle_entity(array('name' => $entity->bundle));
  95. $title = tripal_get_title_format($bundle_entity);
  96. $title = tripal_replace_entity_tokens($title, $entity, $bundle_entity);
  97. }
  98. // Check if the passed alias has tokens.
  99. if($title && (preg_match_all("/\[[^\]]*\]/", $title, $bundle_tokens))) {
  100. // Load the TripalBundle entity for this TripalEntity.
  101. $bundle_entity = tripal_load_bundle_entity(array('name' => $entity->bundle));
  102. // And then replace all the tokens with values from the entity fields.
  103. $title = tripal_replace_entity_tokens($title, $entity, $bundle_entity);
  104. }
  105. // As long as we were able to determine a title, we should update it ;-).
  106. if ($title) {
  107. db_update('tripal_entity')
  108. ->fields(array(
  109. 'title' => $title
  110. ))
  111. ->condition('id', $entity->id)
  112. ->execute();
  113. }
  114. }
  115. /**
  116. * Sets the URL alias for an entity.
  117. */
  118. public function setAlias($entity, $alias = NULL) {
  119. $source_url = "bio_data/$entity->id";
  120. // If no alias was supplied then we should try to generate one using the
  121. // default format set by admins.
  122. if (!$alias) {
  123. // Load the TripalBundle entity for this TripalEntity.
  124. $bundle_entity = tripal_load_bundle_entity(array('name' => $entity->bundle));
  125. // First get the format for the url alias based on the bundle of the entity.
  126. $alias = tripal_get_bundle_variable('url_format', $bundle_entity->id);
  127. // And then replace all the tokens with values from the entity fields.
  128. $alias = tripal_replace_entity_tokens($alias, $entity, $bundle_entity);
  129. }
  130. // If there is still no alias supplied then we should generate one using
  131. // the term name and entity id.
  132. if (!$alias) {
  133. // Load the term for this TripalEntity.
  134. $term = entity_load('TripalTerm', array('id' => $entity->term_id));
  135. $term = reset($term);
  136. // Set a default based on the term name and entity id.
  137. $alias = str_replace(' ', '', $term->name) . '/[TripalEntity__entity_id]';
  138. // And then replace all the tokens with values from the entity fields.
  139. $alias = tripal_replace_entity_tokens($alias, $entity, $bundle_entity);
  140. }
  141. // Check if the passed alias has tokens.
  142. if($alias && (preg_match_all("/\[[^\]]*\]/", $alias, $bundle_tokens))) {
  143. // Load the TripalBundle entity for this TripalEntity.
  144. $bundle_entity = tripal_load_bundle_entity(array('name' => $entity->bundle));
  145. // And then replace all the tokens with values from the entity fields.
  146. $alias = tripal_replace_entity_tokens($alias, $entity, $bundle_entity);
  147. }
  148. // Make sure the alias doesn't contain spaces.
  149. $alias = preg_replace('/\s+/','-',$alias);
  150. // Or any non alpha numeric characters.
  151. $alias = preg_replace('/[^a-zA-Z0-9\-\/]/','',$alias);
  152. $alias = preg_replace('/_/','-',$alias);
  153. if ($alias) {
  154. // Determine if this alias has already been used.
  155. $sql ='
  156. SELECT count(*) as num_alias
  157. FROM {url_alias}
  158. WHERE alias=:alias
  159. ';
  160. $num_aliases = db_query($sql, array(':alias' => $alias))->fetchField();
  161. // Either there isn't an alias yet so we just create one.
  162. // OR an Alias already exists but we would like to add a new one.
  163. if ($num_aliases == 0) {
  164. // First delete any previous alias' for this entity.
  165. // Then save the new one.
  166. // TODO: publishing an entity can be very slow if there are lots of
  167. // entries in the url_alias table, due to this type of
  168. // SQL statement that gets called somewhere by Drupal:
  169. // SELECT DISTINCT SUBSTRING_INDEX(source, '/', 1) AS path FROM url_alias.
  170. // Perhaps we should write our own SQL to avoid this issue.
  171. $values = array(
  172. 'source' => $source_url,
  173. 'alias' => $alias,
  174. 'language' => 'und',
  175. );
  176. // path_delete(array('source' => $source_url));
  177. // $path = array('source' => $source_url, 'alias' => $alias);
  178. // path_save($path);
  179. //Now check if an entry with the source url for this entity already
  180. // exists. This is an issue when updating existing url aliases. To avoid
  181. // creating 404s existing aliases need to be updated and a redirect
  182. // created to handle the old alias.
  183. $existing_aliases = db_select('url_alias', 'ua')
  184. ->fields('ua')
  185. ->condition('source', $source_url, '=')
  186. ->execute()->fetchAll();
  187. $num_aliases = count($existing_aliases);
  188. if($num_aliases) {
  189. // For each existing entry create a redirect.
  190. foreach ($existing_aliases as $ea) {
  191. $path = [
  192. 'source' => $ea->source,
  193. 'alias' => $alias,
  194. 'pid' => $ea->pid,
  195. 'original' => [
  196. 'alias' => $ea->alias,
  197. 'pid' => $ea->pid,
  198. 'language' => $ea->language,
  199. ]
  200. ];
  201. module_load_include('module', 'redirect', 'redirect');
  202. redirect_path_update($path);
  203. //After redirects created now update the url_aliases table.
  204. db_update('url_alias')
  205. ->fields([
  206. 'alias' => $alias,
  207. ])
  208. ->condition('source', $source_url, '=')
  209. ->condition('pid', $ea->pid, '=')
  210. ->execute();
  211. }
  212. }
  213. else {
  214. drupal_write_record('url_alias', $values);
  215. }
  216. }
  217. // If there is only one alias matching then it might just be that we already
  218. // assigned this alias to this entity in a previous save.
  219. elseif ($num_aliases == 1) {
  220. $bundle_entity = tripal_load_bundle_entity(array('name' => $entity->bundle));
  221. // Check to see if the single alias is for the same entity and if not
  222. // warn the admin that the alias is already used (ie: not unique?)
  223. $sql = "
  224. SELECT count(*) as num_alias
  225. FROM {url_alias}
  226. WHERE alias=:alias AND source=:source
  227. ";
  228. $replace = array(':alias' => $alias, ':source' => $source_url);
  229. $same_alias = db_query($sql, $replace)->fetchField();
  230. if (!$same_alias) {
  231. $msg = 'The URL alias, %alias, already exists for another page. ' .
  232. 'Please ensure the pattern supplied on the <a href="!link" ' .
  233. 'target="_blank">%type Edit Page</a> under URL Path options is ' .
  234. 'unique.';
  235. $msg_var = array(
  236. '%alias' => $alias,
  237. '!link' => url("admin/structure/bio_data/manage/$entity->bundle"),
  238. '%type' => $bundle_entity->label
  239. );
  240. tripal_report_error('trpentity', TRIPAL_WARNING, $msg, $msg_var);
  241. drupal_set_message(t($msg, $msg_var), 'warning');
  242. }
  243. }
  244. // If there are more then one alias' matching what we generated then there's
  245. // a real problem and we need to warn the administrator.
  246. else {
  247. $bundle_entity = tripal_load_bundle_entity(array('name' => $entity->bundle));
  248. $aliases = db_query('SELECT source FROM {url_alias} WHERE alias=:alias',
  249. array(':alias' => $alias))->fetchAll();
  250. $pages = array();
  251. foreach($aliases as $a) {
  252. $pages[] = $a->source;
  253. }
  254. $msg = 'The URL alias, %alias, already exists for multiple pages! '.
  255. 'Please ensure the pattern supplied on the <a href="!link" ' .
  256. 'target="_blank">%type Edit Page</a> under URL Path options is ' .
  257. 'unique.';
  258. $msg_var = array(
  259. '%alias' => $alias,
  260. '!link' => url("admin/structure/bio_data/manage/$entity->bundle"),
  261. '%type' => $bundle_entity->label
  262. );
  263. drupal_set_message(t($msg, $msg_var), 'error');
  264. $msg .= ' This url alias has already been used for the following pages: %pages.
  265. You can manually delete alias\' using a combination of path_load() and path_delete().';
  266. $msg_var['%pages'] = implode(', ', $pages);
  267. tripal_report_error('trpentity', TRIPAL_ERROR, $msg, $msg_var);
  268. }
  269. }
  270. }
  271. /**
  272. * Saves a new entity.
  273. *
  274. * @param $entity
  275. * A TripalEntity object to save.
  276. *
  277. * @return
  278. * The saved entity object with updated properties.
  279. */
  280. public function save($entity, DatabaseTransaction $transaction = NULL) {
  281. global $user;
  282. $pkeys = array();
  283. // Get the author information.
  284. $author = $user;
  285. if (property_exists($entity, 'uid')) {
  286. $author = user_load($entity->uid);
  287. }
  288. $changed_date = time();
  289. $create_date = $changed_date;
  290. if (property_exists($entity, 'created')) {
  291. if (!is_numeric($entity->created)) {
  292. $temp = new DateTime($entity->created);
  293. $create_date = $temp->getTimestamp();
  294. }
  295. }
  296. $status = 1;
  297. if (property_exists($entity, 'status')) {
  298. if ($entity->status === 0 or $entity->status === 1) {
  299. $status = $entity->status;
  300. }
  301. }
  302. $transaction = isset($transaction) ? $transaction : db_transaction();
  303. try {
  304. // If our entity has no id, then we need to give it a
  305. // time of creation.
  306. if (empty($entity->id)) {
  307. $entity->created = time();
  308. $invocation = 'entity_insert';
  309. }
  310. else {
  311. $invocation = 'entity_update';
  312. $pkeys = array('id');
  313. }
  314. // Invoke hook_entity_presave().
  315. module_invoke_all('entity_presave', $entity, $entity->type);
  316. // Write out the entity record.
  317. $record = array(
  318. 'term_id' => $entity->term_id,
  319. 'type' => $entity->type,
  320. 'bundle' => $entity->bundle,
  321. 'title' => $entity->title,
  322. 'uid' => $author->uid,
  323. 'created' => $create_date,
  324. 'changed' => $changed_date,
  325. 'status' => $status,
  326. );
  327. if (property_exists($entity, 'nid') and $entity->nid) {
  328. $record['nid'] = $entity->nid;
  329. }
  330. if ($invocation == 'entity_update') {
  331. $record['id'] = $entity->id;
  332. }
  333. $success = drupal_write_record('tripal_entity', $record, $pkeys);
  334. if ($success == SAVED_NEW) {
  335. $entity->id = $record['id'];
  336. }
  337. // Now we need to either insert or update the fields which are
  338. // attached to this entity. We use the same primary_keys logic
  339. // to determine whether to update or insert, and which hook we
  340. // need to invoke.
  341. if ($invocation == 'entity_insert') {
  342. field_attach_insert('TripalEntity', $entity);
  343. }
  344. else {
  345. field_attach_update('TripalEntity', $entity);
  346. }
  347. // Set the title for this entity.
  348. $this->setTitle($entity);
  349. // Set the path/url alias for this entity.
  350. $this->setAlias($entity);
  351. // Invoke either hook_entity_update() or hook_entity_insert().
  352. module_invoke_all('entity_postsave', $entity, $entity->type);
  353. module_invoke_all($invocation, $entity, $entity->type);
  354. // Clear any cache entries for this entity so it can be reloaded using
  355. // the values that were just saved.
  356. $cid = 'field:TripalEntity:' . $entity->id;
  357. cache_clear_all($cid, 'cache_field', TRUE);
  358. return $entity;
  359. }
  360. catch (Exception $e) {
  361. $transaction->rollback();
  362. watchdog_exception('tripal', $e);
  363. drupal_set_message("Could not save the entity: " . $e->getMessage(), "error");
  364. return FALSE;
  365. }
  366. }
  367. /**
  368. * Override the load function.
  369. *
  370. * A TripalEntity may have a large number of fields attached which may
  371. * slow down the loading of pages and web services. Therefore, we only
  372. * want to attach fields that are needed.
  373. *
  374. * @param $ids
  375. * The list of entity IDs to load.
  376. * @param $conditions
  377. * The list of key/value filters for querying the entity.
  378. * @param $field_ids
  379. * The list of numeric field IDs for fields that should be attached.
  380. * @param $cache
  381. * When loading of entities they can be cached with Drupal for later
  382. * faster loading. However, this can cause memory issues when running
  383. * Tripal jobs that load lots of entities. Caching of entities can
  384. * be disabled to improve memory performance by setting this to FALSE.
  385. */
  386. public function load($ids = array(), $conditions = array(), $field_ids = array(), $cache = TRUE) {
  387. $entities = array();
  388. // Revisions are not statically cached, and require a different query to
  389. // other conditions, so separate the revision id into its own variable.
  390. if ($this->revisionKey && isset($conditions[$this->revisionKey])) {
  391. $revision_id = $conditions[$this->revisionKey];
  392. unset($conditions[$this->revisionKey]);
  393. }
  394. else {
  395. $revision_id = FALSE;
  396. }
  397. // Create a new variable which is either a prepared version of the $ids
  398. // array for later comparison with the entity cache, or FALSE if no $ids
  399. // were passed. The $ids array is reduced as items are loaded from cache,
  400. // and we need to know if it's empty for this reason to avoid querying the
  401. // database when all requested entities are loaded from cache.
  402. $passed_ids = !empty($ids) ? array_flip($ids) : FALSE;
  403. // Try to load entities from the static cache.
  404. if ($this->cache && !$revision_id) {
  405. $entities = $this->cacheGet($ids, $conditions);
  406. // If any entities were loaded, remove them from the ids still to load.
  407. if ($passed_ids) {
  408. $ids = array_keys(array_diff_key($passed_ids, $entities));
  409. }
  410. }
  411. // Support the entitycache module if activated.
  412. if (!empty($this->entityInfo['entity cache']) && !$revision_id && $ids && !$conditions) {
  413. $cached_entities = EntityCacheControllerHelper::entityCacheGet($this, $ids, $conditions);
  414. // If any entities were loaded, remove them from the ids still to load.
  415. $ids = array_diff($ids, array_keys($cached_entities));
  416. $entities += $cached_entities;
  417. // Add loaded entities to the static cache if we are not loading a
  418. // revision.
  419. if ($this->cache && !empty($cached_entities) && !$revision_id) {
  420. $this->cacheSet($cached_entities);
  421. }
  422. }
  423. // Load any remaining entities from the database. This is the case if $ids
  424. // is set to FALSE (so we load all entities), if there are any ids left to
  425. // load or if loading a revision.
  426. if (!($this->cacheComplete && $ids === FALSE && !$conditions) && ($ids === FALSE || $ids || $revision_id)) {
  427. $queried_entities = array();
  428. foreach ($this->query($ids, $conditions, $revision_id) as $record) {
  429. // Skip entities already retrieved from cache.
  430. if (isset($entities[$record->{$this->idKey}])) {
  431. continue;
  432. }
  433. // For DB-based entities take care of serialized columns.
  434. if (!empty($this->entityInfo['base table'])) {
  435. $schema = drupal_get_schema($this->entityInfo['base table']);
  436. foreach ($schema['fields'] as $field => $info) {
  437. if (!empty($info['serialize']) && isset($record->$field)) {
  438. $record->$field = unserialize($record->$field);
  439. // Support automatic merging of 'data' fields into the entity.
  440. if (!empty($info['merge']) && is_array($record->$field)) {
  441. foreach ($record->$field as $key => $value) {
  442. $record->$key = $value;
  443. }
  444. unset($record->$field);
  445. }
  446. }
  447. }
  448. }
  449. $queried_entities[$record->{$this->idKey}] = $record;
  450. }
  451. }
  452. // Pass all entities loaded from the database through $this->attachLoad(),
  453. // which attaches fields (if supported by the entity type) and calls the
  454. // entity type specific load callback, for example hook_node_load().
  455. if (!empty($queried_entities)) {
  456. $this->attachLoad($queried_entities, $revision_id, $field_ids);
  457. $entities += $queried_entities;
  458. }
  459. // Entity cache module support: Add entities to the entity cache if we are
  460. // not loading a revision.
  461. if (!empty($this->entityInfo['entity cache']) && !empty($queried_entities) && !$revision_id) {
  462. EntityCacheControllerHelper::entityCacheSet($this, $queried_entities);
  463. }
  464. if ($this->cache and $cache) {
  465. // Add entities to the cache if we are not loading a revision.
  466. if (!empty($queried_entities) && !$revision_id) {
  467. $this->cacheSet($queried_entities);
  468. // Remember if we have cached all entities now.
  469. if (!$conditions && $ids === FALSE) {
  470. $this->cacheComplete = TRUE;
  471. }
  472. }
  473. }
  474. // Ensure that the returned array is ordered the same as the original
  475. // $ids array if this was passed in and remove any invalid ids.
  476. if ($passed_ids && $passed_ids = array_intersect_key($passed_ids, $entities)) {
  477. foreach ($passed_ids as $id => $value) {
  478. $passed_ids[$id] = $entities[$id];
  479. }
  480. $entities = $passed_ids;
  481. }
  482. return $entities;
  483. }
  484. /**
  485. * Override the attachLoad function.
  486. *
  487. * A TripalEntity may have a large number of fields attached which may
  488. * slow down the loading of pages and web services. Therefore, we only
  489. * want to attach fields that are needed.
  490. *
  491. * @param $queried_entities
  492. * The list of queried
  493. * @param $revision_id
  494. * ID of the revision that was loaded, or FALSE if the most current
  495. * revision was loaded.
  496. * @param $field_ids
  497. */
  498. protected function attachLoad(&$queried_entities, $revision_id = FALSE,
  499. $field_ids = array()) {
  500. // Attach fields.
  501. if ($this->entityInfo['fieldable']) {
  502. if ($revision_id) {
  503. $function = 'field_attach_load_revision';
  504. }
  505. else {
  506. $function = 'field_attach_load';
  507. }
  508. foreach ($queried_entities as $id => $entity) {
  509. $info = entity_get_info($entity->type);
  510. $field_cache = array_key_exists('field cache', $info) ? $info['field cache'] : FALSE;
  511. $bundle_name = $entity->bundle;
  512. // Iterate through the field instances and find those that are set to
  513. // 'auto_attach' and which are attached to this bundle. Add all
  514. // fields that don't need auto attach to the field_ids array.
  515. $instances = field_info_instances('TripalEntity', $bundle_name);
  516. foreach ($instances as $instance) {
  517. $field_name = $instance['field_name'];
  518. $field = field_info_field($field_name);
  519. $field_id = $field['id'];
  520. // Add this field to the entity with default value.
  521. if (!isset($queried_entities[$id]->$field_name)) {
  522. $queried_entities[$id]->$field_name = array();
  523. }
  524. // Options used for the field_attach_load function.
  525. $options = array();
  526. $options['field_id'] = $field['id'];
  527. // The cache ID for the entity. We must manually set the cache
  528. // because the field_attach_load won't do it for us.
  529. $cfid = "field:TripalEntity:$id:$field_name";
  530. // Check if the field is cached. if so, then don't reload.
  531. if ($field_cache) {
  532. $cache_data = cache_get($cfid, 'cache_field');
  533. if (!empty($cache_data)) {
  534. $queried_entities[$id]->$field_name = $cache_data->data;
  535. $queried_entities[$id]->{$field_name}['#processed'] = TRUE;
  536. continue;
  537. }
  538. }
  539. // If a list of field_ids is provided then we specifically want
  540. // to only load the fields specified.
  541. if (count($field_ids) > 0) {
  542. if (in_array($field_id, $field_ids)) {
  543. $function($this->entityType, array($entity->id => $queried_entities[$id]),
  544. FIELD_LOAD_CURRENT, $options);
  545. // Cache the field.
  546. if ($field_cache) {
  547. cache_set($cfid, $entity->$field_name, 'cache_field');
  548. }
  549. $queried_entities[$id]->{$field_name}['#processed'] = TRUE;
  550. }
  551. }
  552. // If we don't have a list of fields then load them all, but only
  553. // if the instance is a TripalField and it is set to not auto
  554. // attach then we will ignore it. It can only be set by providing
  555. // the id in the $field_id array handled previously.
  556. else {
  557. // We only load via AJAX if empty fields are not hidden.
  558. $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
  559. $hide_variable = tripal_get_bundle_variable('hide_empty_field', $bundle->id, 'hide');
  560. if (array_key_exists('settings', $instance) and
  561. array_key_exists('auto_attach', $instance['settings']) and
  562. $instance['settings']['auto_attach'] == FALSE and
  563. $hide_variable == 'show') {
  564. // Add an empty value. This will allow the tripal_entity_view()
  565. // hook to add the necessary prefixes to the field for ajax
  566. // loading.
  567. $queried_entities[$id]->$field_name['und'][0]['value'] = '';
  568. $queried_entities[$id]->{$field_name}['#processed'] = FALSE;
  569. }
  570. else {
  571. $function($this->entityType, array($entity->id => $queried_entities[$id]),
  572. FIELD_LOAD_CURRENT, $options);
  573. // Cache the field.
  574. if ($field_cache) {
  575. cache_set($cfid, $entity->$field_name, 'cache_field');
  576. }
  577. $queried_entities[$id]->{$field_name}['#processed'] = TRUE;
  578. }
  579. }
  580. }
  581. }
  582. }
  583. // Call hook_entity_load().
  584. foreach (module_implements('entity_load') as $module) {
  585. $function = $module . '_entity_load';
  586. $function($queried_entities, $this->entityType);
  587. }
  588. // Call hook_TYPE_load(). The first argument for hook_TYPE_load() are
  589. // always the queried entities, followed by additional arguments set in
  590. // $this->hookLoadArguments.
  591. $args = array_merge(array($queried_entities), $this->hookLoadArguments);
  592. foreach (module_implements($this->entityInfo['load hook']) as $module) {
  593. call_user_func_array($module . '_' . $this->entityInfo['load hook'], $args);
  594. }
  595. }
  596. }