Search $block->getData('configProvider') in form.mini.phtml returns null after upgrade to 2.3.6

magento.stackexchange https://magento.stackexchange.com/questions/326733

  •  15-04-2021
  •  | 
  •  

Question

In 2.3.6, the following line was added to form.mini.phtml:

$configProvider = $block->getData('configProvider');

Since the upgrade, this returns null and causes a fatal error due to this subsequent call on the null object:

$configProvider->isSuggestionsAllowed()

"Uncaught Error: Call to a member function isSuggestionsAllowed() on null"

My site uses a custom module that adds notices during shipping and checkout using blocks. This module is causing the fatal error, but it shouldn't have anything to do with the search block.

I need to change the module di.xml file or custom class to return a configProvider for search, or tell it to use the default class. Can anyone point me the right direction? Many thanks.

Here is my code:

/app/code/Port80/CIBC/etc/frontend/di.xml


<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Model\CompositeConfigProvider">
        <arguments>
            <argument name="configProviders" xsi:type="array">
                <item name="cms_block_config_provider" xsi:type="object">Port80\CIBC\Model\ConfigProvider</item>
            </argument>
        </arguments>
    </type> 
    <preference for="Magento\Customer\Model\Vat" type="Port80\CIBC\Model\Customer\Vat" />
</config>

/app/code/Port80/CIBC/Model/ConfigProvider.php



use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\View\LayoutInterface;

class ConfigProvider implements ConfigProviderInterface
{
    /** @var LayoutInterface  */
    protected $_layout;

    public function __construct(LayoutInterface $layout)
    {
        $this->_layout = $layout;
    }

    public function getConfig()
    {
        return [
            'payment_notices' => $this->_layout->createBlock('Magento\Cms\Block\Block')->setBlockId('checkout_payment_notices')->toHtml(),
            'shipping_notices' => $this->_layout->createBlock('Magento\Cms\Block\Block')->setBlockId('checkout_shipping_notices')->toHtml()
        ];
    }
}
Was it helpful?

Solution

I had a similar problem after upgrading to 2.3.6. One of my theme layout files referred to the Magento_Search::form.mini.phtml template without the configProvider argument. adding the configProvider argument like this solved the issue:

<block class="Magento\Framework\View\Element\Template" name="top.search" as="topSearch" template="Magento_Search::form.mini.phtml">
    <arguments>
        <argument name="configProvider" xsi:type="object">Magento\Search\ViewModel\ConfigProvider</argument>
    </arguments>
</block>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top