无法编辑或查看 Magento 产品 |参数 #1 ($meta) 必须是数组类型,在 /

问题描述 投票:0回答:1

从 Magento 1.9.2.1 迁移到 2.4.6,一切顺利,尝试在后端查看产品时出现问题(前端没有显示),我收到类型错误并且不确定如何解决此问题。

页面在尝试查看或编辑产品时显示此错误:

TypeError: Magento\Framework\View\Element\UiComponent\DataProvider\Sanitizer::sanitizeComponentMetadata(): Argument #1 ($meta) must be of type array, null given in /var/www/magento2/vendor/magento/framework/View/Element/UiComponent/DataProvider/Sanitizer.php:85
Stack trace:
#0 [internal function]: Magento\Framework\View\Element\UiComponent\DataProvider\Sanitizer->sanitizeComponentMetadata()
#1 /var/www/magento2/vendor/magento/framework/View/Element/UiComponent/DataProvider/Sanitizer.php(97): array_map()
#2 [internal function]: Magento\Framework\View\Element\UiComponent\DataProvider\Sanitizer->sanitizeComponentMetadata()
#3 /var/www/magento2/vendor/magento/framework/View/Element/UiComponent/DataProvider/Sanitizer.php(97): array_map()
#4 /var/www/magento2/vendor/magento/framework/View/Element/UiComponentFactory.php(332): Magento\Framework\View\Element\UiComponent\DataProvider\Sanitizer->sanitizeComponentMetadata()
#5 /var/www/magento2/vendor/magento/framework/View/Element/UiComponentFactory.php(231): Magento\Framework\View\Element\UiComponentFactory->mergeMetadata()
#6 /var/www/magento2/vendor/magento/framework/View/Layout/Generator/UiComponent.php(140): Magento\Framework\View\Element\UiComponentFactory->create()
#7 /var/www/magento2/vendor/magento/framework/View/Layout/Generator/UiComponent.php(103): Magento\Framework\View\Layout\Generator\UiComponent->generateComponent()
#8 /var/www/magento2/vendor/magento/framework/View/Layout/GeneratorPool.php(93): Magento\Framework\View\Layout\Generator\UiComponent->process()
#9 /var/www/magento2/vendor/magento/framework/View/Layout.php(365): Magento\Framework\View\Layout\GeneratorPool->process()
#10 /var/www/magento2/generated/code/Magento/Framework/View/Layout/Interceptor.php(68): Magento\Framework\View\Layout->generateElements()
#11 /var/www/magento2/vendor/magento/framework/View/Layout/Builder.php(129): Magento\Framework\View\Layout\Interceptor->generateElements()
#12 /var/www/magento2/vendor/magento/framework/View/Page/Builder.php(65): Magento\Framework\View\Layout\Builder->generateLayoutBlocks()
#13 /var/www/magento2/vendor/magento/framework/View/Layout/Builder.php(65): Magento\Framework\View\Page\Builder->generateLayoutBlocks()
#14 /var/www/magento2/vendor/magento/framework/View/Layout.php(271): Magento\Framework\View\Layout\Builder->build()
#15 /var/www/magento2/vendor/magento/framework/View/Layout.php(896): Magento\Framework\View\Layout->build()
#16 /var/www/magento2/generated/code/Magento/Framework/View/Layout/Interceptor.php(293): Magento\Framework\View\Layout->getBlock()
#17 /var/www/magento2/vendor/magento/module-backend/Model/View/Result/Page.php(26): Magento\Framework\View\Layout\Interceptor->getBlock()
#18 /var/www/magento2/generated/code/Magento/Backend/Model/View/Result/Page/Interceptor.php(23): Magento\Backend\Model\View\Result\Page->setActiveMenu()
#19 /var/www/magento2/vendor/magento/module-catalog/Controller/Adminhtml/Product/Edit.php(82): Magento\Backend\Model\View\Result\Page\Interceptor->setActiveMenu()
#20 /var/www/magento2/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Catalog\Controller\Adminhtml\Product\Edit->execute()
#21 /var/www/magento2/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Catalog\Controller\Adminhtml\Product\Edit\Interceptor->___callParent()
#22 /var/www/magento2/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Catalog\Controller\Adminhtml\Product\Edit\Interceptor->Magento\Framework\Interception\{closure}()
#23 /var/www/magento2/generated/code/Magento/Catalog/Controller/Adminhtml/Product/Edit/Interceptor.php(23): Magento\Catalog\Controller\Adminhtml\Product\Edit\Interceptor->___callPlugins()
#24 /var/www/magento2/vendor/magento/framework/App/Action/Action.php(111): Magento\Catalog\Controller\Adminhtml\Product\Edit\Interceptor->execute()
#25 /var/www/magento2/vendor/magento/module-backend/App/AbstractAction.php(151): Magento\Framework\App\Action\Action->dispatch()
#26 /var/www/magento2/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Backend\App\AbstractAction->dispatch()
#27 /var/www/magento2/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Catalog\Controller\Adminhtml\Product\Edit\Interceptor->___callParent()
#28 /var/www/magento2/vendor/magento/module-backend/App/Action/Plugin/Authentication.php(145): Magento\Catalog\Controller\Adminhtml\Product\Edit\Interceptor->Magento\Framework\Interception\{closure}()
#29 /var/www/magento2/vendor/magento/framework/Interception/Interceptor.php(135): Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch()
#30 /var/www/magento2/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Catalog\Controller\Adminhtml\Product\Edit\Interceptor->Magento\Framework\Interception\{closure}()
#31 /var/www/magento2/generated/code/Magento/Catalog/Controller/Adminhtml/Product/Edit/Interceptor.php(32): Magento\Catalog\Controller\Adminhtml\Product\Edit\Interceptor->___callPlugins()
#32 /var/www/magento2/vendor/magento/framework/App/FrontController.php(245): Magento\Catalog\Controller\Adminhtml\Product\Edit\Interceptor->dispatch()
#33 /var/www/magento2/vendor/magento/framework/App/FrontController.php(212): Magento\Framework\App\FrontController->getActionResponse()
#34 /var/www/magento2/vendor/magento/framework/App/FrontController.php(147): Magento\Framework\App\FrontController->processRequest()
#35 /var/www/magento2/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch()
#36 /var/www/magento2/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent()
#37 /var/www/magento2/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}()
#38 /var/www/magento2/generated/code/Magento/Framework/App/FrontController/Interceptor.php(23): Magento\Framework\App\FrontController\Interceptor->___callPlugins()
#39 /var/www/magento2/vendor/magento/framework/App/Http.php(116): Magento\Framework\App\FrontController\Interceptor->dispatch()
#40 /var/www/magento2/generated/code/Magento/Framework/App/Http/Interceptor.php(23): Magento\Framework\App\Http->launch()
#41 /var/www/magento2/vendor/magento/framework/App/Bootstrap.php(264): Magento\Framework\App\Http\Interceptor->launch()
#42 /var/www/magento2/pub/index.php(30): Magento\Framework\App\Bootstrap->run()
#43 {main}

