uc_shipping_handler_field_shipment_id.inc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @file
  4. * Shipment ID field handler.
  5. */
  6. /**
  7. * Field handler: simple renderer that links to the shipment page.
  8. */
  9. class uc_shipping_handler_field_shipment_id extends views_handler_field {
  10. /**
  11. * Override init function to provide generic option to link to shipment.
  12. */
  13. function init(&$view, &$data) {
  14. parent::init($view, $data);
  15. if (!empty($this->options['link_to_shipment'])) {
  16. $this->additional_fields['order_id'] = array('table' => $this->table_alias, 'field' => 'order_id');
  17. }
  18. }
  19. /**
  20. * Overrides views_handler::option_definition().
  21. */
  22. function option_definition() {
  23. $options = parent::option_definition();
  24. $options['link_to_shipment'] = array('default' => FALSE);
  25. return $options;
  26. }
  27. /**
  28. * Overrides views_handler::options_form().
  29. *
  30. * Provides link to shipment administration page.
  31. */
  32. function options_form(&$form, &$form_state) {
  33. parent::options_form($form, $form_state);
  34. $form['link_to_shipment'] = array(
  35. '#title' => t('Link this field to the shipment page'),
  36. '#description' => t('This will override any other link you have set.'),
  37. '#type' => 'checkbox',
  38. '#default_value' => !empty($this->options['link_to_shipment']),
  39. );
  40. }
  41. /**
  42. * Renders whatever the data is as a link to the order.
  43. *
  44. * Data should be made XSS safe prior to calling this function.
  45. */
  46. function render_link($data, $values) {
  47. if (!empty($this->options['link_to_shipment'])) {
  48. $this->options['alter']['make_link'] = FALSE;
  49. if (user_access('fulfill orders')) {
  50. $path = 'admin/store/orders/' . $this->get_value($values, 'order_id') . '/shipments/' . $values->{$this->field_alias};
  51. }
  52. else {
  53. $path = FALSE;
  54. }
  55. if ($path && $data !== NULL && $data !== '') {
  56. $this->options['alter']['make_link'] = TRUE;
  57. $this->options['alter']['path'] = $path;
  58. }
  59. }
  60. return $data;
  61. }
  62. /**
  63. * Overrides views_handler_field::render().
  64. */
  65. function render($values) {
  66. return $this->render_link(check_plain($values->{$this->field_alias}), $values);
  67. }
  68. }