Magento – Incompatible argument type error in Magento 2.2.2

compilationerrormagento2

I have installed Magento 2.2.2.

Running php bin/magento setup:di:compile result in this error:

Magento\Backend\Model\View\Layout\GeneratorPool
Incompatible argument type: Required type: \Magento\Framework\View\Layout\Condition\ConditionFactory.php

Actual type: \Magento\Framework\App\Config\ScopeConfigInterface; File: 
vendor/magento/module-backend/Model/View/Layout/GeneratorPool.php

In

vendor/magento/framework/View/Layout/Condition/ConditionFactory.php:

<?php

namespace Magento\Framework\View\Layout\Condition;

use Magento\Framework\ObjectManagerInterface;

/**
 * Factory for composite.
 */
class ConditionFactory
{
    /**
     * @var ObjectManagerInterface
     */
    private $objectManager;

    /**
     * @param ObjectManagerInterface $objectManager
     */
    public function __construct(ObjectManagerInterface $objectManager)
    {
        $this->objectManager = $objectManager;
    }

    /**
     * @param array $elementVisibilityConditions
     *
     * @return Condition
     */
    public function create(array $elementVisibilityConditions)
    {
        $conditions = [];
        foreach ($elementVisibilityConditions as $condition) {
            $conditions[] = $this->objectManager->create($condition['name']);
        }
        return $this->objectManager->create(Condition::class, ['conditions' => $conditions]);
    }
}

In

vendor/magento/module-backend/Model/View/Layout/GeneratorPool.php:

<?php
namespace Magento\Backend\Model\View\Layout;

use Magento\Framework\View\Layout\ScheduledStructure;
use Magento\Framework\View\Layout\Data\Structure;

/**
 * Pool of generators for structural elements
 */
class GeneratorPool extends \Magento\Framework\View\Layout\GeneratorPool
{
    /**
     * @var Filter\Acl
     */
    protected $aclFilter;

    /**
     * @param ScheduledStructure\Helper $helper
     * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
     * @param \Magento\Framework\App\ScopeResolverInterface $scopeResolver
     * @param \Psr\Log\LoggerInterface $logger
     * @param Filter\Acl $aclFilter
     * @param array $generators
     */
    public function __construct(
        ScheduledStructure\Helper $helper,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Framework\App\ScopeResolverInterface $scopeResolver,
        \Psr\Log\LoggerInterface $logger,
        Filter\Acl $aclFilter,
        array $generators = null
    ) {
        $this->aclFilter = $aclFilter;
        parent::__construct(
            $helper,
            $scopeConfig,
            $scopeResolver,
            $logger,
            $generators
        );
    }

    /**
     * Build structure that is based on scheduled structure
     *
     * @param ScheduledStructure $scheduledStructure
     * @param Structure $structure
     * @return $this
     */
    protected function buildStructure(ScheduledStructure $scheduledStructure, Structure $structure)
    {
        parent::buildStructure($scheduledStructure, $structure);
        $this->aclFilter->filterAclElements($scheduledStructure, $structure);
        return $this;
    }
}

What is the fix?

Best Answer

It used to be there but was removed. Make sure no di.xml still references it. So look for something like this:

<preference for="Magento\Framework\View\Layout\GeneratorPool"
    type="Magento\Backend\Model\View\Layout\GeneratorPool" />

On the cause: It looks like you copied Magento 2.2 over an earlier version and something botched your upgrade path. Did you follow these instructions?

Related Topic