tripal_views_handler_field_entity_link_edit.inc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. class tripal_views_handler_field_entity_link_edit extends tripal_views_handler_field {
  3. function option_definition() {
  4. $options = parent::option_definition();
  5. $options['text'] = array('default' => '', 'translatable' => TRUE);
  6. return $options;
  7. }
  8. function options_form(&$form, &$form_state) {
  9. $form['text'] = array(
  10. '#type' => 'textfield',
  11. '#title' => t('Text to display'),
  12. '#default_value' => $this->options['text'],
  13. );
  14. parent::options_form($form, $form_state);
  15. // The path is set by render_link function so don't allow to set it.
  16. $form['alter']['path'] = array('#access' => FALSE);
  17. $form['alter']['external'] = array('#access' => FALSE);
  18. }
  19. function render($values) {
  20. if ($entity = $this->get_value($values)) {
  21. return $this->render_link($entity, $values);
  22. }
  23. }
  24. function render_link($entity, $values) {
  25. if (entity_access('edit', 'TripalEntity', $entity)) {
  26. $this->options['alter']['make_link'] = TRUE;
  27. $this->options['alter']['path'] = 'bio_data/' . $entity->id . '/edit';
  28. $text = !empty($this->options['text']) ? $this->options['text'] : t('view');
  29. return $text;
  30. }
  31. }
  32. }