retrieves pdf file name from media

This commit is contained in:
Chris 2021-08-10 14:34:52 +02:00
parent 5b1f1a0239
commit 31b43a5f2d
5 changed files with 22 additions and 116 deletions

View File

@ -19,10 +19,9 @@ return [
],
'DefaultSettings' => [
'PDFLinkBlockForm' => [
'title' => '',
'link_name' => '',
'renderSourceLink' => true,
'width' => 600,
'zoom_type' => '',
'description_text' => '',
'wrapStyle' => 'overflow-y: hidden;display: flex;flex-direction: column;justify-content: center;',
]
]

View File

@ -1,5 +1,5 @@
[info]
name = "Image viewer"
name = "PDF link"
description = "View and optionally zoom images"
tags = ""
license = "MIT"

View File

@ -11,40 +11,15 @@ class PDFLinkBlockForm extends Form
{
$this->add([
'name' => 'o:block[__blockIndex__][o:data][width]',
'type' => Element\Select::class,
'name' => 'o:block[__blockIndex__][o:data][description_text]',
'type' => Element\Textarea::class,
'options' => [
'label' => 'Width',
'value_options' => Module::IMAGE_WIDTH,
'label' => 'Short summary',
],
'attributes' => [
'rows' => '10',
],
]);
$this->add([
'name' => 'o:block[__blockIndex__][o:data][zoom_type]',
'type' => Element\Select::class,
'options' => [
'label' => 'Zooming',
'value_options' => Module::ZOOM_TYPE,
],
]);
$this->add([
'type' => Element\Checkbox::class,
'name' => 'o:block[__blockIndex__][o:data][renderSourceLink]',
'options' => [
'label' => 'Display a link to the item',
//'use_hidden_element' => true,
'checked_value' => true,
'unchecked_value' => false,
],
]);
$this->add([
'name' => 'o:block[__blockIndex__][o:data][title]',
'type' => Element\Text::class,
'options' => [
'label' => 'Sub-title',
]
]);
}
}

View File

@ -34,7 +34,7 @@ class PDFLink extends AbstractBlockLayout
}
public function getLabel() {
return 'Image viewer';
return 'PDF link';
}
public function form(PhpRenderer $view,
@ -47,10 +47,7 @@ class PDFLink extends AbstractBlockLayout
? $block->data() + $this->defaultSettings
: $this->defaultSettings;
$form->setData([
'o:block[__blockIndex__][o:data][title]' => $data['title'],
'o:block[__blockIndex__][o:data][width]' => $data['width'],
'o:block[__blockIndex__][o:data][zoom_type]' => $data['zoom_type'],
'o:block[__blockIndex__][o:data][renderSourceLink]' => $data['renderSourceLink'],
'o:block[__blockIndex__][o:data][description_text]' => $data['description_text'],
]);
$form->prepare();
@ -71,18 +68,15 @@ class PDFLink extends AbstractBlockLayout
return '';
}
$thumbnails = [];
static $id = 0;
$media = $attachments[0]->item()->media()[0];
return $view->partial('common/block-layout/pDFLink', [
'zoom_type' => $block->dataValue('zoom_type'),
'title' => $block->dataValue('title'),
'description_text' => $block->dataValue('description_text'),
'link_name' => $media->displayTitle(),
'item_url' => $attachments[0]->item()->url(),
'renderSourceLink' => $block->dataValue('renderSourceLink'),
'width' => $block->dataValue('width'),
'image' => $media->primaryMedia()->thumbnailUrl('large'),
'id' => 'iv-' . ++$id,
'pdf_url' => $media->originalUrl(),
'id' => 'pdf-' . ++$id,
]);
}
}

View File

@ -1,68 +1,6 @@
<?php
if ($zoom_type == "wheelzoom") {
$this->headScript()->appendFile($this->assetUrl('vendor/wheelzoom/wheelzoom.js',
'PDFLink'));
}
if ($zoom_type == "zoom") {
$this->headScript()->appendFile($this->assetUrl('vendor/zoom/jquery.zoom.min.js',
'PDFLink'));
}
if ($zoom_type == "zoom" || $zoom_type == "wheelzoom") {
$this->headLink()->appendStylesheet($this->assetUrl('css/zoom.css',
'PDFLink'));
}
?>
<?php if ($renderSourceLink) { ?>
<div class="source-link">
<a href="<?= $item_url ?>">Source</a>
</div>
<?php } ?>
<?php if ($zoom_type == "zoom") { ?>
<div id='<?= $id ?>' class='zoom' style='width:<?= $width ?>%; cursor:grab'>
<img src='<?= $image ?>' alt='<?= $title ?>'/>
</div>
<?php } ?>
<?php if ($zoom_type == "wheelzoom") { ?>
<div class='zoom' style='display:block; width:<?= $width ?>%; cursor:crosshair'>
<img id="<?= $id ?>" src="<?= $image ?>" />
</div>
<?php } ?>
<?php if ($zoom_type == "") { ?>
<div class="archive-img">
<img id="<?= $id ?>"
style="width: <?= $width ?>%;"
src="<?= $image ?>"
/>
</div>
<?php } ?>
<?php if ($title) { ?>
<div class="item_title">
<?= $title ?>
</div>
<?php } ?>
<?php if ($zoom_type == "zoom") { ?>
<script>
$(document).ready(function(){
$('#<?= $id ?>').zoom({on:'grab', 'duration': 200, 'magnify': 1.5});
});
</script>
<?php } ?>
<?php if ($zoom_type == "wheelzoom") { ?>
<script>
$(document).ready(function(){
wheelzoom(document.querySelector('#<?= $id ?>'));
});
</script>
<?php } ?>
<div class="arc-hive-pdf">
<div class="pdf-summary"><?= $description_text ?></div>
<a href="<?= $pdf_url ?>"><?= $link_name ?>.pdf</a>
</div>