Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freeform formatting template resources are not Craft Cloud compatible #1660

Open
timkelty opened this issue Nov 26, 2024 · 6 comments
Open
Assignees
Labels
issue Something isn't working correctly

Comments

@timkelty
Copy link
Contributor

What happened?

Craft Cloud requires that front-end resources be defined as asset bundles, so it can publish them to the CDN at deploy time.

Freeform ships with Formatting Templates that attempt to load CSS/JS via view.assetManager.publishedUrl, but because those are never defined as Asset Bundles, they are never copied to the CDN: https://github.com/solspace/craft-freeform/blob/v5/packages/plugin/src/templates/_templates/formatting/flexbox/index.twig#L2-L3

The result is a URL to something like: https://cdn.craft.cloud/{envId}/builds/{buildId}/cpresources/Solspace-Freeform-templates-_templates-formatting-flexbox/_main.css which will be a 404.

The most straightforward way to address this would probably be to move the referenced assets to packages/plugin/src/Resources/{css,js} and a corresponding \Solspace\Freeform\Resources\Bundles\TemplateBundle`.

Errors and Stack Trace (if available)

No response

How can we reproduce this?

Render a form using a formatting template that includes resources, eg flexbox.

Freeform Edition

Pro

Freeform Version

5.6.8

Craft Version

5.4.9

When did this issue start?

No response

Previous Freeform Version

No response

@timkelty timkelty added the issue Something isn't working correctly label Nov 26, 2024
@timkelty timkelty changed the title Freeform template resources are not Craft Cloud compatible Freeform formatting template resources are not Craft Cloud compatible Nov 26, 2024
@kjmartens
Copy link
Contributor

Thank you for bringing this to our attention @timkelty.

We'll look into this and address it shortly. 🙂

@kjmartens
Copy link
Contributor

This should be resolved now in Freeform 5.8 🙂

@kjmartens
Copy link
Contributor

Sorry about this @timkelty. We'll look into it shortly.

@kjmartens kjmartens reopened this Dec 11, 2024
@gustavs-gutmanis
Copy link
Contributor

Hi @timkelty,

I moved all assets into their own Bundles and am loading the bundles within the templates in this commit: 05cddb8

I'm not really sure what else to do here, could you give some guidance, please?

@timkelty
Copy link
Contributor Author

timkelty commented Dec 12, 2024

@gustavs-gutmanis The conversion to asset bundles makes them publishable, which is great. What's happening now is an issue with alias resolution.

Asset bundle classes are instantiated and published in isolation, meaning the @freeform-formatting-templates alias defined \Solspace\Freeform\Freeform::init isn't available when the bundle is published.

The easiest fix is to always use the automatic alias the plugin installer adds for you based on your, in this case @Solspace/Freeform. Which would make these asset bundles' sourcePath look something like:

// @freeform-formatting-templates is defined in \Solspace\Freeform\Freeform::init, which isn't called when `craft cloud/asset-bundles/publish` publishes asset bundles to the CDN
// $this->sourcePath = '@freeform-formatting-templates/flexbox';

// So, if we want to use an alias, we can use the automatically registered one:
$this->sourcePath = '@Solspace/Freeform/templates/_templates/formatting/flexbox';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue Something isn't working correctly
Development

No branches or pull requests

3 participants