2

I'm editing/rewriting this question since I've made a bit more progress on it since I first posted it, and now the questions I have about what I'm trying to do are more specific:

I have a content type with a video field that can have multiple values (i.e. multiple videos attached to each node). What I'm trying to do is have the first video for each node display by default when the page is loaded, in a block in the main content area, and have a list of all the videos in a sidebar block, where clicking on one of them will reload the page with that video loaded in the main block instead.

I'm using a view that lists all videos for a node, and the two blocks are displays of that same view. The sidebar block seems to be working OK - I have the video thumbnails and titles, linked to the current node's path with "?vid=[field_module_video_1-fid]" appended, which is successfully generating the links. But what I'm having trouble with is having the main block accept that argument.

The main block is set to display just one video. I gave it a contextual filter for field_module_video:fid (the relationship to that field was already there), and since block displays can't pull a value directly from the URL, gave it a default of PHP code, using the following:

$vid = intval($_GET['vid'];
return $vid;

(Using intval to make sure that the value it gets is purely numeric and prevent SQL injection etc.) I set the action for it to take if the filter doesn't validate to display all values (which in this case just means showing the first one), so that when someone comes directly to the page rather than by clicking a thumbnail, they'd see the first video by default.

But none of the available forms of validation seem to be what I need - Content just uses node IDs, not field IDs. Basic validation just checks that something is there, but doesn't seem to do anything with it. Numeric just checks that it's a number. Nothing validates field IDs.

If I set the validation to basic, no video shows at all, whether there's an argument appended to the URL or not. If I set it to numeric, the first video always shows regardless of whether there's an argument or what the argument is. I'm not really sure why the difference - the fact that it's showing the first one no matter what for numeric suggests that the filter is not validating, but I don't know why it then doesn't do that for basic.

And more importantly, how do I get it to validate for field ID so that it will display the selected video? I'm guessing I have to use PHP code of some kind, but I'm not sure what or how. Most of my PHP experience to date has been non-Drupal-related.

Edited to add an export of the view in question:

$view = new view();
$view->name = 'ln_module_videos';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'LN Module Videos';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_ajax'] = TRUE;
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'slideshow';
$handler->display->display_options['style_options']['slideshow_type'] = 'views_slideshow_cycle';
$handler->display->display_options['style_options']['slideshow_skin'] = 'default';
$handler->display->display_options['style_options']['skin_info'] = array(
  'class' => 'default',
  'name' => 'Default',
  'module' => 'views_slideshow',
  'path' => '',
  'stylesheets' => array(),
);
$handler->display->display_options['style_options']['widgets']['top']['views_slideshow_pager']['weight'] = '1';
$handler->display->display_options['style_options']['widgets']['top']['views_slideshow_pager']['type'] = 'views_slideshow_pager_fields';
$handler->display->display_options['style_options']['widgets']['top']['views_slideshow_pager']['views_slideshow_pager_fields_fields'] = array(
  'field_module_video' => 0,
  'field_module_video_1' => 0,
  'filename' => 0,
  'nothing' => 0,
);
$handler->display->display_options['style_options']['widgets']['top']['views_slideshow_controls']['weight'] = '1';
$handler->display->display_options['style_options']['widgets']['top']['views_slideshow_controls']['type'] = 'views_slideshow_controls_text';
$handler->display->display_options['style_options']['widgets']['top']['views_slideshow_slide_counter']['weight'] = '1';
$handler->display->display_options['style_options']['widgets']['bottom']['views_slideshow_pager']['enable'] = 1;
$handler->display->display_options['style_options']['widgets']['bottom']['views_slideshow_pager']['weight'] = '1';
$handler->display->display_options['style_options']['widgets']['bottom']['views_slideshow_pager']['type'] = 'views_slideshow_pager_fields';
$handler->display->display_options['style_options']['widgets']['bottom']['views_slideshow_pager']['views_slideshow_pager_fields_fields'] = array(
  'nothing' => 'nothing',
  'field_module_video' => 0,
  'field_module_video_1' => 0,
  'filename' => 0,
);
$handler->display->display_options['style_options']['widgets']['bottom']['views_slideshow_controls']['weight'] = '1';
$handler->display->display_options['style_options']['widgets']['bottom']['views_slideshow_controls']['type'] = 'views_slideshow_controls_text';
$handler->display->display_options['style_options']['widgets']['bottom']['views_slideshow_slide_counter']['weight'] = '1';
$handler->display->display_options['style_options']['views_slideshow_cycle']['timeout'] = '5000';
$handler->display->display_options['style_options']['views_slideshow_cycle']['speed'] = '700';
$handler->display->display_options['style_options']['views_slideshow_cycle']['delay'] = '0';
$handler->display->display_options['style_options']['views_slideshow_cycle']['pause'] = 0;
$handler->display->display_options['style_options']['views_slideshow_cycle']['action_advanced'] = 1;
$handler->display->display_options['style_options']['views_slideshow_cycle']['start_paused'] = 1;
$handler->display->display_options['style_options']['views_slideshow_cycle']['remember_slide_days'] = '1';
$handler->display->display_options['style_options']['views_slideshow_cycle']['items_per_slide'] = '1';
$handler->display->display_options['style_options']['views_slideshow_cycle']['wait_for_image_load_timeout'] = '3000';
$handler->display->display_options['style_options']['views_slideshow_cycle']['cleartype'] = 0;
$handler->display->display_options['style_options']['views_slideshow_cycle']['cleartypenobg'] = 0;
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Content: Video (field_module_video:fid) */
$handler->display->display_options['relationships']['field_module_video_fid']['id'] = 'field_module_video_fid';
$handler->display->display_options['relationships']['field_module_video_fid']['table'] = 'field_data_field_module_video';
$handler->display->display_options['relationships']['field_module_video_fid']['field'] = 'field_module_video_fid';
$handler->display->display_options['relationships']['field_module_video_fid']['required'] = TRUE;
/* Field: Content: Video */
$handler->display->display_options['fields']['field_module_video']['id'] = 'field_module_video';
$handler->display->display_options['fields']['field_module_video']['table'] = 'field_data_field_module_video';
$handler->display->display_options['fields']['field_module_video']['field'] = 'field_module_video';
$handler->display->display_options['fields']['field_module_video']['label'] = '';
$handler->display->display_options['fields']['field_module_video']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_module_video']['hide_empty'] = TRUE;
$handler->display->display_options['fields']['field_module_video']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_module_video']['type'] = 'file_rendered';
$handler->display->display_options['fields']['field_module_video']['settings'] = array(
  'file_view_mode' => 'media_large',
);
$handler->display->display_options['fields']['field_module_video']['group_rows'] = FALSE;
$handler->display->display_options['fields']['field_module_video']['delta_offset'] = '0';
/* Field: thumbnail */
$handler->display->display_options['fields']['field_module_video_1']['id'] = 'field_module_video_1';
$handler->display->display_options['fields']['field_module_video_1']['table'] = 'field_data_field_module_video';
$handler->display->display_options['fields']['field_module_video_1']['field'] = 'field_module_video';
$handler->display->display_options['fields']['field_module_video_1']['ui_name'] = 'thumbnail';
$handler->display->display_options['fields']['field_module_video_1']['label'] = '';
$handler->display->display_options['fields']['field_module_video_1']['exclude'] = TRUE;
$handler->display->display_options['fields']['field_module_video_1']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_module_video_1']['hide_empty'] = TRUE;
$handler->display->display_options['fields']['field_module_video_1']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_module_video_1']['type'] = 'file_rendered';
$handler->display->display_options['fields']['field_module_video_1']['settings'] = array(
  'file_view_mode' => 'media_preview',
);
$handler->display->display_options['fields']['field_module_video_1']['group_rows'] = FALSE;
$handler->display->display_options['fields']['field_module_video_1']['delta_offset'] = '0';
/* Field: File: Name */
$handler->display->display_options['fields']['filename']['id'] = 'filename';
$handler->display->display_options['fields']['filename']['table'] = 'file_managed';
$handler->display->display_options['fields']['filename']['field'] = 'filename';
$handler->display->display_options['fields']['filename']['relationship'] = 'field_module_video_fid';
$handler->display->display_options['fields']['filename']['label'] = '';
$handler->display->display_options['fields']['filename']['exclude'] = TRUE;
$handler->display->display_options['fields']['filename']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['filename']['hide_empty'] = TRUE;
/* Field: Global: Custom text */
$handler->display->display_options['fields']['nothing']['id'] = 'nothing';
$handler->display->display_options['fields']['nothing']['table'] = 'views';
$handler->display->display_options['fields']['nothing']['field'] = 'nothing';
$handler->display->display_options['fields']['nothing']['label'] = '';
$handler->display->display_options['fields']['nothing']['exclude'] = TRUE;
$handler->display->display_options['fields']['nothing']['alter']['text'] = '[field_module_video_1]<br/>
[filename]';
$handler->display->display_options['fields']['nothing']['element_type'] = '0';
$handler->display->display_options['fields']['nothing']['element_class'] = 'video-preview';
$handler->display->display_options['fields']['nothing']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['nothing']['element_wrapper_type'] = '0';
$handler->display->display_options['fields']['nothing']['element_default_classes'] = FALSE;
$handler->display->display_options['fields']['nothing']['hide_empty'] = TRUE;
/* Contextual filter: Content: Nid */
$handler->display->display_options['arguments']['nid']['id'] = 'nid';
$handler->display->display_options['arguments']['nid']['table'] = 'node';
$handler->display->display_options['arguments']['nid']['field'] = 'nid';
$handler->display->display_options['arguments']['nid']['default_action'] = 'default';
$handler->display->display_options['arguments']['nid']['default_argument_type'] = 'node';
$handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
$handler->display->display_options['path'] = 'video-test';

/* Display: Sidebar Block */
$handler = $view->new_display('block', 'Sidebar Block', 'block_1');
$handler->display->display_options['display_description'] = 'Lists all videos for a learning module in a sidebar block';
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Content: Video */
$handler->display->display_options['fields']['field_module_video']['id'] = 'field_module_video';
$handler->display->display_options['fields']['field_module_video']['table'] = 'field_data_field_module_video';
$handler->display->display_options['fields']['field_module_video']['field'] = 'field_module_video';
$handler->display->display_options['fields']['field_module_video']['label'] = '';
$handler->display->display_options['fields']['field_module_video']['exclude'] = TRUE;
$handler->display->display_options['fields']['field_module_video']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_module_video']['hide_empty'] = TRUE;
$handler->display->display_options['fields']['field_module_video']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_module_video']['type'] = 'file_rendered';
$handler->display->display_options['fields']['field_module_video']['settings'] = array(
  'file_view_mode' => 'media_large',
);
$handler->display->display_options['fields']['field_module_video']['group_rows'] = FALSE;
$handler->display->display_options['fields']['field_module_video']['delta_offset'] = '0';
/* Field: Content: Path */
$handler->display->display_options['fields']['path']['id'] = 'path';
$handler->display->display_options['fields']['path']['table'] = 'node';
$handler->display->display_options['fields']['path']['field'] = 'path';
$handler->display->display_options['fields']['path']['label'] = '';
$handler->display->display_options['fields']['path']['exclude'] = TRUE;
$handler->display->display_options['fields']['path']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['path']['absolute'] = TRUE;
/* Field: thumbnail */
$handler->display->display_options['fields']['field_module_video_1']['id'] = 'field_module_video_1';
$handler->display->display_options['fields']['field_module_video_1']['table'] = 'field_data_field_module_video';
$handler->display->display_options['fields']['field_module_video_1']['field'] = 'field_module_video';
$handler->display->display_options['fields']['field_module_video_1']['ui_name'] = 'thumbnail';
$handler->display->display_options['fields']['field_module_video_1']['label'] = '';
$handler->display->display_options['fields']['field_module_video_1']['exclude'] = TRUE;
$handler->display->display_options['fields']['field_module_video_1']['alter']['make_link'] = TRUE;
$handler->display->display_options['fields']['field_module_video_1']['alter']['path'] = '[path]?vid=[field_module_video_1-fid]';
$handler->display->display_options['fields']['field_module_video_1']['alter']['absolute'] = TRUE;
$handler->display->display_options['fields']['field_module_video_1']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_module_video_1']['hide_empty'] = TRUE;
$handler->display->display_options['fields']['field_module_video_1']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_module_video_1']['type'] = 'file_rendered';
$handler->display->display_options['fields']['field_module_video_1']['settings'] = array(
  'file_view_mode' => 'media_preview',
);
$handler->display->display_options['fields']['field_module_video_1']['group_rows'] = FALSE;
$handler->display->display_options['fields']['field_module_video_1']['delta_offset'] = '0';
/* Field: File: Name */
$handler->display->display_options['fields']['filename']['id'] = 'filename';
$handler->display->display_options['fields']['filename']['table'] = 'file_managed';
$handler->display->display_options['fields']['filename']['field'] = 'filename';
$handler->display->display_options['fields']['filename']['relationship'] = 'field_module_video_fid';
$handler->display->display_options['fields']['filename']['label'] = '';
$handler->display->display_options['fields']['filename']['exclude'] = TRUE;
$handler->display->display_options['fields']['filename']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['filename']['hide_empty'] = TRUE;
/* Field: Global: Custom text */
$handler->display->display_options['fields']['nothing']['id'] = 'nothing';
$handler->display->display_options['fields']['nothing']['table'] = 'views';
$handler->display->display_options['fields']['nothing']['field'] = 'nothing';
$handler->display->display_options['fields']['nothing']['label'] = '';
$handler->display->display_options['fields']['nothing']['alter']['text'] = '<span class="field-module-video-thumbnail">[field_module_video_1]</span> <span class="field-module-video-title">[filename]</span>';
$handler->display->display_options['fields']['nothing']['element_type'] = '0';
$handler->display->display_options['fields']['nothing']['element_class'] = 'video-preview';
$handler->display->display_options['fields']['nothing']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['nothing']['element_wrapper_type'] = '0';
$handler->display->display_options['fields']['nothing']['element_default_classes'] = FALSE;
$handler->display->display_options['fields']['nothing']['hide_empty'] = TRUE;

/* Display: Main Video Block */
$handler = $view->new_display('block', 'Main Video Block', 'block_2');
$handler->display->display_options['display_description'] = 'Main video featured in content area on learning module pages';
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '1';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['style_options']['default_row_class'] = FALSE;
$handler->display->display_options['style_options']['row_class_special'] = FALSE;
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Content: Video */
$handler->display->display_options['fields']['field_module_video']['id'] = 'field_module_video';
$handler->display->display_options['fields']['field_module_video']['table'] = 'field_data_field_module_video';
$handler->display->display_options['fields']['field_module_video']['field'] = 'field_module_video';
$handler->display->display_options['fields']['field_module_video']['label'] = '';
$handler->display->display_options['fields']['field_module_video']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_module_video']['hide_empty'] = TRUE;
$handler->display->display_options['fields']['field_module_video']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_module_video']['type'] = 'file_rendered';
$handler->display->display_options['fields']['field_module_video']['settings'] = array(
  'file_view_mode' => 'media_large',
);
$handler->display->display_options['fields']['field_module_video']['group_rows'] = FALSE;
$handler->display->display_options['fields']['field_module_video']['delta_offset'] = '0';
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Content: Nid */
$handler->display->display_options['arguments']['nid']['id'] = 'nid';
$handler->display->display_options['arguments']['nid']['table'] = 'node';
$handler->display->display_options['arguments']['nid']['field'] = 'nid';
$handler->display->display_options['arguments']['nid']['default_action'] = 'default';
$handler->display->display_options['arguments']['nid']['default_argument_type'] = 'node';
$handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';
/* Contextual filter: Content: Video (field_module_video:fid) */
$handler->display->display_options['arguments']['field_module_video_fid']['id'] = 'field_module_video_fid';
$handler->display->display_options['arguments']['field_module_video_fid']['table'] = 'field_data_field_module_video';
$handler->display->display_options['arguments']['field_module_video_fid']['field'] = 'field_module_video_fid';
$handler->display->display_options['arguments']['field_module_video_fid']['default_action'] = 'default';
$handler->display->display_options['arguments']['field_module_video_fid']['default_argument_type'] = 'php';
$handler->display->display_options['arguments']['field_module_video_fid']['default_argument_options']['code'] = '$vid = intval($_GET[\'vid\'];
return $vid;';
$handler->display->display_options['arguments']['field_module_video_fid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['field_module_video_fid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['field_module_video_fid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['field_module_video_fid']['specify_validation'] = TRUE;
$handler->display->display_options['arguments']['field_module_video_fid']['validate']['type'] = 'numeric';
$handler->display->display_options['arguments']['field_module_video_fid']['validate']['fail'] = 'ignore';

I should also add - it's only the last two displays (Sidebar Block and Main Video Block) that are in use. The original slideshow display, the settings of which I just noticed are in the Master section, is no longer being used, since it made the main content area too crowded, especially on nodes with a large number of videos. The sidebar block approach seemed more likely to be able to accommodate a varying number of videos without making the page too busy or breaking the layout.

  • Can you export the view so we can get a closer look? – CR47 Jun 4 '13 at 18:07
  • Yes, sorry - I should have added that in the first place! Editing the question to add that. – spidersilk Jun 4 '13 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.