I have started to create a custom views plugin to sort the fields in view according to the video views(not node views but youtube views) on my video content type.
This is how I've implemented hook_views_data():

$data = array();

$data['post_video_views']['table']['group'] = t('PROJECT_NAME');

$data['post_video_views']['table']['join'] = array(
  'node' => array(
    'left_field' => 'nid',
    'field' => 'nid',

$data['post_video_views']['popular'] = array(
  'title' => t('Popular videos'),
  'help' => t('Youtube views'),
  'field' => array(
    'handler' => 'views_handler_field',
  'sort' => array(
    'handler' => 'views_handler_sort',

This gives me an option to sort ascending and descending and also provides the fields to add. Everything working fine till this step.

Now, I want that this options should only appear when when I have the following filter criteria satisfied: Content: Type (= Video). How can this be done? I know this should be simple to do but just don't know where to do it.

P.S: I am using Views 3 with D 7.22.

  • Would love to be proven wrong, but I'm pretty sure there's no existing mechanism to do that. You'd probably have to implement your own views_handler_relationship which adds an explicit content type condition to the join
    – Clive
    Commented Aug 7, 2013 at 14:01
  • Are you wanting this option to be presented in the UI automatically when content type video is selected, or do you want all Views with content type video to be automatically sorted by this plugin?
    – Jimajamma
    Commented Aug 18, 2013 at 12:19
  • @Jimajamma I want this option (sort criteria) to appear in UI only when content type video is selected.
    – AjitS
    Commented Aug 18, 2013 at 14:10

1 Answer 1


You can use a hook_form_alter to add a conditional display of your filter based on the video selected option.

  *Implement hook_form_alter

function MY_MODULE_form_alter(&$form, &$form_state, $form_id) {
   //dsm($form) -> to get the form['#id']
   if ($form['#id'] == 'views-exposed-form-YOUR_VIEWS_NAME-DISPLAY') {
      $form['YOUR_FIELD_NAME']['#states'] = array(
       'visible' => array(
        ':input[name="THE_VIDEO_FIELD_NAME"]' => array('value' => 'THE_VIDEO_KEY'),


YOUR_FIELD_NAME is the field to display conditionally

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.