Skip to content

Commit

Permalink
Merge pull request #22 from mungurs/patch-1
Browse files Browse the repository at this point in the history
[Admin:Form:File]: add download link
  • Loading branch information
strads10 authored Jan 26, 2018
2 parents b24588c + 58baf5a commit 9012f1c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/Admin/Form/Fields/Renderer/FileFieldRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,24 @@ public function render()
* @param ArboryFile $file
* @return Element
*/
public function createFileDetails( ArboryFile $file ): Element
public function createFileDetails(ArboryFile $file): Element
{
$fileSize = ( new FileSize( $file ) )->getReadableSize();
$fileDetails = Html::div( $file->getOriginalName() . ' / ' . $fileSize );
$fileSize = (new FileSize($file))->getReadableSize();

$fileDetails = Html::div();
$downloadLink = Html::a($file->getOriginalName() . ' / ' . $fileSize)->addAttributes([
'href' => $file->getUrl(),
"target" => "_blank",
"download"
]);
$removeInput =
Html::button()->addClass( 'remove fa fa-times' )->addAttributes([
Html::button()->addClass('remove fa fa-times')->addAttributes([
'type' => 'submit',
'name' => Element::formatName( $this->field->getNameSpacedName() . '.remove' ),
'name' => Element::formatName($this->field->getNameSpacedName() . '.remove'),
]);

if( !$this->field->isRequired() )
{
$fileDetails->append( $removeInput );
if (!$this->field->isRequired()) {
$fileDetails->append([$downloadLink, $removeInput]);
}

return $fileDetails;
Expand Down

0 comments on commit 9012f1c

Please sign in to comment.