hydrates markdown into pdf and saves the file

This commit is contained in:
buttle 2021-05-25 14:09:59 +02:00
parent 34dc2e3869
commit 52aa513390
4 changed files with 50 additions and 19 deletions

View File

@ -16,6 +16,14 @@ composer install
chmod -R a+w vendor/mpdf/mpdf/tmp
```
Setup some permissions
```
cd omeka/files
mkdir docs
chown www-data docs
```
## LISENCE
The module is released under the [MIT] License.

View File

@ -17,6 +17,13 @@ return [
Form\TechDocumentBlockForm::class => Form\TechDocumentBlockForm::class,
],
],
/*
'media_ingesters' => [
'factories' => [
'TechDocument_media' => Service\Media\Ingester\TechDocumentMediaFactory::class,
],
],
*/
'DefaultSettings' => [
'TechDocumentBlockForm' => [
'wrapStyle' => 'overflow-y: hidden;display: flex;flex-direction: column;justify-content: center;',

View File

@ -11,7 +11,8 @@ class TechDocumentFactory implements FactoryInterface
{
return new TechDocument(
$services->get('FormElementManager'),
$services->get('Config')['DefaultSettings']['TechDocumentBlockForm']
$services->get('Config')['DefaultSettings']['TechDocumentBlockForm'],
$services->get('Config')['file_store']['local']['base_path'] ?: (OMEKA_PATH . '/files')
);
}
}

View File

@ -1,15 +1,18 @@
<?php
namespace TechDocument\Site\BlockLayout;
use Omeka\Api\Representation\SiteRepresentation;
use Omeka\Api\Representation\SitePageRepresentation;
use Omeka\Api\Representation\SitePageBlockRepresentation;
use Omeka\Site\BlockLayout\AbstractBlockLayout;
use Laminas\View\Renderer\PhpRenderer;
use Omeka\Api\Representation\SitePageBlockRepresentation;
use Omeka\Api\Representation\SitePageRepresentation;
use Omeka\Api\Representation\SiteRepresentation;
use Omeka\Entity\SitePageBlock;
use Omeka\Site\BlockLayout\AbstractBlockLayout;
use Omeka\Stdlib\ErrorStore;
use Laminas\Form\FormElementManager;
use TechDocument\Form\TechDocumentBlockForm;
//require_once(dirname(__DIR__, 3) . '/vendor/erusev/parsedown/Parsedown.php');
//require_once(dirname(__DIR__, 3) . '/vendor/mpdf/mpdf/src/Mpdf.php');
require_once(dirname(__DIR__, 3) . '/vendor/autoload.php');
@ -31,20 +34,43 @@ class TechDocument extends AbstractBlockLayout
*/
protected $defaultSettings = [];
protected $storage_dir = "";
/**
* @param FormElementManager $formElementManager
* @param array $defaultSettings
*/
public function __construct(FormElementManager $formElementManager, array $defaultSettings)
public function __construct(FormElementManager $formElementManager,
array $defaultSettings,
string $storage_dir)
{
$this->formElementManager = $formElementManager;
$this->defaultSettings = $defaultSettings;
$this->storage_dir = $storage_dir;
}
public function getLabel() {
return 'Techical document';
}
public function onHydrate(SitePageBlock $block, ErrorStore $errorStore): void
{
$data = $block->getData();
$site_title = $block->getPage()->getSite()->getTitle();
$parsedown = new Parsedown();
$text = "# ".$site_title." ".$dir."\n";
$text .= "## Arc-hive technical documentation\n";
$text .= "### Characteristics\n";
$text .= $data['characteristics'];
$html = $parsedown->setBreaksEnabled(true)->text($text);
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML($html);
$mpdf->Output($this->storage_dir.'/docs/'.$site_title.'.pdf', \Mpdf\Output\Destination::FILE);
}
public function form(PhpRenderer $view,
SiteRepresentation $site,
SitePageRepresentation $page = null,
@ -69,17 +95,6 @@ class TechDocument extends AbstractBlockLayout
public function render(PhpRenderer $view, SitePageBlockRepresentation $block)
{
$parsedown = new Parsedown();
$text = "# Arc-hive technical documentation\n";
$text .= "## characteristics\n";
$text .= $block->dataValue('characteristics');
$html = $parsedown->text($text);
$mpdf = new \Mpdf\Mpdf();
$mpdf = $mpdf->WriteHTML($html);
$mpdf->Output();
return $html;
return "";
}
}