'orocommerce wysiwyg editor - file / image wrong src

I have similar issue that Wysiwyg images not moved to public cache

when I add a file or image in wysiwyg, it displays properly in editor but after saving, it doesn't display in admin nor front.
Generated markup src is incorrect/not properly replaced:

<picture id="irozi"><source srcset="{{ wysiwyg_image('22','d9ffaffc-f286-4707-bd4b-29504628acc2','wysiwyg_original','webp') }}" type="image/webp"><img src="{{ wysiwyg_image('22','0872c470-f50a-4290-8043-96ffd5e205d2','wysiwyg_original','') }}" id="icysf" alt="test picture"></picture>  
<a href="{{ wysiwyg_file('21','43acd9a6-4b54-4439-9d1d-08241dd5a63e') }}" title="test file" target="_self" class="digital-asset-file no-hash">my-file.csv</a>

My field already exists (in a custom bundle) and "File applications" doesn't show in "Entity Management". Do I need that conf? How to achieve it with a migration?

What else should I do to have a correct src for files and images?



Solution 1:[1]

File applications config is required if you want to display an image that is ACL protected within the application. You can set it using a migration, e.g.:

$queries->addQuery(
            new UpdateEntityConfigFieldValueQuery(
                'Acme\Demobundle\Entity\FancyFile',
                'image',
                'attachment',
                'file_applications',
                ['default', 'commerce']
            )
        );

The issue might also be related to image processing. Please, check the log file for errors.

UPDATE

Also, as a WYSIWYG field has some twig placeholders it has to be rendered with the applied postprocessing.

On the storefront it should be rendered with:

{% if entity.contentStyle|length -%}
    {%- apply spaceless -%}
        <style type="text/css">{{ entity.contentStyle|render_content }}</style>
    {%- endapply -%}
{%- endif %}

{{ entity.content|render_content }}

There are also ready-to-use layout block types: wysiwyg_style and text_with_placeholders.

On the back-office there is a macro

{% import '@OroEntityConfig/macros.html.twig' as entityConfig %}
{{ entityConfig.renderWysiwygContentPreview(entity.content)|raw }}

Where the entity.content is the field path to render.

The team will update the documentation to mention that.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1