ds_extras.module

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

Display Suite extras main functions.

Functions

Namesort descending Description
ds_extras_admin_paths Implements hook_admin_paths().
ds_extras_block_info Implements hook_block_info().
ds_extras_block_view Implements hook_block_view().
ds_extras_ctools_plugin_api Implements hook_ctools_plugin_api().
ds_extras_ds_field_access DS fields access.
ds_extras_ds_field_settings_alter Implements hook_ds_field_settings_alter().
ds_extras_ds_field_theme_functions_info Implements hook_ds_field_theme_functions_info().
ds_extras_ds_layout_info_alter Implements hook_ds_layout_info_alter().
ds_extras_ds_layout_region_alter Implements hook_ds_layout_region_alter().
ds_extras_ds_layout_settings_alter Implements hook_ds_layout_settings_alter().
ds_extras_entity_info Implements hook_entity_info().
ds_extras_entity_view_alter Implements hook_entity_view_alter().
ds_extras_field_attach_view_alter Implements hook_field_attach_view_alter().
ds_extras_field_extra_fields Implements hook_field_extra_fields().
ds_extras_flags_add_flag_link Output flag.
ds_extras_form_field_ui_display_overview_form_alter Implements hook_form_FORM_ID_alter().
ds_extras_form_field_ui_field_edit_form_alter Implements hook_form_FORM_ID_alter().
ds_extras_form_node_form_alter Implements hook_form_FORM_ID_alter().
ds_extras_get_view_mode Utility funtion to return the view mode for the current entity.
ds_extras_is_entity_page_view Helper function to check if this is a page view.
ds_extras_menu Implements hook_menu().
ds_extras_menu_alter Implements hook_menu_alter().
ds_extras_module_implements_alter Implements hook_module_implements_alter().
ds_extras_permission Implements hook_permission().
ds_extras_preprocess_field Implements hook_preprocess_field().
ds_extras_preprocess_view_layout Implements hook_preprocess_views_view().
ds_extras_process_page_title Page title options for a full entity page view.
ds_extras_switch_view_mode_field Switch view mode field.
ds_extras_switch_view_mode_preview_callback Ajax callback for _ds_field_ui_table_layouts_preview().
ds_extras_theme_registry_alter Implements hook_theme_registry_alter().
ds_vd_render_title_field Function used for theming the views title, user name etc. Note that this is a function so it can't be overridden by a phptemplate function.
theme_ds_field_expert Custom output all HTML for the field.
theme_ds_field_minimal Provide minimal HTML for the field.
theme_ds_field_reset Reset all HTML for the field.

File

