PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/video/views/video_views_handler_field_data.inc

#
Pascal | 59 lines | 36 code | 6 blank | 17 comment | 3 complexity | b6fccd13f64aea753d81fd701a6398bc MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @file
  4. * video_handler_field_data.inc
  5. *
  6. * Provides a handler for displaying thumbnails within the serialized data column.
  7. */
  8. class video_views_handler_field_data extends content_handler_field {
  9. function render($values) {
  10. $values = drupal_clone($values); // Prevent affecting the original.
  11. $data = unserialize($values->{$this->field_alias});
  12. $filepath = $data['video_thumb'];
  13. // We're down to a single node here, so we can retrieve the actual field
  14. // definition for the node type being considered.
  15. $field = content_fields($this->content_field['field_name'], $values->{$this->aliases['type']});
  16. $options = $this->options;
  17. $db_info = content_database_info($field);
  18. // Build a pseudo-node from the retrieved values.
  19. $node = drupal_clone($values);
  20. $node->type = $values->{$this->aliases['type']};
  21. $node->nid = $values->{$this->aliases['nid']};
  22. $node->vid = $values->{$this->aliases['vid']};
  23. // Some formatters need to behave differently depending on the build_mode
  24. // (for instance: preview), so we provide one.
  25. $node->build_mode = NODE_BUILD_NORMAL;
  26. $item = array();
  27. foreach ($db_info['columns'] as $column => $attributes) {
  28. $item[$column] = $values->{$this->aliases[$attributes['column']]};
  29. }
  30. $item['#delta'] = $field['multiple'] ? $values->{$this->aliases['delta']} : 0;
  31. //added for thumbnails this should work.
  32. $file = pathinfo($filepath);
  33. $item['filepath'] = $filepath;
  34. $item['filename'] = $file['basename'];
  35. $item['filemime'] = file_get_mimetype($file['basename']);
  36. $item['filesize'] = is_readable($filepath) ? filesize($filepath) : 0;
  37. // Render items.
  38. $formatter_name = $options['format'];
  39. if ($formatter = _content_get_formatter($formatter_name, $field['type'])) {
  40. if (content_handle('formatter', 'multiple values', $formatter) == CONTENT_HANDLE_CORE) {
  41. // Single-value formatter.
  42. $output = content_format($field, $item, $formatter_name, $node);
  43. }
  44. else {
  45. // Multiple values formatter - we actually have only one value to display.
  46. $output = content_format($field, array($item), $formatter_name, $node);
  47. }
  48. return $this->render_link($output, $values);
  49. }
  50. return '';
  51. }
  52. }