N Scott
N Scott

Reputation: 21

Drupal Views conditional link

Using views and Views custom field...I want a link to change depending on if a file was uploaded [upload_fid-path], or if a URL [field_url_url] was given.

If a file was uploaded that takes precedance over the URL...If no file is attached, than link to the URL...If no URL exist, then link to node.

Any help would be appreciated, thanks!

Upvotes: 2

Views: 1772

Answers (2)

Rajesh Vishwakarma
Rajesh Vishwakarma

Reputation: 387

Use views conditional module, this will help you to create if else statement. Only for drupal 7

Ref: https://drupal.org/project/views_conditional

Upvotes: 0

Nikit
Nikit

Reputation: 5128

Add file field in views.
Add Customfield: PHP code, enter there code:

<?php
    print '<pre>'.print_r($data).'</pre>';
?>

you will see internal of data, filled like:

stdClass Object
(
    [nid] => 46
    [node_type] => consignment
    [node_vid] => 53
    [node_data_field_cnsgm_image_field_cnsgm_image_fid] => Array
        (
            [0] => Array
                (
                    [fid] => 47
                    [list] => 1
                    [data] => a:3:{s:11:"description";s:10:"Test descr";s:3:"alt";s:0:"";s:5:"title";s:0:"";}
                )

            [1] => Array
                (
                    [fid] => 57
                    [list] => 1
                    [data] => a:3:{s:11:"description";s:0:"";s:3:"alt";s:0:"";s:5:"title";s:0:"";}
                )

        )

)

node_data_field_cnsgm_image_field_cnsgm_image_fid for current example is file field representation, fid is reference to {files} table, there you can get path to filepath of file.
So you need to check this field to show what you want...

p.s. You field will be difference. Be carefull, $data column names will changed if you add new fields in views, so need to add you custom field at last time...

Upvotes: 1

Related Questions