sites/all/modules/ulmus/ds/modules/ds_extras/ds_extras.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Display Suite extras main functions.
  5. */
  6. /**
  7. * Implements hook_menu().
  8. */
  9. function ds_extras_menu() {
  10. $items = array();
  11. $items['admin/structure/ds/list/extras'] = array(
  12. 'title' => 'Extras',
  13. 'description' => 'Configure extra functionality for Display Suite.',
  14. 'page callback' => 'drupal_get_form',
  15. 'page arguments' => array('ds_extras_settings'),
  16. 'access arguments' => array('admin_display_suite'),
  17. 'file' => 'includes/ds_extras.admin.inc',
  18. 'type' => MENU_LOCAL_TASK,
  19. );
  20. if (variable_get('ds_extras_switch_field')) {
  21. $items['ds-switch-view-mode'] = array(
  22. 'title' => 'Switch view',
  23. 'description' => 'Switches a view mode inline.',
  24. 'page callback' => 'ds_switch_view_mode_inline',
  25. 'access arguments' => array('access content'),
  26. 'file' => 'includes/ds_extras.pages.inc',
  27. 'type' => MENU_CALLBACK,
  28. );
  29. }
  30. if (variable_get('ds_extras_vd', FALSE) && module_exists('field_ui') && module_exists('views')) {
  31. $items['admin/structure/ds/vd'] = array(
  32. 'title' => 'Views displays',
  33. 'description' => 'Manage your views templates.',
  34. 'page callback' => 'ds_extras_vd_overview',
  35. 'file' => 'includes/ds_extras.vd.inc',
  36. 'access arguments' => array('admin_display_suite'),
  37. 'type' => MENU_LOCAL_TASK,
  38. );
  39. $items['admin/structure/ds/vd/manage'] = array(
  40. 'title' => 'Manage layout',
  41. 'description' => 'Manage your views templates.',
  42. 'page callback' => 'ds_extras_vd_manage',
  43. 'file' => 'includes/ds_extras.vd.inc',
  44. 'access arguments' => array('admin_display_suite'),
  45. 'type' => MENU_LOCAL_TASK,
  46. );
  47. }
  48. return $items;
  49. }
  50. /**
  51. * Implements hook_entity_info().
  52. */
  53. function ds_extras_entity_info() {
  54. module_load_include('inc', 'ds_extras', 'includes/ds_extras.registry');
  55. return _ds_extras_entity_info();
  56. }
  57. /**
  58. * Implements hook_ds_layout_info_alter().
  59. */
  60. function ds_extras_ds_layout_info_alter(&$layouts) {
  61. if (variable_get('ds_extras_hidden_region')) {
  62. foreach ($layouts as $key => $layout) {
  63. $layouts[$key]['regions']['ds_hidden'] = t('Hidden');
  64. }
  65. }
  66. }
  67. /**
  68. * Implements hook_permission().
  69. */
  70. function ds_extras_permission() {
  71. $permissions = array();
  72. // Extra check to make sure this doesn't get fired on install.
  73. if (variable_get('ds_extras_switch_view_mode', FALSE)) {
  74. foreach (node_type_get_names() as $key => $name) {
  75. $permissions['ds_switch ' . $key] = array(
  76. 'title' => t('Switch view modes on :type', array(':type' => $name))
  77. );
  78. }
  79. }
  80. if (variable_get('ds_extras_field_permissions', FALSE)) {
  81. $entities = entity_get_info();
  82. foreach ($entities as $entity_type => $info) {
  83. $fields = ds_get_fields($entity_type);
  84. foreach ($fields as $key => $finfo) {
  85. $permissions['view ' . $key . ' on ' . $entity_type] = array(
  86. 'title' => t('View !field on !entity_type', array('!field' => $finfo['title'], '!entity_type' => $info['label'])),
  87. );
  88. }
  89. }
  90. }
  91. return $permissions;
  92. }
  93. /**
  94. * Implements hook_admin_paths().
  95. */
  96. function ds_extras_admin_paths() {
  97. if (variable_get('node_admin_theme')) {
  98. return array(
  99. 'node/*/display' => TRUE,
  100. 'user/*/display' => TRUE,
  101. 'taxonomy/term/*/display' => TRUE,
  102. );
  103. }
  104. }
  105. /**
  106. * Implements hook_menu_alter().
  107. */
  108. function ds_extras_menu_alter(&$items) {
  109. module_load_include('inc', 'ds_extras', 'includes/ds_extras.registry');
  110. _ds_extras_menu_alter($items);
  111. }
  112. /**
  113. * Implements hook_theme_registry_alter().
  114. */
  115. function ds_extras_theme_registry_alter(&$theme_registry) {
  116. module_load_include('inc', 'ds_extras', 'includes/ds_extras.registry');
  117. _ds_extras_theme_registry_alter($theme_registry);
  118. }
  119. /**
  120. * Implements hook_module_implements_alter().
  121. */
  122. function ds_extras_module_implements_alter(&$implementations, $hook) {
  123. module_load_include('inc', 'ds_extras', 'includes/ds_extras.registry');
  124. _ds_extras_module_implements_alter($implementations, $hook);
  125. }
  126. /**
  127. * Implements hook_form_FORM_ID_alter().
  128. */
  129. function ds_extras_form_field_ui_display_overview_form_alter(&$form, &$form_state) {
  130. form_load_include($form_state, 'inc', 'ds_extras', 'includes/ds_extras.admin');
  131. ds_extras_field_ui_alter($form, $form_state);
  132. }
  133. /**
  134. * Implements hook_ctools_plugin_api().
  135. */
  136. function ds_extras_ctools_plugin_api($owner, $api) {
  137. if ($owner == 'ds_extras' && $api == 'ds_extras') {
  138. return array('version' => 1);
  139. }
  140. }
  141. /**
  142. * DS fields access.
  143. *
  144. * @param $field
  145. * The machine name of the field
  146. * @param $entity_type
  147. * The name of the entity type.
  148. */
  149. function ds_extras_ds_field_access($field, $entity_type) {
  150. if (user_access('view ' . $field . ' on ' . $entity_type)) {
  151. return TRUE;
  152. }
  153. return FALSE;
  154. }
  155. /**
  156. * Implements hook_field_attach_view_alter().
  157. */
  158. function ds_extras_field_attach_view_alter(&$build, $context) {
  159. // If views and core doesn't send information along on the entity,
  160. // Display Suite doesn't have a context to render the fields.
  161. if (!isset($build['#entity_type']) && !isset($build['#bundle'])) {
  162. return;
  163. }
  164. $block_data = &drupal_static('ds_block_region');
  165. $region_blocks = variable_get('ds_extras_region_blocks', array());
  166. if (empty($region_blocks)) {
  167. return;
  168. }
  169. $entity_type = $build['#entity_type'];
  170. $bundle = $build['#bundle'];
  171. $view_mode = $context['view_mode'];
  172. $properties = array();
  173. foreach (element_properties($build) as $property) {
  174. $properties[$property] = $build[$property];
  175. }
  176. $properties['#view_mode'] = $view_mode;
  177. if ($layout = ds_get_layout($entity_type, $bundle, $view_mode)) {
  178. foreach ($region_blocks as $block_key => $block) {
  179. if ($block['info'] == "{$entity_type}_{$bundle}_{$view_mode}" && isset($layout['settings']['regions'][$block_key]) && !empty($layout['settings']['regions'][$block_key])) {
  180. foreach ($layout['settings']['regions'][$block_key] as $key => $field) {
  181. if (isset($build[$field])) {
  182. $block_data[$block_key][$field] = $build[$field];
  183. unset($build[$field]);
  184. }
  185. }
  186. if (isset($block_data[$block_key]) && is_array($block_data[$block_key])) {
  187. $block_data[$block_key] += $properties;
  188. }
  189. }
  190. }
  191. }
  192. }
  193. /**
  194. * Implements hook_form_FORM_ID_alter().
  195. */
  196. function ds_extras_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
  197. $theme_functions = module_invoke_all('ds_field_theme_functions_info');
  198. unset($theme_functions['theme_ds_field_expert']);
  199. $form['instance']['ds_extras_field_template'] = array(
  200. '#type' => 'select',
  201. '#title' => t('Field Template'),
  202. '#default_value' => isset($form['#instance']['ds_extras_field_template']) ? $form['#instance']['ds_extras_field_template'] : '',
  203. '#options' => $theme_functions,
  204. '#description' => t('Choose the default HTML for this field.'),
  205. '#empty_option' => t('Use sitewide default'),
  206. );
  207. }
  208. /**
  209. * Utility funtion to return the view mode for the current entity.
  210. *
  211. * The drupal_static is called in ds_extras_node_show to set
  212. * the current view mode. Through this technique, the hide page
  213. * title functionality can also work across other view modes
  214. * if another one is chosen for the full page of the node.
  215. */
  216. function ds_extras_get_view_mode() {
  217. return drupal_static('ds_extras_view_mode');
  218. }
  219. /**
  220. * Page title options for a full entity page view.
  221. */
  222. function ds_extras_process_page_title(&$variables) {
  223. $page_title = drupal_static('ds_page_title');
  224. if (!empty($page_title)) {
  225. $variables['title'] = $page_title['title'];
  226. if (!empty($page_title['head_title'])) {
  227. drupal_set_title($page_title['head_title']);
  228. }
  229. }
  230. // Support for Views page title, currently only hiding the title.
  231. if (variable_get('ds_extras_vd', FALSE) && $view = views_get_page_view()) {
  232. if ($layout = ds_get_layout('ds_views', $view->name . '-' . $view->current_display, 'default')) {
  233. if (isset($layout['settings']['hide_page_title']) && $layout['settings']['hide_page_title'] == 1) {
  234. $variables['title'] = '';
  235. }
  236. }
  237. }
  238. }
  239. /**
  240. * Implements hook_ds_layout_settings_alter().
  241. */
  242. function ds_extras_ds_layout_settings_alter($record, $form_state) {
  243. if (isset($form_state['values']['additional_settings']['ds_page_title']['ds_page_title_options']['page_option_type']) ||
  244. isset($form_state['values']['page_option_type'])) {
  245. // Save page title view type
  246. if (isset($form_state['values']['additional_settings']['ds_page_title']['ds_page_title_options']['page_option_type'])) {
  247. $record->settings['hide_page_title'] = $form_state['values']['additional_settings']['ds_page_title']['ds_page_title_options']['page_option_type'];
  248. }
  249. else {
  250. $form_state['values']['page_option_type'];
  251. }
  252. // Save page title
  253. if (isset($form_state['values']['additional_settings']['ds_page_title']['ds_page_title_options']['page_option_title'])) {
  254. $record->settings['page_option_title'] = $form_state['values']['additional_settings']['ds_page_title']['ds_page_title_options']['page_option_title'];
  255. }
  256. else {
  257. $record->settings['page_option_title'] = $form_state['values']['page_option_title'];
  258. }
  259. }
  260. if (isset($form_state['values']['additional_settings']['hide_sidebars'])) {
  261. $record->settings['hide_sidebars'] = $form_state['values']['additional_settings']['hide_sidebars'];
  262. }
  263. }
  264. /**
  265. * Switch view mode field.
  266. */
  267. function ds_extras_switch_view_mode_field($field) {
  268. $output = '';
  269. static $added = FALSE;
  270. if (isset($field['formatter_settings'])) {
  271. $entity = $field['entity'];
  272. $id = $entity->nid;
  273. $url = $field['entity_type'] . '-' . $field['view_mode'] . '-' . $id . '-';
  274. $switch = array();
  275. foreach ($field['formatter_settings']['vms'] as $key => $value) {
  276. if (!empty($value)) {
  277. $class = 'switch-' . $key;
  278. if ($key == $field['view_mode']) {
  279. $switch[] = '<span class="' . $class . '">' . check_plain(t($value)) . '</span>';
  280. }
  281. else {
  282. $switch[] = '<span class="' . $class . '"><a href="" class="' . $url . $key . '">' . check_plain(t($value)) . '</a></span>';
  283. }
  284. }
  285. }
  286. if (!empty($switch)) {
  287. if (!$added) {
  288. $add = TRUE;
  289. drupal_add_js(drupal_get_path('module', 'ds_extras') . '/js/ds_extras.js');
  290. }
  291. $output = '<div class="switch-view-mode-field">' . implode(' ', $switch) . '</div>';
  292. }
  293. }
  294. return $output;
  295. }
  296. /**
  297. * Implements hook_form_FORM_ID_alter().
  298. */
  299. function ds_extras_form_node_form_alter(&$form, $form_state, $form_id) {
  300. // Switch full view mode.
  301. if (user_access('ds_switch ' . $form['#node']->type)) {
  302. $view_mode_settings = field_view_mode_settings('node', $form['#node']->type);
  303. // Get the view modes.
  304. $ds_vm = ds_entity_view_modes('node');
  305. $layouts = array();
  306. $options = array('' => t('Default'));
  307. foreach ($ds_vm as $key => $item) {
  308. $overriden = (!empty($view_mode_settings[$key]['custom_settings']) ? TRUE : FALSE);
  309. if ($overriden) {
  310. $layout = ds_get_layout('node', $form['#node']->type, $key, FALSE);
  311. $layouts[$key] = $layout;
  312. $options[$key] = $item['label'];
  313. }
  314. }
  315. // Add default layout settings
  316. $layouts[''] = ds_get_layout('node', $form['#node']->type, 'default', FALSE);
  317. // Only fire if we have more than 1 option.
  318. if (count($options) > 1) {
  319. $node = $form['#node'];
  320. if (!isset($form['ds_extras'])) {
  321. $form['ds_extras'] = array(
  322. '#type' => 'fieldset',
  323. '#title' => t('Display settings'),
  324. '#collapsible' => TRUE,
  325. '#collapsed' => TRUE,
  326. '#group' => 'additional_settings',
  327. '#weight' => 100,
  328. );
  329. }
  330. $form['ds_extras']['ds_switch'] = array(
  331. '#type' => 'select',
  332. '#title' => t('View mode'),
  333. '#options' => $options,
  334. '#default_value' => isset($node->ds_switch) ? $node->ds_switch : '',
  335. '#description' => t('Switch to a different view mode to display the full page view of this node.'),
  336. '#weight' => -1,
  337. '#ajax' => array(
  338. 'callback' => 'ds_extras_switch_view_mode_preview_callback',
  339. 'wrapper' => 'ds_switch_preview_wrapper',
  340. ),
  341. );
  342. $form['ds_extras']['preview'] = array(
  343. '#type' => 'container',
  344. '#prefix' => '<div id="ds_switch_preview_wrapper">',
  345. '#suffix' => '</div>',
  346. );
  347. $mode = isset($form_state['input']['ds_switch']) ? $form_state['input']['ds_switch'] : (isset($node->ds_switch) ? $node->ds_switch : '');
  348. $chosen_layout = $layouts[$mode];
  349. $fallback_image = drupal_get_path('module', 'ds') . '/images/preview.png';
  350. $image = (isset($chosen_layout['image']) && !empty($chosen_layout['image'])) ? $chosen_layout['path'] . '/' . $chosen_layout['layout'] . '.png' : $fallback_image;
  351. if (isset($chosen_layout['panels']) && !empty($chosen_layout['panels']['icon'])) {
  352. $image = $chosen_layout['panels']['path'] . '/' . $chosen_layout['panels']['icon'];
  353. }
  354. $form['ds_extras']['preview']['image'] = array(
  355. '#markup' => '<div class="ds-layout-preview-image"><img src="' . base_path() . $image . '"/></div>',
  356. );
  357. }
  358. }
  359. }
  360. /**
  361. * Ajax callback for _ds_field_ui_table_layouts_preview().
  362. */
  363. function ds_extras_switch_view_mode_preview_callback($form, $form_state) {
  364. return $form['ds_extras']['preview'];
  365. }
  366. /**
  367. * Implements hook_block_info().
  368. */
  369. function ds_extras_block_info() {
  370. $region_blocks = variable_get('ds_extras_region_blocks', array());
  371. if (empty($region_blocks)) {
  372. return array();
  373. }
  374. foreach ($region_blocks as $key => $block) {
  375. $blocks[$key] = array(
  376. 'info' => $block['title'],
  377. 'cache' => DRUPAL_NO_CACHE,
  378. );
  379. }
  380. return $blocks;
  381. }
  382. /**
  383. * Implements hook_block_view().
  384. */
  385. function ds_extras_block_view($delta = '') {
  386. $data = drupal_static('ds_block_region');
  387. $region_blocks = variable_get('ds_extras_region_blocks', array());
  388. if (!empty($data[$delta])) {
  389. $block = array();
  390. $block['subject'] = $region_blocks[$delta]['title'];
  391. $block['content'] = $data[$delta];
  392. return $block;
  393. }
  394. }
  395. /**
  396. * Implements hook_ds_layout_region_alter().
  397. */
  398. function ds_extras_ds_layout_region_alter($context, &$region_info) {
  399. $region_blocks = variable_get('ds_extras_region_blocks', array());
  400. // Bail out if region_blocks is empty or we are working on default view mode.
  401. if (empty($region_blocks) || $context['view_mode'] == 'default') {
  402. return;
  403. }
  404. $entity_type = $context['entity_type'];
  405. $bundle = $context['bundle'];
  406. $view_mode = $context['view_mode'];
  407. foreach ($region_blocks as $block_key => $block) {
  408. if ($block['info'] == "{$entity_type}_{$bundle}_{$view_mode}") {
  409. $region_info['region_options'][$block_key] = $block['title'];
  410. if (isset($region_info['table_regions'])) {
  411. $region_info['table_regions'][$block_key] = array(
  412. 'title' => check_plain($block['title']),
  413. 'message' => t('No fields are displayed in this region'),
  414. );
  415. }
  416. }
  417. }
  418. }
  419. /**
  420. * Implements hook_field_extra_fields().
  421. */
  422. function ds_extras_field_extra_fields() {
  423. $extra = array();
  424. // Register a single field so fields for vd are
  425. // picked up nicely in the display overview form.
  426. if (variable_get('ds_extras_vd')) {
  427. ctools_include('export');
  428. $vd_settings = ctools_export_crud_load_all('ds_vd');
  429. foreach ($vd_settings as $vd) {
  430. $extra['ds_views'][$vd->vd] = array(
  431. 'display' => array(
  432. 'title' => array(
  433. 'label' => t('Title'),
  434. 'description' => t('Title'),
  435. 'weight' => 10,
  436. ),
  437. ),
  438. );
  439. }
  440. }
  441. if (variable_get('ds_extras_fields_extra')) {
  442. $fields = explode("\n", variable_get('ds_extras_fields_extra_list', FALSE));
  443. foreach ($fields as $field) {
  444. $field = trim($field);
  445. if (!empty($field)) {
  446. list($entity, $bundle, $field_name) = explode('|', $field);
  447. $extra[check_plain($entity)][check_plain($bundle)]['display'][$field_name] = array(
  448. 'label' => drupal_ucfirst(str_replace('_', ' ', check_plain($field_name))),
  449. 'description' => drupal_ucfirst(str_replace('_', ' ', check_plain($field_name))),
  450. 'weight' => 0,
  451. );
  452. }
  453. }
  454. }
  455. return $extra;
  456. }
  457. /**
  458. * Output flag.
  459. */
  460. function ds_extras_flags_add_flag_link($field) {
  461. return flag_create_link($field['properties']['flag'], $field['entity']->nid);
  462. }
  463. /**
  464. * Implements hook_preprocess_views_view().
  465. */
  466. function ds_extras_preprocess_view_layout(&$variables) {
  467. if ($layout = ds_get_layout('ds_views', $variables['view']->name . '-' . $variables['view']->current_display, 'default')) {
  468. $variables['elements']['#entity_type'] = $variables['#entity_type'] = 'ds_views';
  469. $variables['elements']['#bundle'] = $variables['#bundle'] = $variables['view']->name . '-' . $variables['view']->current_display;
  470. $variables['elements']['#view_mode'] = 'default';
  471. $variables['ds_views'] = $variables['view'];
  472. $variables['render_code_fields'] = TRUE;
  473. ds_field_attach_view_alter($variables, array('view_mode' => 'default', 'entity' => $variables['view']));
  474. // Special case for views function fields.
  475. if (isset($variables['view']->ds_vd)) {
  476. foreach ($variables['view']->ds_vd as $key => $value) {
  477. $variables[$key] = $value;
  478. }
  479. }
  480. // Don't remove the variables so we don't trigger notices.
  481. $variables['preprocess_keep'] = TRUE;
  482. ds_entity_variables($variables);
  483. if (isset($variables['#attached'])) {
  484. drupal_process_attached($variables);
  485. }
  486. }
  487. }
  488. /**
  489. * Function used for theming the views title, user name etc. Note that
  490. * this is a function so it can't be overridden by a phptemplate function.
  491. */
  492. function ds_vd_render_title_field($field) {
  493. $output = '';
  494. $formatter = explode('_', $field['formatter']);
  495. $tag = $formatter[2];
  496. $output = '<' . $tag . '>' . $field['entity']->get_title() . '</' . $tag . '>';
  497. // Views is a special case, we stack title on the entity.
  498. $field['entity']->preprocess_fields[] = 'title';
  499. $field['entity']->ds_vd['title'] = $output;
  500. }
  501. /**
  502. * Implements hook_entity_view_alter().
  503. */
  504. function ds_extras_entity_view_alter(&$build, $entity_type) {
  505. static $loaded = array();
  506. // If views and core doesn't send information along on the entity,
  507. // Display Suite doesn't have a context to render the layout.
  508. if (!isset($build['#entity_type']) || !isset($build['#bundle'])) {
  509. return;
  510. }
  511. $bundle = $build['#bundle'];
  512. $view_mode = $build['#view_mode'];
  513. if ($overridden_view_mode = ds_extras_get_view_mode()) {
  514. $view_mode = $overridden_view_mode;
  515. }
  516. $layout = ds_get_layout($entity_type, $bundle, $view_mode);
  517. // Page title options.
  518. if (variable_get('ds_extras_hide_page_title', FALSE)) {
  519. $page_title = &drupal_static('ds_page_title');
  520. if (isset($layout['settings']['hide_page_title']) && $layout['settings']['hide_page_title'] == 1 && ds_extras_is_entity_page_view($build, $entity_type)) {
  521. $page_title['title'] = '';
  522. }
  523. elseif (isset($layout['settings']['hide_page_title']) && $layout['settings']['hide_page_title'] == 2 && !empty($layout['settings']['page_option_title']) && ds_extras_is_entity_page_view($build, $entity_type)) {
  524. $contexts = array();
  525. $id = (arg(0) == 'taxonomy') ? arg(2) : arg(1);
  526. $entity = entity_load($entity_type, array($id));
  527. ds_create_entity_context($entity_type, $entity[$id], $contexts);
  528. $title = $layout['settings']['page_option_title'];
  529. $title = filter_xss_admin(ctools_context_keyword_substitute($title, array(), $contexts));
  530. $page_title['title'] = $title;
  531. $page_title['head_title'] = $title;
  532. }
  533. }
  534. // Disable blocks.
  535. if (isset($layout['settings']['hide_sidebars']) && !isset($loaded[$entity_type][$bundle][$view_mode])) {
  536. // Store the setting.
  537. $loaded[$entity_type][$bundle][$view_mode] = TRUE;
  538. // Disable blocks.
  539. if (isset($layout['settings']['hide_sidebars']) && $layout['settings']['hide_sidebars']) {
  540. ctools_set_no_blocks();
  541. }
  542. }
  543. }
  544. /**
  545. * Helper function to check if this is a page view.
  546. *
  547. * The page title option adds the ability to hide or override the page title.
  548. * However, it can't happen that an entity bleeds its page title to say a view
  549. * or the frontpage.
  550. *
  551. * See http://drupal.org/node/1526732 and http://drupal.org/node/1446554.
  552. */
  553. function ds_extras_is_entity_page_view($build, $entity_type) {
  554. switch ($entity_type) {
  555. case 'node':
  556. return node_is_page($build['#node']);
  557. break;
  558. case 'user':
  559. $page_account = menu_get_object('user');
  560. return (!empty($page_account) ? $page_account->uid == $build['#account']->uid : FALSE);
  561. break;
  562. case 'taxonomy_term':
  563. $page_term = menu_get_object('taxonomy_term', 2);
  564. return (!empty($page_term) ? $page_term->tid == $build['#term']->tid : FALSE);
  565. break;
  566. case 'profile2':
  567. return $build['#view_mode'] == 'page';
  568. break;
  569. }
  570. return FALSE;
  571. }
  572. /**
  573. * Implements hook_ds_field_theme_functions_info().
  574. */
  575. function ds_extras_ds_field_theme_functions_info() {
  576. return array(
  577. 'theme_field' => t('Drupal default'),
  578. 'theme_ds_field_reset' => t('Full Reset'),
  579. 'theme_ds_field_minimal' => t('Minimal'),
  580. 'theme_ds_field_expert' => t('Expert'),
  581. );
  582. }
  583. /**
  584. * Reset all HTML for the field.
  585. */
  586. function theme_ds_field_reset($variables) {
  587. $output = '';
  588. // Render the label.
  589. if (!$variables['label_hidden']) {
  590. $output .= '<div class="label-' . $variables['element']['#label_display'] . '">' . $variables['label'];
  591. if (!variable_get('ft-kill-colon', FALSE)) {
  592. $output .= ':&nbsp;';
  593. }
  594. $output .= '</div>';
  595. }
  596. // Render the items.
  597. foreach ($variables['items'] as $delta => $item) {
  598. $output .= drupal_render($item);
  599. }
  600. return $output;
  601. }
  602. /**
  603. * Provide minimal HTML for the field.
  604. */
  605. function theme_ds_field_minimal($variables) {
  606. $output = '';
  607. $config = $variables['ds-config'];
  608. $classes = isset($config['classes']) ? ' ' . $config['classes'] : '';
  609. // Add a simple wrapper.
  610. $output .= '<div class="field field-name-' . strtr($variables['element']['#field_name'], '_', '-') . $classes . '">';
  611. // Render the label.
  612. if (!$variables['label_hidden']) {
  613. $output .= '<div class="label-' . $variables['element']['#label_display'] . '">' . $variables['label'];
  614. if (!isset($config['lb-col'])) {
  615. $output .= ':&nbsp;';
  616. }
  617. $output .= '</div>';
  618. }
  619. // Render the items.
  620. foreach ($variables['items'] as $delta => $item) {
  621. $output .= drupal_render($item);
  622. }
  623. $output .="</div>";
  624. return $output;
  625. }
  626. /**
  627. * Custom output all HTML for the field.
  628. */
  629. function theme_ds_field_expert($variables) {
  630. $output = '';
  631. $config = $variables['ds-config'];
  632. // Render the label if it's not hidden.
  633. if (!$variables['label_hidden']) {
  634. $label_wrapper = isset($config['lb-el']) ? $config['lb-el'] : 'div';
  635. $class = array('label-' . $variables['element']['#label_display']);
  636. if (!empty($config['lb-cl'])) $class[] = $config['lb-cl'];
  637. $class = !empty($class) ? ' class="' . implode(' ', $class) . '"' : '';
  638. $attributes = array();
  639. if (!empty($config['lb-at'])) $attributes[] = $config['lb-at'];
  640. if (!empty($config['lb-def-at'])) $attributes[] = $variables['title_attributes'];
  641. $attributes = (!empty($attributes)) ? ' ' . implode(' ', $attributes) : '';
  642. $output .= '<' . $label_wrapper . $class . $attributes . '>' . $variables['label'];
  643. if (!isset($config['lb-col'])) $output .= ':&nbsp;';
  644. $output .= '</' . $label_wrapper . '>';
  645. }
  646. // Field items wrapper
  647. if (isset($config['fis'])) {
  648. $class = (!empty($config['fis-cl'])) ? ' class="' . $config['fis-cl'] . '"' : '';
  649. $attributes = array();
  650. if (!empty($config['fis-at'])) $attributes[] = $config['fis-at'];
  651. if (!empty($config['fis-def-at'])) $attributes[] = $variables['content_attributes'];
  652. $attributes = (!empty($attributes)) ? ' ' . implode(' ', $attributes) : '';
  653. $output .= '<' . $config['fis-el'] . $class . $attributes . '>';
  654. }
  655. // Render items.
  656. foreach ($variables['items'] as $delta => $item) {
  657. // Field item wrapper.
  658. if (isset($config['fi'])) {
  659. $class = array();
  660. if (!empty($config['fi-odd-even'])) {
  661. $class[] = $delta % 2 ? 'odd' : 'even';
  662. }
  663. if (!empty($config['fi-cl'])) {
  664. $class[] = $config['fi-cl'];
  665. }
  666. $class = !empty($class) ? ' class="'. implode(' ', $class) .'"' : '';
  667. $attributes = array();
  668. if (!empty($config['fi-at'])) {
  669. $attributes[] = token_replace($config['fi-at'], array($variables['element']['#entity_type'] => $variables['element']['#object']), array('clear' => TRUE));
  670. }
  671. if (!empty($config['fi-def-at'])) {
  672. $attributes[] = $variables['item_attributes'][$delta];
  673. }
  674. $attributes = (!empty($attributes)) ? ' ' . implode(' ', $attributes) : '';
  675. $output .= '<' . $config['fi-el'] . $class . $attributes .'>';
  676. }
  677. // Render field content.
  678. $output .= drupal_render($item);
  679. // Closing field item wrapper.
  680. if (isset($config['fi'])) {
  681. $output .= '</' . $config['fi-el'] . '>';
  682. }
  683. }
  684. // Closing field items wrapper.
  685. if (isset($config['fis'])) {
  686. $output .= '</' . $config['fis-el'] . '>';
  687. }
  688. // Outer wrapper.
  689. if (isset($config['ow'])) {
  690. $class = array();
  691. if (!empty($config['ow-cl'])) $class[] = $config['ow-cl'];
  692. if (!empty($config['ow-def-cl'])) $class[] = $variables['classes'];
  693. $class = (!empty($class)) ? ' class="' . implode(' ', $class) . '"' : '';
  694. $attributes = array();
  695. if (!empty($config['ow-at'])) $attributes[] = $config['ow-at'];
  696. if (!empty($config['ow-def-at'])) $attributes[] = $variables['attributes'];
  697. $attributes = (!empty($attributes)) ? ' ' . implode(' ', $attributes) : '';
  698. $output = '<' . $config['ow-el'] . $class . $attributes . '>' . $output . '</' . $config['ow-el'] . '>';
  699. }
  700. return $output;
  701. }
  702. /**
  703. * Implements hook_ds_field_settings_alter().
  704. */
  705. function ds_extras_ds_field_settings_alter(&$field_settings, $form, &$form_state) {
  706. $fields = $form_state['values']['fields'];
  707. $default_field_function = variable_get('ft-default', 'theme_field');
  708. $wrappers = array(
  709. 'ow' => t('Wrapper'),
  710. 'fis' => t('Field items'),
  711. 'fi' => t('Field item')
  712. );
  713. foreach ($fields as $key => $field) {
  714. // Make sure we need to save anything for this field.
  715. if (_ds_field_valid($key, $field, $form_state)) {
  716. continue;
  717. }
  718. // Get the values.
  719. $values = isset($form_state['formatter_settings'][$key]['ft']) ? $form_state['formatter_settings'][$key]['ft'] : array();
  720. if (empty($values)) {
  721. continue;
  722. }
  723. $field_settings[$key]['formatter_settings']['ft'] = array();
  724. // Theme output function.
  725. $function = isset($values['func']) ? $values['func'] : $default_field_function;
  726. if ($function != $default_field_function) {
  727. $field_settings[$key]['formatter_settings']['ft']['func'] = $function;
  728. }
  729. // Field classes.
  730. if ($function != 'theme_ds_field_expert' && $function != 'theme_ds_field_reset' && isset($values['classes'])) {
  731. $classes = is_array($values['classes']) ? implode(' ', $values['classes']) : $values['classes'];
  732. if (!empty($classes)) {
  733. $field_settings[$key]['formatter_settings']['ft']['classes'] = $classes;
  734. }
  735. }
  736. // Label.
  737. if (isset($form_state['values']['fields'][$key]['label']) && $form_state['values']['fields'][$key]['label'] != 'hidden') {
  738. if (!empty($values['lb'])) {
  739. $field_settings[$key]['formatter_settings']['ft']['lb'] = $values['lb'];
  740. }
  741. if (!(empty($values['lb-el'])) && $function == 'theme_ds_field_expert') {
  742. $field_settings[$key]['formatter_settings']['ft']['lb-el'] = check_plain($values['lb-el']);
  743. }
  744. if (!(empty($values['lb-cl'])) && $function == 'theme_ds_field_expert') {
  745. $field_settings[$key]['formatter_settings']['ft']['lb-cl'] = check_plain($values['lb-cl']);
  746. }
  747. if (!(empty($values['lb-at'])) && $function == 'theme_ds_field_expert') {
  748. $field_settings[$key]['formatter_settings']['ft']['lb-at'] = filter_xss($values['lb-at']);
  749. }
  750. if (!(empty($values['lb-def-at'])) && $function == 'theme_ds_field_expert') {
  751. $field_settings[$key]['formatter_settings']['ft']['lb-def-at'] = TRUE;
  752. }
  753. if (!(empty($values['lb-col']))) {
  754. $field_settings[$key]['formatter_settings']['ft']['lb-col'] = TRUE;
  755. }
  756. }
  757. // Custom field configuration.
  758. if ($function == 'theme_ds_field_expert') {
  759. foreach ($wrappers as $wrapper_key => $title) {
  760. if (!empty($values[$wrapper_key])) {
  761. // Enable.
  762. $field_settings[$key]['formatter_settings']['ft'][$wrapper_key] = TRUE;
  763. // Element.
  764. $field_settings[$key]['formatter_settings']['ft'][$wrapper_key . '-el'] = !(empty($values[$wrapper_key . '-el'])) ? check_plain($values[$wrapper_key . '-el']) : 'div';
  765. // Classes.
  766. $field_settings[$key]['formatter_settings']['ft'][$wrapper_key . '-cl'] = !(empty($values[$wrapper_key . '-cl'])) ? check_plain($values[$wrapper_key . '-cl']) : '';
  767. // Default Classes.
  768. if (in_array($wrapper_key, array('ow', 'lb'))) {
  769. $field_settings[$key]['formatter_settings']['ft'][$wrapper_key . '-def-cl'] = !(empty($values[$wrapper_key . '-def-cl'])) ? TRUE : FALSE;
  770. }
  771. // Attributes.
  772. $field_settings[$key]['formatter_settings']['ft'][$wrapper_key . '-at'] = !(empty($values[$wrapper_key . '-at'])) ? filter_xss($values[$wrapper_key . '-at']) : '';
  773. // Default attributes.
  774. $field_settings[$key]['formatter_settings']['ft'][$wrapper_key . '-def-at'] = !(empty($values[$wrapper_key . '-def-at'])) ? TRUE : FALSE;
  775. // Odd even class.
  776. if ($wrapper_key == 'fi') {
  777. $field_settings[$key]['formatter_settings']['ft'][$wrapper_key . '-odd-even'] = !(empty($values[$wrapper_key . '-odd-even'])) ? TRUE : FALSE;
  778. }
  779. }
  780. }
  781. }
  782. }
  783. }
  784. /**
  785. * Implements hook_preprocess_field().
  786. */
  787. function ds_extras_preprocess_field(&$variables) {
  788. // We need to be sure this field is in a layout which is rendered by DS.
  789. if (!ds_get_layout($variables['element']['#entity_type'], $variables['element']['#bundle'], $variables['element']['#view_mode'])) {
  790. return;
  791. }
  792. $entity_type = $variables['element']['#entity_type'];
  793. $bundle = $variables['element']['#bundle'];
  794. $view_mode = $variables['element']['#view_mode'];
  795. $config = array();
  796. static $field_settings = array();
  797. if (!isset($field_settings[$entity_type][$bundle][$view_mode])) {
  798. $layout = ds_get_layout($entity_type, $bundle, $view_mode);
  799. $field_settings[$entity_type][$bundle][$view_mode] = ds_get_field_settings($entity_type, $bundle, $view_mode);
  800. }
  801. // Get the field name and field instance info - if available.
  802. $field_name = $variables['element']['#field_name'];
  803. $field_instance_info = field_info_instance($entity_type, $field_name, $bundle);
  804. // Check if this field has custom output settings.
  805. $variables['ds-config'] = array();
  806. if (isset($field_settings[$entity_type][$bundle][$view_mode][$field_name]['formatter_settings']['ft'])) {
  807. $config = $field_settings[$entity_type][$bundle][$view_mode][$field_name]['formatter_settings']['ft'];
  808. $variables['ds-config'] = $config;
  809. }
  810. // CSS classes
  811. if (isset($config['classes'])) {
  812. $variables['classes_array'][] = $config['classes'];
  813. }
  814. // Alter the label if configured.
  815. if (!$variables['label_hidden']) {
  816. if (isset($config['lb'])) {
  817. $variables['label'] = t(check_plain($config['lb']));
  818. }
  819. }
  820. // Determine the field template. In case it's something different
  821. // than theme_field, we'll add that function as a suggestion.
  822. if (isset($config['func']) && $config['func'] != 'theme_field') {
  823. $variables['ds-config'] = $config;
  824. $variables['theme_hook_suggestions'] = array();
  825. // Either it uses the function.
  826. $variables['theme_hook_suggestions'][] = $config['func'];
  827. // Or the template file(s).
  828. $suggestion = 'field__' . str_replace('theme_ds_field_', '', $config['func']);
  829. $variables['theme_hook_suggestions'][] = $suggestion;
  830. $variables['theme_hook_suggestions'][] = $suggestion . '__' . $field_name;
  831. $variables['theme_hook_suggestions'][] = $suggestion . '__' . $variables['element']['#bundle'];
  832. $variables['theme_hook_suggestions'][] = $suggestion . '__' . $field_name . '__' . $variables['element']['#bundle'];
  833. }
  834. // Check if we have a default field template on instance level.
  835. elseif (isset($field_instance_info['ds_extras_field_template']) && !empty($field_instance_info['ds_extras_field_template']) && $field_instance_info['ds_extras_field_template'] != 'theme_field') {
  836. $variables['theme_hook_suggestions'] = array();
  837. // Either it uses the function.
  838. $variables['theme_hook_suggestions'][] = $field_instance_info['ds_extras_field_template'];
  839. // Or the template file(s).
  840. $suggestion = 'field__' . str_replace('theme_ds_field_', '', $field_instance_info['ds_extras_field_template']);
  841. $variables['theme_hook_suggestions'][] = $suggestion;
  842. $variables['theme_hook_suggestions'][] = $suggestion . '__' . $field_name;
  843. $variables['theme_hook_suggestions'][] = $suggestion . '__' . $variables['element']['#bundle'];
  844. $variables['theme_hook_suggestions'][] = $suggestion . '__' . $field_name . '__' . $variables['element']['#bundle'];
  845. }
  846. // Use Display Suite Extras Default theming function.
  847. elseif (!isset($config['func']) || empty($config['func'])) {
  848. $field_theme_function = variable_get('ft-default', 'theme_field');
  849. if ($field_theme_function != 'theme_field') {
  850. $variables['theme_hook_suggestions'] = array();
  851. $variables['ds-config'] = $config;
  852. // Either it uses the function.
  853. $variables['theme_hook_suggestions'][] = $field_theme_function;
  854. // Or the template file(s).
  855. $suggestion = 'field__' . str_replace('theme_ds_field_', '', $field_theme_function);
  856. $variables['theme_hook_suggestions'][] = $suggestion;
  857. $variables['theme_hook_suggestions'][] = $suggestion . '__' . $field_name;
  858. $variables['theme_hook_suggestions'][] = $suggestion . '__' . $variables['element']['#bundle'];
  859. $variables['theme_hook_suggestions'][] = $suggestion . '__' . $field_name . '__' . $variables['element']['#bundle'];
  860. }
  861. }
  862. }
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.