0

I think there were previous issues with Magento 2 allowing extensions namespaces to be lower case when we initially submitted ours. But now, it seems that Magento 2.2.x enforces uppercase first character, as we got this error:

Exception #0 (Magento\Framework\Config\Dom\ValidationException): Element 'block', attribute 'class': [facet 'pattern'] The value 'vendorname\extensionname\Block\BlockName' is not accepted by the pattern '[A-Z][_a-zA-Z\d](\[A-Z][_a-zA-Z\d])'.*

However, when we updated our extension code to use uppercase everywhere (except the name in the composer.json file), our extension can't seem to find the various classes we now have within Model and Block, and got the following error after compiling:

PHP message: PHP Fatal error: Class 'Vendorname\Extensionname\Block\BlockName' not found in /var/www/magento89/generated/code/Vendorname/Extensionname/Block/BlockName/Interceptor.php on line 7" while reading response header from upstream

The code for the Block in question looks like this (fairly straight forward):

<?php

namespace Vendorname\Extensionname\Block;

class BlockName extends \Magento\Catalog\Block\Product\AbstractProduct
{
    public function __construct(
        \Magento\Catalog\Block\Product\Context $context,
        array $data = []
    ) {
        parent::__construct($context, $data);
    }

    public function getProductsCollection()
    {
        $block=$this->getLayout()->getBlock('category.products.list');
        return $block->getLoadedProductCollection();
    }
}

Edit: adding in the Interceptor code

<?php
namespace Vendorname\Extensionname\Block\BlockName;

/**
 * Interceptor class for @see \Vendorname\Extensionname\Block\BlockName
 */
class Interceptor extends \Vendorname\Extensionname\Block\BlockName implements \Magento\Framework\Interception\InterceptorInterface
{
    use \Magento\Framework\Interception\Interceptor;

    public function __construct(\Magento\Catalog\Block\Product\Context $context, array $data = array())
    {
        $this->___init();
        parent::__construct($context, $data);
    }

    /**
     * {@inheritdoc}
     */
    public function getImage($product, $imageId, $attributes = array())
    {
        $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getImage');
        if (!$pluginInfo) {
            return parent::getImage($product, $imageId, $attributes);
        } else {
            return $this->___callPlugins('getImage', func_get_args(), $pluginInfo);
        }
    }
}

Is there somewhere in the database that might contain the old namespace somewhere, and it's using that instead of the new updated uppercased namespace?

Any help would be greatly appreciated!

  • Delete the contents of your var/generated/code folder and then run setup:di:compile – andyjv Nov 1 '18 at 19:53
  • @andyjv I've tried this already, but comes out with the same error – Blake Finney Nov 1 '18 at 20:00
0

Please rename vendorname/extensioname to Vendorname/Extensionname

  • I've tried completely renaming the Block name to a few different things, but none seemed to work, unfortunately. – Blake Finney Nov 1 '18 at 20:02
  • Strange for me is that : Fatal error: Class 'Vendorname\Extensionname\Block\BlockName' not found in /var/www/magento89/generated/code/Vendorname/Extensionname/Block/Blockname(/Interceptor.php on line 7 Why in first place with have BlockName and after that I see Blockname? There has to be some problem with filename? Any chance to get access to code? – rafal-kos Nov 1 '18 at 20:23
  • Ah, I think the lowercase n might've been a typo by me. Have edited above. – Blake Finney Nov 1 '18 at 20:27
  • What is in app/etc/config.php? Is there correct module name? – rafal-kos Nov 1 '18 at 20:34
  • Yes, the module is named correctly in app/etc/config.php – Blake Finney Nov 1 '18 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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