Drupal 7令牌和img标签

问题描述 投票:0回答:1

我正在使用Drupal 7,webform和webform2pdf模块创建一个申请表,一旦填写完毕,将生成一份包含申请人所有信息的PDF。

我遇到的问题是我设置的用于上传.jpg头像的字段和一个简短说明的.pdf显示为链接而不是仅列出内容。

我正在使用从webform组件生成的标记来动态地将内容填充到PDF中。

例如[提交:价值:recent_photo]

我需要一个特殊的语法来显示图像而不仅仅是链接吗?

drupal-7 token drupal-webform
1个回答
0
投票

这是我发现解决相同问题的解决方案(Drupal 7,Webform 4)。在MYADMINTHEME / template.php中键入此函数

function MYADMINTHEME_webform_display_file($variables) {
    $element = $variables['element'];
    $current_path = current_path();
    $file = $element['#value'];
    $filemime = !empty($file) ? $element['#value']->filemime : '';

    if (substr_count($current_path, 'downloadpdf') && in_array($filemime, array('image/jpeg','image/gif','image/png'))){
        if ($element['#format'] == 'text')
            return !empty($file) ? webform_file_url($file->uri) : t('no upload');

        $url = drupal_realpath($file->uri);
        return '<img src="' . $url . '"/>';
    } else {
        $url = !empty($file) ? webform_file_url($file->uri) : t('no upload');
        return !empty($file) ? ($element['#format'] == 'text' ? $url : l($file->filename, $url)) : ' ';
    }

}
© www.soinside.com 2019 - 2024. All rights reserved.