elgentos / magento2-prismicio

Magento 2 Prismic integration
GNU General Public License v3.0
38 stars 18 forks source link

Allow Richtext block to addData for extra classes in xml #56

Closed wahidnory closed 4 months ago

wahidnory commented 3 years ago

Currently we have the option to inject a RichText block with content and it generates whatever the user selected as the element type. Example:

<block class="Elgentos\PrismicIO\Block\Dom\RichText" name="deal_of_the_week_text"  template="text"/>

What currently isn't possible is this:

<block class="Elgentos\PrismicIO\Block\Dom\RichText" name="deal_of_the_week_text"  template="text"/>
        <action method="addData">
                <argument name="data" xsi:type="array">
                    <item name="htmlClass" xsi:type="string">someclass some-other-class</item>
                </argument>
         </action>
</block>

This might be possible with a different implementation for the HtmlSerializer

The serializer receives the object and the content. And returns the serialized content.

Food for thought but would be nice to have the ability to add extra classes the RichText block

JeroenBoersma commented 4 months ago

We have the Elgentos\PrismicIO\Block\Container class for this which accepts the same data as a <container ... >

<block class="Elgentos\PrismicIO\Block\Container" name="deal_of_the_week_text">
        <action method="addData">
                <argument name="data" xsi:type="array">
                    <item name="htmlTag" xsi:type="string">div</item>
                    <item name="htmlClass" xsi:type="string">someclass some-other-class</item>
                </argument>
         </action>
    <block class="Elgentos\PrismicIO\Block\Dom\RichText" template="text"/>
</block>

Besides of that you can also implement a \Elgentos\PrismicIO\ViewModel\HtmlSerializer

You can do some implementation of, extend it or create a plugin.

<block class="Elgentos\PrismicIO\Block\Dom\RichText" name="deal_of_the_week_text"  template="text"/>
    <arguments>
        <argument name="htmlSerializer" xsi:type="object">\Elgentos\PrismicIO\ViewModel\HtmlSerializer</argument>
    </arguments>
</block>