/var/www/magento2/vendor/magento/framework/View/Element/UiComponent/DataProvider/Sanitizer.php:85:

magento@redacted:/var/www/magento2$ cat /var/www/magento2/vendor/magento/framework/View/Element/UiComponent/DataProvider/Sanitizer.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

declare(strict_types=1);

namespace Magento\Framework\View\Element\UiComponent\DataProvider;

use Magento\Framework\Phrase;

/**
 * Sanitizes data received from UI data providers.
 */
class Sanitizer
{
    /**
     * Extract rendering config from given UI data.
     *
     * @param array $data
     * @return bool|array
     */
    private function extractConfig(array $data)
    {
        /** @var array|bool $config */
        $config = [];
        if (array_key_exists('__disableTmpl', $data)) {
            //UI data provider has explicitly provided rendering config.
            $config = $data['__disableTmpl'];
            unset($data['__disableTmpl']);
        }

        return $config;
    }

    /**
     * Sanitizes data from a UI data provider.
     *
     * @param array $data
     * @return array
     */
    public function sanitize(array $data): array
    {
        $config = $this->extractConfig($data);
        $toProcess = [];
        array_walk(
            $data,
            function ($datum, string $key) use (&$config, &$toProcess) : void {
                if (is_array($datum)) {
                    //Each array must have it's own __disableTmpl property
                    $toProcess[$key] = $datum;
                } elseif ((
                        !is_bool($config) && !array_key_exists($key, $config)
                    )
                    && (is_string($datum) || $datum instanceof Phrase)
                    && preg_match('/\$\{.+\}/', (string)$datum)
                ) {
                    //Templating is not disabled for all properties or for this property specifically
                    //Property is a string that contains template syntax so we are disabling it's rendering
                    $config[$key] = true;
                }
            }
        );
        if ($toProcess) {
            //Processing sub-arrays
            $data = array_replace($data, array_map([$this, 'sanitize'], $toProcess));
        }
        if ($config !== []) {
            //Some properties require rendering configuration.
            $data['__disableTmpl'] = $config;
        }

        return $data;
    }

    /**
     * Sanitize a component's metadata.
     *
     * Will sanitize full component's metadata as well as metadata of it's child components.
     *
     * @param array $meta
     * @return array
     */
    public function sanitizeComponentMetadata(array $meta): array
    {
        if (array_key_exists('arguments', $meta)
            && is_array($meta['arguments'])
            && array_key_exists('data', $meta['arguments'])
            && is_array($meta['arguments']['data'])
            && array_key_exists('config', $meta['arguments']['data'])
            && is_array($meta['arguments']['data']['config'])
        ) {
            $meta['arguments']['data']['config'] = $this->sanitize($meta['arguments']['data']['config']);
        }
        if (array_key_exists('children', $meta) && is_array($meta['children'])) {
            $meta['children'] = array_map([$this, 'sanitizeComponentMetadata'], $meta['children']);
        }

        return $meta;
    }
}

我已经重新编译、重新编制索引并清除了缓存,但没想到这会解决问题。

php magento typeerror magento2 sanitization
1个回答
0
投票

问题出在您的数据库上,对于某些产品,元属性为空,所以这就是您看到此错误的原因。

© www.soinside.com 2019 - 2024. All rights reserved.