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' => [ 'DefaultSettings' => [
'PDFLinkBlockForm' => [ 'PDFLinkBlockForm' => [
'title' => '', 'link_name' => '',
'renderSourceLink' => true, 'renderSourceLink' => true,
'width' => 600, 'description_text' => '',
'zoom_type' => '',
'wrapStyle' => 'overflow-y: hidden;display: flex;flex-direction: column;justify-content: center;', 'wrapStyle' => 'overflow-y: hidden;display: flex;flex-direction: column;justify-content: center;',
] ]
] ]

View File

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

View File

@ -11,40 +11,15 @@ class PDFLinkBlockForm extends Form
{ {
$this->add([ $this->add([
'name' => 'o:block[__blockIndex__][o:data][width]', 'name' => 'o:block[__blockIndex__][o:data][description_text]',
'type' => Element\Select::class, 'type' => Element\Textarea::class,
'options' => [ 'options' => [
'label' => 'Width', 'label' => 'Short summary',
'value_options' => Module::IMAGE_WIDTH, ],
'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() { public function getLabel() {
return 'Image viewer'; return 'PDF link';
} }
public function form(PhpRenderer $view, public function form(PhpRenderer $view,
@ -47,10 +47,7 @@ class PDFLink extends AbstractBlockLayout
? $block->data() + $this->defaultSettings ? $block->data() + $this->defaultSettings
: $this->defaultSettings; : $this->defaultSettings;
$form->setData([ $form->setData([
'o:block[__blockIndex__][o:data][title]' => $data['title'], 'o:block[__blockIndex__][o:data][description_text]' => $data['description_text'],
'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'],
]); ]);
$form->prepare(); $form->prepare();
@ -71,18 +68,15 @@ class PDFLink extends AbstractBlockLayout
return ''; return '';
} }
$thumbnails = [];
static $id = 0; static $id = 0;
$media = $attachments[0]->item()->media()[0]; $media = $attachments[0]->item()->media()[0];
return $view->partial('common/block-layout/pDFLink', [ return $view->partial('common/block-layout/pDFLink', [
'zoom_type' => $block->dataValue('zoom_type'), 'description_text' => $block->dataValue('description_text'),
'title' => $block->dataValue('title'), 'link_name' => $media->displayTitle(),
'item_url' => $attachments[0]->item()->url(), 'item_url' => $attachments[0]->item()->url(),
'renderSourceLink' => $block->dataValue('renderSourceLink'), 'pdf_url' => $media->originalUrl(),
'width' => $block->dataValue('width'), 'id' => 'pdf-' . ++$id,
'image' => $media->primaryMedia()->thumbnailUrl('large'),
'id' => 'iv-' . ++$id,
]); ]);
} }
} }

View File

@ -1,68 +1,6 @@
<?php <div class="arc-hive-pdf">
if ($zoom_type == "wheelzoom") { <div class="pdf-summary"><?= $description_text ?></div>
$this->headScript()->appendFile($this->assetUrl('vendor/wheelzoom/wheelzoom.js', <a href="<?= $pdf_url ?>"><?= $link_name ?>.pdf</a>
'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> </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 } ?>