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 chmod -R a+w vendor/mpdf/mpdf/tmp
``` ```
Setup some permissions
```
cd omeka/files
mkdir docs
chown www-data docs
```
## LISENCE ## LISENCE
The module is released under the [MIT] License. The module is released under the [MIT] License.

View File

@ -17,6 +17,13 @@ return [
Form\TechDocumentBlockForm::class => Form\TechDocumentBlockForm::class, Form\TechDocumentBlockForm::class => Form\TechDocumentBlockForm::class,
], ],
], ],
/*
'media_ingesters' => [
'factories' => [
'TechDocument_media' => Service\Media\Ingester\TechDocumentMediaFactory::class,
],
],
*/
'DefaultSettings' => [ 'DefaultSettings' => [
'TechDocumentBlockForm' => [ 'TechDocumentBlockForm' => [
'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

@ -11,7 +11,8 @@ class TechDocumentFactory implements FactoryInterface
{ {
return new TechDocument( return new TechDocument(
$services->get('FormElementManager'), $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 <?php
namespace TechDocument\Site\BlockLayout; 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 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 Laminas\Form\FormElementManager;
use TechDocument\Form\TechDocumentBlockForm; use TechDocument\Form\TechDocumentBlockForm;
//require_once(dirname(__DIR__, 3) . '/vendor/erusev/parsedown/Parsedown.php'); //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/mpdf/mpdf/src/Mpdf.php');
require_once(dirname(__DIR__, 3) . '/vendor/autoload.php'); require_once(dirname(__DIR__, 3) . '/vendor/autoload.php');
@ -31,20 +34,43 @@ class TechDocument extends AbstractBlockLayout
*/ */
protected $defaultSettings = []; protected $defaultSettings = [];
protected $storage_dir = "";
/** /**
* @param FormElementManager $formElementManager * @param FormElementManager $formElementManager
* @param array $defaultSettings * @param array $defaultSettings
*/ */
public function __construct(FormElementManager $formElementManager, array $defaultSettings) public function __construct(FormElementManager $formElementManager,
array $defaultSettings,
string $storage_dir)
{ {
$this->formElementManager = $formElementManager; $this->formElementManager = $formElementManager;
$this->defaultSettings = $defaultSettings; $this->defaultSettings = $defaultSettings;
$this->storage_dir = $storage_dir;
} }
public function getLabel() { public function getLabel() {
return 'Techical document'; 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, public function form(PhpRenderer $view,
SiteRepresentation $site, SiteRepresentation $site,
SitePageRepresentation $page = null, SitePageRepresentation $page = null,
@ -69,17 +95,6 @@ class TechDocument extends AbstractBlockLayout
public function render(PhpRenderer $view, SitePageBlockRepresentation $block) public function render(PhpRenderer $view, SitePageBlockRepresentation $block)
{ {
$parsedown = new Parsedown(); return "";
$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;
} }
} }