tripal_views_handler_area_action_links.inc 5.1 KB

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