2

I have a view that I have attached a data export view to. I want to change the default orange icon that shows XLS at the bottom of the view, to another button with text "Download View". How can I achieve this?

| improve this question | | | | |
1

This image is set in function views_data_export_views_plugins(), in views_data_export.views

Implement your own hook_views_plugins() and override ['style']['views_data_export_xls']['export feed icon'] with your own value. Just make sure your module fires after Views Data Export.

| improve this answer | | | | |
  • How will I ensure that my module fires after Views Data Export – user1685929 May 21 '13 at 20:52
  • Click a link I put there? – Mołot May 21 '13 at 22:15
1

Revised Answer: Seems dreadfully hacky, but it is a fix in one place where my earlier answer was CSS and preprocess. I found that as soon as the CSV link had filter arguments appended then the CSS a[href$='.csv'] targeting broke.

THEMENAME_preprocess_views_view($vars){

    if(!empty($vars['feed_icon'])){

    $vars['feed_icon'] = str_replace('sites/all/modules/views_data_export/images/csv.png', drupal_get_path('theme', 'THEMENAME').'/images/feed-icon-csv.png', $vars['feed_icon']);
    $vars['feed_icon'] = str_replace('sites/all/modules/kml/images/kml.png', drupal_get_path('theme', 'THEMENAME').'/images/feed-icon-kml.png', $vars['feed_icon']);

    }
}

Old answer that does not work if the view has query parameters:

I did the following to strip out those images but leave the links:

THEMENAME_preprocess_views_view($vars){
    if($vars['view']->name == 'view_name'){

        $vars['feed_icon'] = strip_tags($vars['feed_icon'], '<a>');

    }
}

Then in my CSS I could easily add:

.feed-icon a[href$='.csv'] {
    display: inline-block;
    background: url('images/feed-icon-csv.png');
    width: 94px;
    height: 27px;
}

Yes I know it is not great for accessibility but hooks were really not working for me.

| improve this answer | | | | |
0

You can simple hook into the _views_data_export_feed_icon Function (like above). The Function above doesn't work for me.

So here is mine:

function YOURMODULEORTHEME_views_data_export_feed_icon($variables) 
{
    extract($variables, EXTR_SKIP);
    $url_options = array('html' => TRUE, 'attributes' => array('class' => 'YOURCLASS-button'));
    if($query) {
        $url_options['query'] = $query;
    }
    return l($text, $url, $url_options);
}

You could specify your own class to style the Button.

The "alt" Text (defined in the View) is now your Link.

| improve this answer | | | | |
0

Similar to what was posted above, however, you need to do it in hook_views_plugins_alter() rather than defining your own plugin in hook_views_plugins().

Set the export feed icon to your updated icon:

function MYMODULE_views_plugins_alter(&$plugins) {
  $plugins['style']['views_data_export_xls']['export feed icon'] = [PATH_TO_MY_ICON];
}
| improve this answer | | | | |
-2

override theme_views_data_export_feed_icon function in your theme template.php

Example :

function themename_views_data_export_feed_icon($image_path, $url, $query = '', $text = '') {

    $url_options = array('html' => true, 'attributes' => array('class' => 'csv-export'));
    if ($query) {
       $url_options['query'] = $query;
    }
    return l(t('Download View'), $url, $url_options);
}
| improve this answer | | | | |
  • And by the way, it does not answer the question - default RSS feed icon has nothing to do with views data export XLS button. – Mołot Oct 25 '13 at 7:18
  • How the export button will come at top of my view? I need to change any configuration or will it come automatically? For my views it is not showing. – ARUN May 24 '14 at 13:20

Your Answer

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

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