+ component & twig function/filter for inject assets from manifest.json

This commit is contained in:
2022-01-09 19:09:18 +03:00
parent ae36a5cb0a
commit 829231a79f
8 changed files with 149 additions and 6 deletions

59
components/Manifest.php Normal file
View File

@ -0,0 +1,59 @@
<?php namespace Wpstudio\Assetsmanifest\Components;
use Cms\Classes\ComponentBase;
use Wpstudio\AssetsManifest\Classes\ManifestReader;
class Manifest extends ComponentBase
{
const LANG_PREFIX = 'wpstudio.assetsmanifest::lang.components.manifest.';
private ?ManifestReader $manifestReader;
public function componentDetails(): array
{
return [
'name' => self::LANG_PREFIX . 'name',
'description' => self::LANG_PREFIX . 'description',
];
}
public function defineProperties(): array
{
return [
'path' => [
'title' => self::LANG_PREFIX . 'properties.path.title',
'description' => self::LANG_PREFIX . 'properties.path.description',
'validationPattern' => '^[^/].*/manifest.json',
'validationMessage' => self::LANG_PREFIX . 'properties.path.validationMessage',
'placeholder' => 'assets/build/manifest.json',
'showExternalParam' => false,
'required' => true,
]
];
}
/**
* @return void
* @throws \Wpstudio\AssetsManifest\Classes\AssetsManifestException
*/
public function init(): void
{
app()->instance(Manifest::class, $this);
$this->prepareVars();
}
/**
* @return void
* @throws \Wpstudio\AssetsManifest\Classes\AssetsManifestException
*/
private function prepareVars(): void
{
$this->manifestReader = new ManifestReader(base_path($this->property('path')));
}
public function getManifestReader(): ManifestReader
{
return $this->manifestReader;
}
}

View File

@ -0,0 +1,3 @@
<p>This is the default markup for component manifest</p>
<small>You can delete this file if you want</small>