video_embed_field.views.inc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @file
  4. * Hooks for Views integration.
  5. */
  6. /**
  7. * Implements hook_field_views_data().
  8. */
  9. function video_embed_field_field_views_data($field) {
  10. $data = field_views_field_default_views_data($field);
  11. // Only expose these components as Views field handlers.
  12. $implemented = array(
  13. 'video_url' => 'views_handler_field',
  14. 'thumbnail_path' => 'views_embed_field_views_handler_field_thumbnail_path',
  15. 'description' => 'views_handler_field',
  16. );
  17. // Get the translated field information.
  18. $properties = video_embed_field_data_property_info();
  19. // Iterate over video_embed_field defined tables.
  20. foreach ($data as &$table) {
  21. // Make sure the parent Views field (video_embed_field) is defined.
  22. if (isset($table[$field['field_name']]['field'])) {
  23. // Use the parent field definition as a template for component columns.
  24. $field_def = $table[$field['field_name']]['field'];
  25. // Remove 'additional fields' from the field definition. We don't
  26. // necessarily want all our sibling columns.
  27. unset($field_def['additional fields']);
  28. // Define the valid columns.
  29. $valid_columns = array();
  30. foreach ($implemented as $implement => $handler) {
  31. $column_name = $field['field_name'] . '_' . $implement;
  32. $valid_columns[$column_name] = $handler;
  33. }
  34. // Iterate over the video_embed_field components.
  35. foreach ($table as $column_name => &$column) {
  36. if (empty($column['field']) && isset($valid_columns[$column_name])) {
  37. // Assign the default component definition.
  38. $column['field'] = $field_def;
  39. $column['field']['real field'] = $column_name;
  40. $column['field']['handler'] = $valid_columns[$column_name];
  41. // Assign human-friendly labels for video_embed_field components.
  42. $field_labels = field_views_field_label($field['field_name']);
  43. $field_label = array_shift($field_labels);
  44. $property = str_replace($field_def['field_name'] . '_', '', $column_name);
  45. if (!empty($properties[$property])) {
  46. $property_label = $properties[$property]['label'];
  47. $title = t('@field-label - @property-label', array(
  48. '@field-label' => $field_label,
  49. '@property-label' => $property_label,
  50. ));
  51. $column['title'] = $title;
  52. $column['title short'] = $title;
  53. }
  54. }
  55. }
  56. }
  57. }
  58. return $data;
  59. }