tripal_views_handler_area_action_links.inc

  1. 2.x tripal_views/views/handlers/tripal_views_handler_area_action_links.inc
  2. 3.x tripal_chado_views/views/handlers/tripal_views_handler_area_action_links.inc

Contains tripal_views_handler_area_action_links Area Handler

File

tripal_views/views/handlers/tripal_views_handler_area_action_links.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Contains tripal_views_handler_area_action_links Area Handler
  5. */
  6. /**
  7. * Provides an area for adding action links to a view.
  8. *
  9. * @ingroup tripal_views
  10. */
  11. class tripal_views_handler_area_action_links extends views_handler_area {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. function option_definition() {
  16. $options = parent::option_definition();
  17. $options['link-1']['label-1'] = array('default' => '');
  18. $options['link-1']['path-1'] = array('default' => '');
  19. $options['link-2']['label-2'] = array('default' => '');
  20. $options['link-2']['path-2'] = array('default' => '');
  21. $options['link-3']['label-3'] = array('default' => '');
  22. $options['link-3']['path-3'] = array('default' => '');
  23. $options['link-4']['label-4'] = array('default' => '');
  24. $options['link-4']['path-4'] = array('default' => '');
  25. return $options;
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. function options_form(&$form, &$form_state) {
  31. parent::options_form($form, $form_state);
  32. $form['label']['#default_value'] = 'Action Links';
  33. $form['link-1'] = array(
  34. '#type' => 'fieldset',
  35. '#title' => t('Link #1')
  36. );
  37. $form['link-1']['label-1'] = array(
  38. '#type' => 'textfield',
  39. '#title' => t('Label'),
  40. '#description' => t('The text that will be displayed as the link'),
  41. '#default_value' => $this->options['link-1']['label-1'],
  42. );
  43. $form['link-1']['path-1'] = array(
  44. '#type' => 'textfield',
  45. '#title' => t('URL'),
  46. '#description' => t('The path that the link will link to'),
  47. '#default_value' => $this->options['link-1']['path-1']
  48. );
  49. $form['link-2'] = array(
  50. '#type' => 'fieldset',
  51. '#title' => t('Link #2')
  52. );
  53. $form['link-2']['label-2'] = array(
  54. '#type' => 'textfield',
  55. '#title' => t('Label'),
  56. '#description' => t('The text that will be displayed as the link'),
  57. '#default_value' => $this->options['link-2']['label-2'],
  58. );
  59. $form['link-2']['path-2'] = array(
  60. '#type' => 'textfield',
  61. '#title' => t('URL'),
  62. '#description' => t('The path that the link will link to'),
  63. '#default_value' => $this->options['link-2']['path-2']
  64. );
  65. $form['link-3'] = array(
  66. '#type' => 'fieldset',
  67. '#title' => t('Link #3')
  68. );
  69. $form['link-3']['label-3'] = array(
  70. '#type' => 'textfield',
  71. '#title' => t('Label'),
  72. '#description' => t('The text that will be displayed as the link'),
  73. '#default_value' => $this->options['link-3']['label-3'],
  74. );
  75. $form['link-3']['path-3'] = array(
  76. '#type' => 'textfield',
  77. '#title' => t('URL'),
  78. '#description' => t('The path that the link will link to'),
  79. '#default_value' => $this->options['link-3']['path-3']
  80. );
  81. $form['link-4'] = array(
  82. '#type' => 'fieldset',
  83. '#title' => t('Link #4')
  84. );
  85. $form['link-4']['label-4'] = array(
  86. '#type' => 'textfield',
  87. '#title' => t('Label'),
  88. '#description' => t('The text that will be displayed as the link'),
  89. '#default_value' => $this->options['link-4']['label-4'],
  90. );
  91. $form['link-4']['path-4'] = array(
  92. '#type' => 'textfield',
  93. '#title' => t('URL'),
  94. '#description' => t('The path that the link will link to'),
  95. '#default_value' => $this->options['link-4']['path-4']
  96. );
  97. }
  98. /**
  99. * {@inheritdoc}
  100. */
  101. function options_submit(&$form, &$form_state) {
  102. parent::options_submit($form, $form_state);
  103. //ddl($form_state, 'form state in submit');
  104. $this->options['link-1']['label-1'] = $form_state['values']['options']['link-1']['label-1'];
  105. $this->options['link-1']['path-1'] = $form_state['values']['options']['link-1']['path-1'];
  106. $this->options['link-2']['label-2'] = $form_state['values']['options']['link-2']['label-2'];
  107. $this->options['link-2']['path-2'] = $form_state['values']['options']['link-2']['path-2'];
  108. $this->options['link-3']['label-3'] = $form_state['values']['options']['link-3']['label-3'];
  109. $this->options['link-3']['path-3'] = $form_state['values']['options']['link-3']['path-3'];
  110. $this->options['link-4']['label-4'] = $form_state['values']['options']['link-4']['label-4'];
  111. $this->options['link-4']['path-4'] = $form_state['values']['options']['link-4']['path-4'];
  112. }
  113. /**
  114. * {@inheritdoc}
  115. */
  116. function render($empty = FALSE) {
  117. if (!$empty || !empty($this->options['empty'])) {
  118. $output = '<ul class="action-links">';
  119. // First link
  120. if (!empty($this->options['link-1']['label-1']) AND !empty($this->options['link-1']['path-1'])) {
  121. $output .= '<li>' . l($this->options['link-1']['label-1'], $this->options['link-1']['path-1']) . '</li>';
  122. }
  123. // Second link
  124. if (!empty($this->options['link-2']['label-2']) AND !empty($this->options['link-2']['path-2'])) {
  125. $output .= '<li>' . l($this->options['link-2']['label-2'], $this->options['link-2']['path-2']) . '</li>';
  126. }
  127. // Third link
  128. if (!empty($this->options['link-3']['label-3']) AND !empty($this->options['link-3']['path-3'])) {
  129. $output .= '<li>' . l($this->options['link-3']['label-3'], $this->options['link-3']['path-3']) . '</li>';
  130. }
  131. // Fourth link
  132. if (!empty($this->options['link-4']['label-4']) AND !empty($this->options['link-4']['path-4'])) {
  133. $output .= '<li>' . l($this->options['link-4']['label-4'], $this->options['link-4']['path-4']) . '</li>';
  134. }
  135. $output .= '</ul>';
  136. return $output;
  137. }
  138. return '';
  139. }
  140. }