ds_extras.vd.inc

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

Views displays functions.

Functions

Namesort descending Description
ds_extras_ds_fields_ui_alter Implements hook_ds_fields_ui_alter().
ds_extras_vd_bundle_form Return the views select form to create a bundle.
ds_extras_vd_bundle_form_submit Submit callback: save the new bundle.
ds_extras_vd_bundle_remove Return confirm form to remove a views bundle
ds_extras_vd_bundle_remove_submit Submit callback: remove a views bundle
ds_extras_vd_field_ui Return Field UI display screen for a view and bundle.
ds_extras_vd_manage Edit the display or remove a views display.
ds_extras_vd_overview Show the overview form and the selection list.

File

sites/all/modules/ulmus/ds/modules/ds_extras/includes/ds_extras.vd.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Views displays functions.
  5. */
  6. /**
  7. * Show the overview form and the selection list.
  8. */
  9. function ds_extras_vd_overview() {
  10. $entity_info = entity_get_info('ds_views');
  11. $build = $rows = array();
  12. ctools_include('export');
  13. $vd_settings = ctools_export_crud_load_all('ds_vd');
  14. if ($entity_info) {
  15. foreach ($entity_info['bundles'] as $key => $value) {
  16. // If no initial bundles were created, entity API will create
  17. // one by default, so make sure we do not list that one.
  18. if ($key == 'ds_views') {
  19. continue;
  20. }
  21. $row = array();
  22. $row[] = $value['label'];
  23. $operations = l(t('Manage layout'), 'admin/structure/ds/vd/manage/' . $key . '/display');
  24. if (isset($vd_settings[$key]) && $vd_settings[$key]->export_type == 1) {
  25. $operations .= ' - ' . l(t('Remove'), 'admin/structure/ds/vd/manage/' . $key . '/remove');
  26. }
  27. $row[] = $operations;
  28. $rows[$key] = $row;
  29. }
  30. }
  31. if (empty($rows)) {
  32. $rows = array(
  33. array(array('data' => t('No views selected.'), 'colspan' => '2')),
  34. );
  35. }
  36. $variables = array(
  37. 'header' => array(t('Title'), t('Operations')),
  38. 'rows' => $rows,
  39. );
  40. $build['list'] = array('#markup' => theme('table', $variables));
  41. $build['form'] = drupal_get_form('ds_extras_vd_bundle_form', $rows);
  42. return $build;
  43. }
  44. /**
  45. * Return the views select form to create a bundle.
  46. */
  47. function ds_extras_vd_bundle_form($form, $form_state, $rows) {
  48. $options = array();
  49. $views = views_get_all_views();
  50. foreach ($views as $view_key => $view) {
  51. // Ignore disabled views.
  52. if (isset($view->disabled) && $view->disabled) {
  53. continue;
  54. }
  55. $get_view = views_get_view($view->name);
  56. // Loop through all displays.
  57. foreach ($view->display as $display_key => $display) {
  58. // Ignore default displays.
  59. if ($display_key == 'default') {
  60. continue;
  61. }
  62. $key = $view_key . '-' . $display_key;
  63. $name = drupal_ucfirst($view->name) . ': ' . $display->display_title;
  64. if (!isset($rows[$key])) {
  65. $options[$key] = $name . ' (Views template)';
  66. }
  67. $get_view->set_display($display_key);
  68. if ($get_view->display_handler->uses_fields() && !isset($rows[$key . '-fields'])) {
  69. $options[$key . '-fields'] = $name . ' (Fields)';
  70. }
  71. }
  72. }
  73. $form['vd'] = array(
  74. '#title' => t('Select view'),
  75. '#description' => t('Select a View that you want to manage with Display Suite. If a View uses fields you can also select that view to select a layout and position the fields. Note that html for the label and field are limited.'),
  76. '#type' => 'select',
  77. '#options' => $options,
  78. );
  79. $form['submit'] = array(
  80. '#type' => 'submit',
  81. '#value' => t('Add'),
  82. );
  83. return $form;
  84. }
  85. /**
  86. * Submit callback: save the new bundle.
  87. */
  88. function ds_extras_vd_bundle_form_submit($form, &$form_state) {
  89. // Save new bundle.
  90. $record = new stdClass();
  91. $record->vd = $form_state['values']['vd'];
  92. $record->label = $form['vd']['#options'][$record->vd];
  93. drupal_write_record('ds_vd', $record);
  94. // Clear entity cache and field info fields cache.
  95. cache_clear_all('field_info_fields', 'cache_field');
  96. cache_clear_all('entity_info', 'cache', TRUE);
  97. // Message and redirect.
  98. drupal_set_message(t('Bundle @label has been added.', array('@label' => $record->label)));
  99. $form_state['redirect'] = 'admin/structure/ds/vd';
  100. }
  101. /**
  102. * Edit the display or remove a views display.
  103. *
  104. * @param $bundle
  105. * The name of the bundle
  106. * @param $action
  107. * The action to take (edit or remove)
  108. */
  109. function ds_extras_vd_manage($bundle = '', $action = '') {
  110. $entity_info = entity_get_info('ds_views');
  111. if (!empty($bundle) && isset($entity_info['bundles'][$bundle]) && $action == 'remove') {
  112. return drupal_get_form('ds_extras_vd_bundle_remove', $bundle, $entity_info['bundles'][$bundle]['label']);
  113. }
  114. if (!empty($bundle) && isset($entity_info['bundles'][$bundle]) && $action == 'display') {
  115. return ds_extras_vd_field_ui($bundle);
  116. }
  117. // Redirect to overview.
  118. drupal_set_message(t('No view found to layout.'));
  119. drupal_goto('admin/structure/ds/vd');
  120. }
  121. /**
  122. * Return Field UI display screen for a view and bundle.
  123. *
  124. * @param $bundle
  125. * The name of the bundle
  126. */
  127. function ds_extras_vd_field_ui($bundle) {
  128. global $conf;
  129. // Use drupal_build_form instead of drupal_get_form.
  130. $form_state = array();
  131. $arguments = array('ds_views', $bundle, 'default');
  132. $form_state['build_info']['args'] = $arguments;
  133. $form_state['no_view_mode_suggestions'] = TRUE;
  134. $form_state['no_panels'] = TRUE;
  135. form_load_include($form_state, 'inc', 'field_ui', 'field_ui.admin');
  136. form_load_include($form_state, 'inc', 'ds_extras', 'includes/ds_extras.vd');
  137. // Deny access to field_group if it exists.
  138. if (module_exists('field_group')) {
  139. $form_state['no_field_group'] = TRUE;
  140. }
  141. // Build form.
  142. $build = drupal_build_form('field_ui_display_overview_form', $form_state);
  143. // Deny access to view modes.
  144. $build['additional_settings']['modes']['#access'] = FALSE;
  145. // Deny access to disabling blocks and regions.
  146. $build['additional_settings']['ds_layouts']['hide_sidebars']['#access'] = FALSE;
  147. // Deny access to fields table if there's no layout.
  148. if (!ds_get_layout('ds_views', $bundle, 'default')) {
  149. $build['fields']['#access'] = FALSE;
  150. }
  151. // Add additional validate function so we can remove notices.
  152. if (module_exists('field_group')) {
  153. array_unshift($build['#validate'], 'ds_vd_field_ui_fix_notices');
  154. }
  155. return $build;
  156. }
  157. /**
  158. * Implements hook_ds_fields_ui_alter().
  159. */
  160. function ds_extras_ds_fields_ui_alter(&$fields, $context) {
  161. // Check on the $bundle string to see if the key 2 exists. If it exists,
  162. // we'll call the view to put the fields of this view on and remove
  163. // the fields which comes default by ds_extras_field_extra_fields()
  164. // and only work for the views template.
  165. $bundle = $context['bundle'];
  166. $fields_check = explode('-', $bundle);
  167. if (isset($fields_check[2])) {
  168. $field_copy = array(
  169. 'title' => 'dummy',
  170. 'field_type' => DS_FIELD_TYPE_IGNORE,
  171. );
  172. // Remove the view template fields.
  173. $remove_fields = ds_extras_ds_fields_info('ds_views');
  174. foreach ($remove_fields['ds_views'] as $key => $properties) {
  175. unset($fields[$key]);
  176. }
  177. // Get the view and its fields.
  178. $view = views_get_view($fields_check[0]);
  179. $view->set_display($fields_check[1]);
  180. $fields = $view->display_handler->get_field_labels();
  181. foreach ($fields as $field_key => $field_label) {
  182. $field_properties = $field_copy;
  183. $field_properties['title'] = $field_label;
  184. $fields[$field_key] = $field_properties;
  185. }
  186. }
  187. }
  188. /**
  189. * Return confirm form to remove a views bundle
  190. */
  191. function ds_extras_vd_bundle_remove($form, $form_state, $bundle, $label) {
  192. $form['#bundle'] = $bundle;
  193. $form['#label'] = $label;
  194. return confirm_form($form, t('Are you sure you want to remove bundle @label ?', array('@label' => $label)), 'admin/structure/ds/vd');
  195. }
  196. /**
  197. * Submit callback: remove a views bundle
  198. */
  199. function ds_extras_vd_bundle_remove_submit($form, &$form_state) {
  200. $bundle = $form['#bundle'];
  201. $label = $form['#label'];
  202. // Remove bundle.
  203. db_delete('ds_vd')
  204. ->condition('vd', $bundle)
  205. ->execute();
  206. // Remove layout.
  207. db_delete('ds_layout_settings')
  208. ->condition('bundle', $bundle)
  209. ->execute();
  210. // Remove settings.
  211. db_delete('ds_field_settings')
  212. ->condition('bundle', $bundle)
  213. ->execute();
  214. // Remove from bundle settings.
  215. variable_del('field_bundle_settings_ds_views__' . $bundle);
  216. // Clear entity cache and field info fields cache.
  217. cache_clear_all('field_info_fields', 'cache_field');
  218. cache_clear_all('entity_info', 'cache', TRUE);
  219. drupal_set_message(t('Bundle @label has been removed.', array('@label' => $label)));
  220. }