Hello everybody,

is it somehow possible to add some text to the pdf icon that appears when a pdf is attached to a view?
I have different pdfs attached to a table-view and want some explaining words for the icons but I it seems I am not capable of doing this :(

Thanks in advance!

Comments

justluvgod’s picture

i am having the same issue

ivanilic’s picture

Same for me?

Thanks

ivanilic’s picture

This was quick solution for me, hope someone can tell me if this can be done it other way:

In my views_pdf.modue file (in module folder) I've just changed in line 52 text $image to $title.
This way your module is printing views title instead of image.
This is part of code:

$imagePath = drupal_get_path('module', 'views_pdf') . '/images/pdf.png';

if ($image = theme('image', array('path' => $imagePath, 'title' => $title, 'alt' => $title))) {
return l($title, $path, $options ); // $image was instead of $title
}

As I sad, hopefully someone can show me better practice.

Thanks

killua99’s picture

This could be added for the next version.

I'll update the status of this issue but please if you bring any patch for the current stable version I'll review it and if I see if good enough I'll commit it.

killua99’s picture

Status: Active » Closed (won't fix)
stephandale’s picture

Hi all. I know this issue is closed, but I thought I'd chime in with a Drupal-friendly way to change the icon, for future reference. Best not hack module code as it'll revert when the module is updated.

The views_pdf module defines the 'views_pdf_icon' theme registry key in views_pdf_theme(), which makes Drupal use the module's theme_views_pdf_icon() to theme the icon.

You can alter the registry so that it uses your own function.

Create a module (called 'mymodule' in this example) and add an implementation of hook_theme_registry_alter() to change the icon theming function, alongside your implementation of the icon theming function (mymodule_theme_views_pdf_icon() in this example).

<?php
/**
 * Implements hook_theme_registry_alter().
 *
 * Change the views_pdf_icon theme function to our own.
 */
function mymodule_theme_registry_alter(&$theme_registry) {
  if (isset($theme_registry['views_pdf_icon']['function'])) {
    $theme_registry['views_pdf_icon']['function'] = 'mymodule_theme_views_pdf_icon';
  }
}

/**
 * Custom theme function for views_pdf icons.
 */
function mymodule_theme_views_pdf_icon($vars) {
  $title = $vars['title'];
  $path = $vars['path'];
  $options = $vars['options'];
  $options['html'] = TRUE;
  $options['attributes']['class'] = 'pdf-icon';

  $imagePath = drupal_get_path('module', 'views_pdf') . '/images/pdf.png';

  if ($image = theme('image', array('path' => $imagePath, 'title' => $title, 'alt' => $title))) {
    return l($image, $path, $options);
  }
}
?>

In this example, the mymodule_theme_views_pdf_icon() function is exactly the same as the one from views_pdf-7.x-1.4. Change it as you wish :-)

P.S. Ignore the closing '?>' - you wouldn't normally add that to the end of module code. I had to add it to get the syntax highlighting.

stephandale’s picture

I should also have said that you could change one line in mymodule_theme_views_pdf_icon() to have your own icon used:

<?php
function mymodule_theme_views_pdf_icon($vars) {
  ...
  $imagePath = drupal_get_path('module', 'mymodule') . '/images/pdf.png';
  ...
}
?>

That will load mymodule/images/pdf.png instead of the views_pdf icon.