Skip to content

Cannot remove product_list_toolbar in XML #9413

Closed
@joshfortyfour

Description

@joshfortyfour

Preconditions

  1. Magento 2.1.6
  2. PHP 7.0.18
  3. MySql 5.7.18
  4. Apache 2.4

Steps to reproduce

  1. Create Magento_Catalog/layout/catalog_category_view.xml in custom theme
  2. Add the following code:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <referenceBlock name="product_list_toolbar" remove="true"/>
        </referenceContainer>
    </body>
</page>

Expected result

  1. The toolbar should be removed from the product list pages.

Actual result

  1. The toolbar remains on the page. After talking with Alan Storm about the issue he dug into the vendor/magento/module-catalog/Block/Product/ListProduct.php file and, specifically, the getToolbarBlock() method which does this:
public function getToolbarBlock()
    {
        $blockName = $this->getToolbarBlockName();
        if ($blockName) {
            $block = $this->getLayout()->getBlock($blockName);
            if ($block) {
                return $block;
            }
        }
        $block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, uniqid(microtime()));
        return $block;
    }

It checks for the toolbar and, if it finds it, returns it. If it doesn't find it (i.e., it's removed via xml), it renders it to the page.

Metadata

Metadata

Assignees

Labels

Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions