redirect_handler_field_redirect_operations.inc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @file
  4. * Redirect field handler for redirect operations.
  5. */
  6. class redirect_handler_field_redirect_operations extends views_handler_field {
  7. function construct() {
  8. parent::construct();
  9. $this->additional_fields['rid'] = 'rid';
  10. }
  11. function option_definition() {
  12. $options = parent::option_definition();
  13. $options['edit_text'] = array('default' => '', 'translatable' => TRUE);
  14. $options['delete_text'] = array('default' => '', 'translatable' => TRUE);
  15. return $options;
  16. }
  17. function options_form(&$form, &$form_state) {
  18. parent::options_form($form, $form_state);
  19. $form['edit_text'] = array(
  20. '#type' => 'textfield',
  21. '#title' => t('Text to display for edit links'),
  22. '#default_value' => $this->options['edit_text'],
  23. );
  24. $form['delete_text'] = array(
  25. '#type' => 'textfield',
  26. '#title' => t('Text to display for delete links'),
  27. '#default_value' => $this->options['delete_text'],
  28. );
  29. }
  30. function query() {
  31. $this->ensure_my_table();
  32. $this->add_additional_fields();
  33. }
  34. function render($values) {
  35. $rid = $values->{$this->aliases['rid']};
  36. $redirect = redirect_load($rid);
  37. $destination = drupal_get_destination();
  38. $operations = array();
  39. if (redirect_access('update', $redirect)) {
  40. $operations['edit'] = array(
  41. 'title' => !empty($this->options['edit_text']) ? $this->options['edit_text'] : t('Edit'),
  42. 'href' => 'admin/config/search/redirect/edit/' . $rid,
  43. 'query' => $destination,
  44. );
  45. }
  46. if (redirect_access('delete', $redirect)) {
  47. $operations['delete'] = array(
  48. 'title' => !empty($this->options['delete_text']) ? $this->options['delete_text'] : t('Delete'),
  49. 'href' => 'admin/config/search/redirect/delete/' . $rid,
  50. 'query' => $destination,
  51. );
  52. }
  53. if (!empty($operations)) {
  54. return theme('links', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline', 'nowrap'))));
  55. }
  56. else {
  57. return '';
  58. }
  59. }
  60. }