views_ui_node_views_wizard.class.php

Definition of ViewsUiNodeViewsWizard.

File

plugins/views_wizard/views_ui_node_views_wizard.class.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of ViewsUiNodeViewsWizard.
  5. */
  6. /**
  7. * Tests creating node views with the wizard.
  8. */
  9. class ViewsUiNodeViewsWizard extends ViewsUiBaseViewsWizard {
  10. protected function row_style_options($type) {
  11. $options = array();
  12. $options['teasers'] = t('teasers');
  13. $options['full_posts'] = t('full posts');
  14. $options['titles'] = t('titles');
  15. $options['titles_linked'] = t('titles (linked)');
  16. $options['fields'] = t('fields');
  17. return $options;
  18. }
  19. protected function build_form_style(&$form, &$form_state, $type) {
  20. parent::build_form_style($form, $form_state, $type);
  21. $style_form =& $form['displays'][$type]['options']['style'];
  22. // Some style plugins don't support row plugins so stop here if that's the
  23. // case.
  24. if (!isset($style_form['row_plugin']['#default_value'])) {
  25. return;
  26. }
  27. $row_plugin = $style_form['row_plugin']['#default_value'];
  28. switch ($row_plugin) {
  29. case 'full_posts':
  30. case 'teasers':
  31. $style_form['row_options']['links'] = array(
  32. '#type' => 'select',
  33. '#title_display' => 'invisible',
  34. '#title' => t('Should links be displayed below each node'),
  35. '#options' => array(
  36. 1 => t('with links (allow users to add comments, etc.)'),
  37. 0 => t('without links'),
  38. ),
  39. '#default_value' => 1,
  40. );
  41. $style_form['row_options']['comments'] = array(
  42. '#type' => 'select',
  43. '#title_display' => 'invisible',
  44. '#title' => t('Should comments be displayed below each node'),
  45. '#options' => array(
  46. 1 => t('with comments'),
  47. 0 => t('without comments'),
  48. ),
  49. '#default_value' => 0,
  50. );
  51. break;
  52. }
  53. }
  54. /**
  55. * @override
  56. */
  57. protected function default_display_options($form, $form_state) {
  58. $display_options = parent::default_display_options($form, $form_state);
  59. // Add permission-based access control.
  60. $display_options['access']['type'] = 'perm';
  61. // Remove the default fields, since we are customizing them here.
  62. unset($display_options['fields']);
  63. // Add the title field, so that the display has content if the user switches
  64. // to a row style that uses fields.
  65. /* Field: Content: Title */
  66. $display_options['fields']['title']['id'] = 'title';
  67. $display_options['fields']['title']['table'] = 'node';
  68. $display_options['fields']['title']['field'] = 'title';
  69. $display_options['fields']['title']['label'] = '';
  70. $display_options['fields']['title']['alter']['alter_text'] = 0;
  71. $display_options['fields']['title']['alter']['make_link'] = 0;
  72. $display_options['fields']['title']['alter']['absolute'] = 0;
  73. $display_options['fields']['title']['alter']['trim'] = 0;
  74. $display_options['fields']['title']['alter']['word_boundary'] = 0;
  75. $display_options['fields']['title']['alter']['ellipsis'] = 0;
  76. $display_options['fields']['title']['alter']['strip_tags'] = 0;
  77. $display_options['fields']['title']['alter']['html'] = 0;
  78. $display_options['fields']['title']['hide_empty'] = 0;
  79. $display_options['fields']['title']['empty_zero'] = 0;
  80. $display_options['fields']['title']['link_to_node'] = 1;
  81. return $display_options;
  82. }
  83. protected function page_display_options($form, $form_state) {
  84. $display_options = parent::page_display_options($form, $form_state);
  85. $row_plugin = isset($form_state['values']['page']['style']['row_plugin']) ? $form_state['values']['page']['style']['row_plugin'] : NULL;
  86. $row_options = isset($form_state['values']['page']['style']['row_options']) ? $form_state['values']['page']['style']['row_options'] : array();
  87. $this->display_options_row($display_options, $row_plugin, $row_options);
  88. return $display_options;
  89. }
  90. protected function block_display_options($form, $form_state) {
  91. $display_options = parent::block_display_options($form, $form_state);
  92. $row_plugin = isset($form_state['values']['block']['style']['row_plugin']) ? $form_state['values']['block']['style']['row_plugin'] : NULL;
  93. $row_options = isset($form_state['values']['block']['style']['row_options']) ? $form_state['values']['block']['style']['row_options'] : array();
  94. $this->display_options_row($display_options, $row_plugin, $row_options);
  95. return $display_options;
  96. }
  97. /**
  98. * Set the row style and row style plugins to the display_options.
  99. */
  100. protected function display_options_row(&$display_options, $row_plugin, $row_options) {
  101. switch ($row_plugin) {
  102. case 'full_posts':
  103. $display_options['row_plugin'] = 'node';
  104. $display_options['row_options']['build_mode'] = 'full';
  105. $display_options['row_options']['links'] = !empty($row_options['links']);
  106. $display_options['row_options']['comments'] = !empty($row_options['comments']);
  107. break;
  108. case 'teasers':
  109. $display_options['row_plugin'] = 'node';
  110. $display_options['row_options']['build_mode'] = 'teaser';
  111. $display_options['row_options']['links'] = !empty($row_options['links']);
  112. $display_options['row_options']['comments'] = !empty($row_options['comments']);
  113. break;
  114. case 'titles_linked':
  115. $display_options['row_plugin'] = 'fields';
  116. $display_options['field']['title']['link_to_node'] = 1;
  117. break;
  118. case 'titles':
  119. $display_options['row_plugin'] = 'fields';
  120. $display_options['field']['title']['link_to_node'] = 0;
  121. break;
  122. }
  123. }
  124. }