0

How override core block class for core Catalog Category Link widget? I try:

<preference for="Magento\Catalog\Block\Widget\Link"
            type="Vendor\ModuleName\Rewrites\Block\Widget\Catalog\Category\Widget"/>

But this is not working.

Although, this is the correct block and I use deBag, I go into it, and it is also described in the widget itself.

Part from core widget.xml

<widget id="catalog_category_link"
            class="Magento\Catalog\Block\Category\Widget\Link"
            is_email_compatible="true"
            placeholder_image="Magento_Catalog::images/category_widget_link.png">
        <label translate="true">Catalog Category Link</label>
        <description translate="true">Link to a Specified Category</description>
        <parameters>
            <parameter name="id_path" xsi:type="block" visible="true" required="true" sort_order="10">
                <label translate="true">Category</label>
                <block class="Magento\Catalog\Block\Adminhtml\Category\Widget\Chooser">
                    <data>
                        <item name="button" xsi:type="array">
                            <item name="open" xsi:type="string" translate="true">Select Category...</item>
                        </item>
                    </data>
                </block>
            </parameter>
            <parameter name="anchor_text" xsi:type="text" visible="true">
                <label translate="true">Anchor Custom Text 1234</label>
                <description translate="true">If empty, we'll use the category name here.</description>
            </parameter>
            <parameter name="title" xsi:type="text" visible="true">
                <label translate="true">Anchor Custom Title</label>
            </parameter>
            <parameter name="template" xsi:type="select" visible="true">
                <label translate="true">Template</label>
                <options>
                    <option name="default"
                            value="category/widget/link/link_block.phtml"
                            selected="true">
                        <label translate="true">Category Link Block Template</label>
                    </option>
                    <option name="link_inline" value="category/widget/link/link_inline.phtml">
                        <label translate="true">Category Link Inline Template</label>
                    </option>
                </options>
            </parameter>
        </parameters>
    </widget>
1

1 Answer 1

0

You need to check this file :

vendor/magento/module-catalog/etc/di.xml

arround line no.477

<virtualType name="Magento\Catalog\Block\Category\Widget\Link" type="Magento\Catalog\Block\Widget\Link">
        <arguments>
            <argument name="entityResource" xsi:type="object">Magento\Catalog\Model\ResourceModel\Category</argument>
        </arguments>
</virtualType>

Actually, the class which you are trying to override is virtual type, the original class is this one : Magento\Catalog\Block\Widget\Link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.