tweak_handler_field_user_picture_preset.inc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Field handler to provide simple renderer that allows using a themed user link
  4. */
  5. class tweak_handler_field_user_picture_preset extends views_handler_field_user_picture {
  6. function option_definition() {
  7. $options = parent::option_definition();
  8. $options['preset'] = array(
  9. 'default' => $this->definition['title'],
  10. 'translatable' => FALSE,
  11. );
  12. return $options;
  13. }
  14. /**
  15. * Choose a preset
  16. */
  17. function options_form(&$form, &$form_state) {
  18. parent::options_form($form, $form_state);
  19. $options = array('0' => t('None'));
  20. foreach (imagecache_presets() as $pid => $preset) {
  21. $options[$pid] = $preset['presetname'];
  22. }
  23. $form['preset'] = array(
  24. '#type' => 'select',
  25. '#title' => t('Imagecache preset'),
  26. '#options' => $options,
  27. '#default_value' => $this->options['preset'],
  28. );
  29. if (!empty($form_state['exposed'])) {
  30. $identifier = $this->options['expose']['identifier'];
  31. if (!isset($form_state['input'][$identifier])) {
  32. $form_state['input'][$identifier] = $this->value;
  33. }
  34. }
  35. }
  36. function admin_summary() {
  37. $pid = $this->options['preset'];
  38. if ($pid) {
  39. $preset = imagecache_preset($pid);
  40. $ret = $preset['presetname'];
  41. }
  42. else {
  43. $ret = t('Raw');
  44. }
  45. return $ret;
  46. }
  47. function render($values) {
  48. $pid = $this->options['preset'];
  49. if ($pid) {
  50. $preset = imagecache_preset($pid);
  51. return theme_imagecache($preset['presetname'], $values->{$this->field_alias});
  52. }
  53. else {
  54. return parent::render($values);
  55. }
  56. }
  57. }