views_handler_area.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_area and views_handler_area_broken.
  5. */
  6. /**
  7. * @defgroup views_area_handlers Views area handlers
  8. * @{
  9. * Handlers to tell Views what can display in header, footer
  10. * and empty text in a view.
  11. */
  12. /**
  13. * Base class for area handlers.
  14. *
  15. * @ingroup views_area_handlers
  16. */
  17. class views_handler_area extends views_handler {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function init(&$view, &$options) {
  22. parent::init($view, $options);
  23. // Make sure that no result area handlers are set to be shown when the
  24. // result is empty.
  25. if ($this->handler_type == 'empty') {
  26. $this->options['empty'] = TRUE;
  27. }
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function label() {
  33. if (!isset($this->options['label'])) {
  34. return $this->ui_name();
  35. }
  36. return $this->options['label'];
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function option_definition() {
  42. $options = parent::option_definition();
  43. $this->definition['field'] = !empty($this->definition['field']) ? $this->definition['field'] : '';
  44. $label = !empty($this->definition['label']) ? $this->definition['label'] : $this->definition['field'];
  45. $options['label'] = array('default' => $label, 'translatable' => TRUE);
  46. $options['empty'] = array('default' => FALSE, 'bool' => TRUE);
  47. return $options;
  48. }
  49. /**
  50. * Provide extra data to the administration form.
  51. */
  52. public function admin_summary() {
  53. return $this->label();
  54. }
  55. /**
  56. * Default options form that provides the label widget that all fields should
  57. * have.
  58. */
  59. public function options_form(&$form, &$form_state) {
  60. parent::options_form($form, $form_state);
  61. $form['label'] = array(
  62. '#type' => 'textfield',
  63. '#title' => t('Label'),
  64. '#default_value' => isset($this->options['label']) ? $this->options['label'] : '',
  65. '#description' => t('The label for this area that will be displayed only administratively.'),
  66. );
  67. if ($form_state['type'] != 'empty') {
  68. $form['empty'] = array(
  69. '#type' => 'checkbox',
  70. '#title' => t('Display even if view has no result'),
  71. '#default_value' => isset($this->options['empty']) ? $this->options['empty'] : 0,
  72. );
  73. }
  74. }
  75. /**
  76. * Don't run a query.
  77. */
  78. public function query() {
  79. }
  80. /**
  81. * Render the area.
  82. */
  83. public function render($empty = FALSE) {
  84. return '';
  85. }
  86. /**
  87. * Area handlers shouldn't have groupby.
  88. */
  89. public function use_group_by() {
  90. return FALSE;
  91. }
  92. }
  93. /**
  94. * A special handler to take the place of missing or broken handlers.
  95. *
  96. * @ingroup views_area_handlers
  97. */
  98. class views_handler_area_broken extends views_handler_area {
  99. /**
  100. * {@inheritdoc}
  101. */
  102. public function ui_name($short = FALSE) {
  103. return t('Broken/missing handler');
  104. }
  105. /**
  106. * {@inheritdoc}
  107. */
  108. public function ensure_my_table() {
  109. // No table to ensure!
  110. }
  111. /**
  112. * {@inheritdoc}
  113. */
  114. public function query($group_by = FALSE) {
  115. // No query to run.
  116. }
  117. /**
  118. * {@inheritdoc}
  119. */
  120. public function render($empty = FALSE) {
  121. return '';
  122. }
  123. /**
  124. * {@inheritdoc}
  125. */
  126. public function options_form(&$form, &$form_state) {
  127. $form['markup'] = array(
  128. '#prefix' => '<div class="form-item description">',
  129. '#value' => t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.'),
  130. );
  131. }
  132. /**
  133. * {@inheritdoc}
  134. */
  135. public function broken() {
  136. return TRUE;
  137. }
  138. }
  139. /**
  140. * @}
  141. */