You are here

function vsf_upload_preprocess_views_view in Visual select file 7

Implements hook_preprocess_views_view().

File

submodules/vsf_upload/vsf_upload.module, line 46

Code

function vsf_upload_preprocess_views_view(&$vars) {
  $view = $vars['view'];
  if ($view->tag == 'visual_select_file' && isset($_GET['ckeditor'])) {
    if (module_exists('file_entity') && variable_get('vsf_file_entity', TRUE)) {
      if (file_entity_access('create')) {
        $link = l(t('Add file'), 'file/add', array(
          'query' => array(
            'vsf_destination' => request_uri(),
          ),
        ));
        $vars['header'] = theme('item_list', array(
          'items' => array(
            $link,
          ),
          'attributes' => array(
            'class' => array(
              'action-links',
            ),
          ),
        ));
      }
    }
    else {
      if (user_access('upload vsf files')) {
        $form = drupal_get_form('vsf_upload_form');

        // This is hacky, but this Views header is rendered on /views/ajax when searching, so
        // we have to steer the form away from there (it's bad magic) or it won't submit.
        $query = array_intersect_key($_GET, array_flip(array(
          'vsf_formatter',
          'ckeditor',
          'iframe',
          'vsf_field',
        )));
        $form['#action'] = url('admin/visual_select_file', array(
          'query' => $query,
        ));
        $vars['header'] = drupal_render($form);
      }
    }
  }
}