eva.module

  1. cis7 sites/all/modules/ulmus/eva/eva.module
  2. cle7 sites/all/modules/ulmus/eva/eva.module
  3. ecd7 sites/all/modules/ulmus/eva/eva.module
  4. elmsmedia7 sites/all/modules/ulmus/eva/eva.module
  5. harmony7 sites/all/modules/ulmus/eva/eva.module
  6. icor7 sites/all/modules/ulmus/eva/eva.module
  7. meedjum_blog7 sites/all/modules/ulmus/eva/eva.module
  8. mooc7 sites/all/modules/ulmus/eva/eva.module

Functions

Namesort descending Description
eva_entity_view_alter Implements hook_entity_view_alter().
eva_field_extra_fields Implements hook_content_extra_fields().
eva_form_views_ui_edit_form_alter Implements hook_form_FORM_ID_alter().
eva_get_arguments_from_token_string Get view arguments array from string that contains tokens
eva_get_views Get a list of views and displays attached to speficic entities.
eva_modules_disabled Implements hook_modules_disabled().
eva_modules_enabled Implements hook_modules_enabled().
eva_views_api Implements hook_views_api().
_eva_extract_entity_from_build Extract an actual entity object from its $build array.

File

sites/all/modules/ulmus/eva/eva.module
View source
  1. <?php
  2. // Load theme functions
  3. module_load_include('inc', 'eva', 'eva.theme');
  4. /**
  5. * Implements hook_views_api().
  6. */
  7. function eva_views_api() {
  8. return array(
  9. 'api' => 3,
  10. );
  11. }
  12. /**
  13. * Implements hook_content_extra_fields().
  14. */
  15. function eva_field_extra_fields() {
  16. $extras = array();
  17. $views = eva_get_views();
  18. foreach ($views as $entity => $data) {
  19. foreach ($data as $view) {
  20. foreach ($view['bundles'] as $bundle) {
  21. $extras[$entity][$bundle]['display'][$view['name'] . '_' . $view['display']] = array(
  22. 'label' => (empty($view['title'])) ? $view['name'] : $view['title'],
  23. 'description' => $view['title'],
  24. 'weight' => 10,
  25. );
  26. // Provide a separate extra field for the exposed form if there is any.
  27. if ($view['exposed form']) {
  28. $extras[$entity][$bundle]['display'][$view['name'] . '_' . $view['display'] . '_' . 'form'] = array(
  29. 'label' => ((empty($view['title'])) ? $view['name'] : $view['title']) . ' (' . t('Exposed form') . ')',
  30. 'description' => t('The exposed filter form of the view.'),
  31. 'weight' => 9,
  32. );
  33. }
  34. }
  35. }
  36. }
  37. return $extras;
  38. }
  39. /**
  40. * Implements hook_entity_view_alter().
  41. *
  42. * This is a terrible, terrible hack that should not be necessary; taxonomy and
  43. * some other entity types use fields, but don't implement hook_entity_view().
  44. * We have to ALTER those entity types after they're built. For the time being,
  45. * we'll use a list of special cases to trigger this special handling.
  46. */
  47. function eva_entity_view_alter(&$build, $type) {
  48. $view_mode = $build['#view_mode'];
  49. $language = $build['#language'];
  50. $entity_data = entity_get_info($type);
  51. $entity = _eva_extract_entity_from_build($build);
  52. $entity_ids = entity_extract_ids($type, $entity);
  53. $settings = field_view_mode_settings($type, $entity_ids[2]);
  54. $fields = field_extra_fields_get_display($type, $entity_ids[2], $view_mode);
  55. $views = eva_get_views($type);
  56. foreach ($views as $info) {
  57. $longname = $info['name'] .'_'. $info['display'];
  58. if (isset($fields[$longname]) && $fields[$longname]['visible']) {
  59. if ($view = views_get_view($info['name'])) {
  60. $view->set_display($info['display']);
  61. if ($view->access($info['display'])) {
  62. $view->current_entity = $entity;
  63. if (isset($fields[$longname . '_form']) && $fields[$longname . '_form']['visible']) {
  64. $view->init_handlers();
  65. $exposed_form = $view->display_handler->get_plugin('exposed_form');
  66. $build[$longname . '_form'] = array(
  67. '#markup' => $exposed_form->render_exposed_form(TRUE),
  68. );
  69. }
  70. $result = $view->execute_display($info['display']);
  71. if (!empty($result)) {
  72. $build[$longname] = array(
  73. '#markup' => $result,
  74. '#weight' => $fields[$longname]['weight'],
  75. );
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82. /**
  83. * Get a list of views and displays attached to speficic entities.
  84. *
  85. * This function will cache its results into the views cache, so it gets
  86. * cleared by Views appropriately.
  87. *
  88. * @param $type
  89. * The entity type we want to retrieve views for. If NULL is
  90. * specified, views for all entity types will be returned.
  91. * @param $reset
  92. * Force a rebuild of the data.
  93. * @return
  94. * An array of view name/display name values, or an empty array().
  95. */
  96. function eva_get_views($type = NULL, $reset = FALSE) {
  97. $used_views = &drupal_static(__FUNCTION__);
  98. if (!isset($used_views) || $reset) {
  99. views_include('cache');
  100. // If we're not resetting, check the Views cache.
  101. if (!$reset) {
  102. $cache = views_cache_get("eva");
  103. if (isset($cache->data)) {
  104. $used_views = $cache->data;
  105. }
  106. }
  107. // If it's still empty rebuild it.
  108. if (!isset($used_views)) {
  109. // Trigger a rebuild of the views object cache, which may not be fully loaded.
  110. ctools_include('export');
  111. ctools_export_load_object_reset('views_view');
  112. // Build and cache the data, both in the DB and statically.
  113. $views = views_get_applicable_views('uses hook entity view');
  114. foreach ($views as $data) {
  115. list($view, $display_id) = $data;
  116. $view_entity = $view->display_handler->get_option('entity_type');
  117. // Initialize handlers, to determine if the view uses exposed filters.
  118. $view->init_handlers();
  119. $used_views[$view_entity][] = array(
  120. 'name' => $view->name,
  121. 'title' => 'EVA: ' . $view->get_human_name() . ' - ' . $view->display[$display_id]->display_title,
  122. 'display' => $display_id,
  123. 'bundles' => $view->display_handler->get_option('bundles'),
  124. 'exposed form' => $view->display_handler->uses_exposed(),
  125. );
  126. $view->destroy();
  127. }
  128. views_cache_set("eva", $used_views);
  129. }
  130. }
  131. // Now spit back the data.
  132. if (isset($type) & isset($used_views)) {
  133. return isset($used_views[$type]) ? $used_views[$type] : array();
  134. }
  135. else {
  136. return isset($used_views) ? $used_views : array();
  137. }
  138. }
  139. /**
  140. * Extract an actual entity object from its $build array.
  141. *
  142. * This is a bit more complicated than it should be, since core entities, contrib
  143. * entities, and contrib entities based on EntityAPI all store their junk in
  144. * different slots of the build array. See http://drupal.org/node/1170198.
  145. *
  146. * @param $build
  147. * The token string defined by the view.
  148. * @param $entity_data
  149. * The token type.
  150. *
  151. * I hate you, Milkman Dan.
  152. */
  153. function _eva_extract_entity_from_build($build) {
  154. // EntityAPI often sticks stuff in here.
  155. if (!empty($build['#entity'])) {
  156. return $build['#entity'];
  157. }
  158. // Other entities stick them here!
  159. elseif (!empty($build['#' . $build['#entity_type']])) {
  160. return $build['#' . $build['#entity_type']];
  161. }
  162. // Some entities are naughty.
  163. elseif ($build['#entity_type'] == 'user') {
  164. return $build['#account'];
  165. }
  166. elseif ($build['#entity_type'] == 'taxonomy_term') {
  167. return $build['#term'];
  168. }
  169. return FALSE;
  170. }
  171. /**
  172. * Get view arguments array from string that contains tokens
  173. *
  174. * @param $string
  175. * The token string defined by the view.
  176. * @param $type
  177. * The token type.
  178. * @param $object
  179. * The object being used for replacement data (typically a node).
  180. * @return
  181. * An array of argument values.
  182. *
  183. * @todo: security?
  184. */
  185. function eva_get_arguments_from_token_string($string, $type, $object) {
  186. $args = trim($string);
  187. if (empty($args)) {
  188. return array();
  189. }
  190. $args = token_replace($args, array($type => $object), array('sanitize' => FALSE));
  191. return explode('/', $args);
  192. }
  193. /**
  194. * Implements hook_modules_enabled().
  195. */
  196. function eva_modules_enabled($modules) {
  197. // Reset the static cache in case any of the enabled modules
  198. // implement an eva view
  199. drupal_static_reset('eva_get_views');
  200. cache_clear_all('*', 'cache_views', TRUE);
  201. }
  202. /**
  203. * Implements hook_modules_disabled().
  204. */
  205. function eva_modules_disabled($modules) {
  206. // Reset the static cache in case any of the disabled modules
  207. // implemented an eva view
  208. drupal_static_reset('eva_get_views');
  209. cache_clear_all('*', 'cache_views', TRUE);
  210. }
  211. /**
  212. * Implements hook_form_FORM_ID_alter().
  213. */
  214. function eva_form_views_ui_edit_form_alter(&$form, &$form_state, $form_id) {
  215. // Clear the field cache when views are saved. This will make sure newly
  216. // created EVA views and/or exposed filters will appear.
  217. $form['actions']['save']["#submit"][] = 'field_cache_clear';
  218. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.