1

Thanks in advance :)

I can confirm the module is working correctly. I have tried adding the following to the di.xml file in my module:

<preference for="Magento\Framework\View\Page\Config\Renderer" type="Vendor\Module\Framework\View\Page\Config\Renderer" />

And the following to my Renderer.php file in app\code\Vendor\Module\Framework\View\Page\Config:

<?php

namespace Vendor\Module\Framework\View\Page\Config;

use Magento\Framework\View\Page\Config\Renderer as MagentoRenderer;

class Renderer extends MagentoRenderer
{

  /**
   * Render head content
   *
   * @return string
   */
  public function renderHeadContent()
  {
    $result = '';
    return $result;
  }
}

Without any effect and no entries in any log to debug.

I can make these changes directly here:

vendor\magento\framework\View\Page\Config\Renderer.php

or here

lib\internal\Magento\Framework\View\Page\Config\Renderer.php

and the changes are then visible, but for obvious reasons would like to stay away from the core and restrict my changes to modules.

I would like to start with overriding public function renderHeadContent, but ultimately, I would like to modify protected function addDefaultAttributes. Any advice or assistance would be appreciated, thanks!

Tried: Magento 2: Overriding a protected function that implements another interface

Also tried: How to override /vendor/magento/framework/Logger/Handler/system.php

Also tried: Override framework file vendor/magento/framework/View/Element/Html/Link/Current.php

2 Answers 2

1

I think you need to understand some additional logic related to this renderer.

Firstly see vendor/magento/module-developer/etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <!-- ... -->
    <type name="Magento\Framework\View\Result\Page">
        <arguments>
            <argument name="pageConfigRendererFactory" xsi:type="object">Magento\Developer\Model\View\Page\Config\RendererFactory</argument>
        </arguments>
    </type>
    <!-- ... -->
    <type name="Magento\Developer\Model\View\Page\Config\RendererFactory">
        <arguments>
            <argument name="rendererTypes" xsi:type="array">
                <item name="client_side_compilation" xsi:type="string">Magento\Developer\Model\View\Page\Config\ClientSideLessCompilation\Renderer</item>
                <item name="server_side_compilation" xsi:type="string">Magento\Framework\View\Page\Config\Renderer</item>
            </argument>
        </arguments>
    </type>
    <!-- ... -->
</config>

If you'll check a logic implemented in \Magento\Developer\Model\View\Page\Config\RendererFactory::create you can see that Magento uses 2 different workflow depends on state mode, etc.

You can continue to use preference for Magento\Framework\View\Page\Config\Renderer, but you are need to add additional preference for Magento\Developer\Model\View\Page\Config\ClientSideLessCompilation\Renderer

The alternative way is set your custom renders to Magento\Developer\Model\View\Page\Config\RendererFactory

0

In my case, the Developer setting was set to Client-side compilation and this was preventing my Renderer overrides from being triggered, since Magento\Framework\View\Page\Config\Renderer is only triggered with Server-side compilation.

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.