2

I'm trying to inject \Magento\Framework\Filter\FilterManager $filterManager Object to be able to use truncate fucnction in list.phtml

     $this->_filter->truncate($string, ['length' => $length, 'etc' => '...'])

So I overwride \Magento\Catalog\Block\Product\ListProduct. Everything is connected properly. I Overwride this method

  public function getLoadedProductCollection(){
           var_dump('working');
 } 

It's properly returning the string 'Working'. Now the problem comes when I use the __construct and try to inject Magento\Framework\Filter\FilterManager Class within the constructor. So i'm trying to do

    protected $_filterManager;

    public function __construct(
        \Magento\Catalog\Block\Product\Context $context,
        \Magento\Framework\Data\Helper\PostHelper $postDataHelper,
        \Magento\Catalog\Model\Layer\Resolver $layerResolver,
        CategoryRepositoryInterface $categoryRepository,
        \Magento\Framework\Url\Helper\Data $urlHelper,
        \Magento\Framework\Filter\FilterManager $filterManager,
        array $data = []
    ) {
        $this->_catalogLayer = $layerResolver->get();
        $this->_postDataHelper = $postDataHelper;
        $this->categoryRepository = $categoryRepository;
        $this->urlHelper = $urlHelper;
        $this->_filterManager = $filterManager;
        parent::__construct(
            $context,
            $data
        );

I clean cache, but the page fails to load giving this error.

a:4:{i:0;s:37:"Object DOMDocument should be created.";i:1;s:12622:"#0 

1 Answer 1

0

Try following way:

public function __construct(
    \Magento\Catalog\Block\Product\Context $context,
    \Magento\Framework\Data\Helper\PostHelper $postDataHelper,
    \Magento\Catalog\Model\Layer\Resolver $layerResolver,
    CategoryRepositoryInterface $categoryRepository,
    \Magento\Framework\Url\Helper\Data $urlHelper,
    \Magento\Framework\Filter\FilterManager $filterManager,
    array $data = []
) {
    $this->_catalogLayer = $layerResolver->get();
    $this->_postDataHelper = $postDataHelper;
    $this->categoryRepository = $categoryRepository;
    $this->urlHelper = $urlHelper;
    $this->filterManager = $filterManager;
    parent::__construct(
        $context,
        $postDataHelper,
        $layerResolver,
        $categoryRepository,
        $urlHelper,
        $data
    );
}
3
  • Still having the same issue. The site keeps breaking whenever I try to use the __Construct Commented Nov 7, 2016 at 13:10
  • Delete var/generation/* and clear cache
    – Sohel Rana
    Commented Nov 7, 2016 at 14:26
  • Run di:compile in your root Magento directory it should work Commented Feb 6, 2019 at 11:40

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.