Skip to content

Commit

Permalink
Adding displayFileImageLink function
Browse files Browse the repository at this point in the history
  • Loading branch information
jegelstaff committed Dec 19, 2024
1 parent 111fd5d commit 927ee69
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions modules/formulize/class/fileUploadElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,24 @@ function displayFileImage($entryOrDataset, $elementHandle, $dataSetKey=null, $lo
return $url;
}

/**
* Take the value of a file upload element, and return an anchor tag of the image thumbnail if applicable
*
* @param array $entryOrDataset The record from a dataset, or the entire dataset, as returned from getData
* @param string $elementHandle The element handle of the file upload element we're working with
* @param int $dataSetKey Optional. The key in the dataset array of the entry record we want to work with. Required if $entryOrDataset is the entire dataset.
* @param int $localId Optional. The ordinal id of the instance of the element handle we want to work with. Only required if there are multiple entries represented in this dataset record which all include data attached to this element handle, ie: if the handle is on the many side of a one to many connection in the dataset.
* @return string Returns the an HTML a tag referring to the file if the file is an image, and using the thumbnail as the clickable element, or returns the url for the file otherwise. If the file upload failed, this will return the error message from when the upload failed.
*/
function displayFileImageLink($entryOrDataset, $elementHandle, $dataSetKey=null, $localId='NULL') {
$image = displayFileImage($entryOrDataset, $elementHandle, $dataSetKey=null, $localId='NULL');
if(substr($image, 0, 4) == '<img') {
$url = display($entryOrDataset, $elementHandle, $dataSetKey, $localId);
$image = "<a href='$url' target='_blank'>$image</a>";
}
return $image;
}

/**
* Check if a filename has one of various common image file type extensions.
*
Expand Down

0 comments on commit 927ee69

Please sign in to comment.