Skip to content

wf-assets

Intro

wf-assets are some assets (JS/JSON/HTML files) that are used in Javascript code, but they are generated by the Symfony application. One of the reasons for their existence is being able to share parameters between Symfony application and Javascript code.

These assets are downloaded in one of the following ways:

  • make wf_assets - usually used in the CI environment
  • make dev - used in the development environment.

filemap.json

When running make dev, besides initially downloading the wf-assets, it also sets up listeners for the source files - files used by Symfony to generate the wf-assets. These can be PHP files, but also YML or XML files.

The list of url => [dependencies] is stored in the vendor/wfcms/standard/Wf/Bundle/CmsBaseAdminBundle/Resources/config/gulp/filemap.json file.

Note: Besides the URIs being listed there, XalokNext also downloads every wf-html file, that is, twig files in the src/App/Bundle/CmsBundle/Resources/views/Template directory.

v7.3+Extending filemap.json

If one wants to add a new wf-asset in the project, one should add a subscriber for the Wf\Bundle\CmsBaseBundle\WfAssets\Event\FilemapLoadEvent:

php
<?php

namespace App\Bundle\CmsAdminBundle\WfAssets;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Wf\Bundle\CmsBaseBundle\WfAssets\Event\FilemapLoadEvent;

class FilemapSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [FilemapLoadEvent::class => 'onFilemapLoad'];
    }

    public function onFilemapLoad(FilemapLoadEvent $event)
    {
        $filemap = $event->getFilemap();
        $filemap['bundles/appcms/javascripts/example-url.html'] = [
            './app/config/**/*.yml',
            './src/App/Bundle/CmsAdminBundle/Controller/JavascriptController.php',
        ];
        $event->setFilemap($filemap);
    }
}

Note: If you're doing this inside the project, the event subscriber is automatically set up through Symfony's autowiring.

If you do it inside a bundle (e.g. a client-group bundle) you need to manually add the service definition and tag it:

xml
<service id="wf_firebase.assets.filemap_subscriber" class="Wf\Bundle\FirebaseBundle\WfAssets\FilemapSubscriber">
    <tag name="kernel.event_subscriber" />
</service>

Note: The above example shows only how to add an example wf-asset with some dependencies. You must add the route/controller/action logic for the URI and adapt the dependencies according to the needs.