Magento – How to debug: Broken reference: No element found with ID ‘customer’

layout-updatemagento2theme

Getting a critical error that doesn't seem to be affecting anything on the frontend that I can notice.

main.CRITICAL: Broken reference: No element found with ID 'customer'.

Error is caught in Magento\Framework\View\Layout\GeneratorPool::moveElementInStructure when it's trying to do

$structure->setAsChild($element, $destination, $alias);

The arguments have values…

$element = top.links
$destination = customer
$alias = top.links

I've narrowed it down to the file app/design/frontend/MyConpany/default/Magento_Theme/layout/default.xml causing this problem. When this file is removed, no errors are logged, but there are no top.links or customer references there. How do you debug this?

app/design/frontend/MyConpany/default/Magento_Theme/layout/default.xml:

 <container name="above.header.msg" htmlTag="div" htmlClass="above-header--msg">
        <block class="Magento\Framework\View\Element\Template" name="top-header-content" template="Magento_Theme::html/top-content.phtml" />
     </container>
     <referenceContainer name="header.panel" htmlClass="panel header page-content">
        <block class="Magento\Framework\View\Element\Html\Links" name="header.links">
           <arguments>
              <argument name="css_class" xsi:type="string">header links</argument>
           </arguments>
        </block>
     </referenceContainer>
     <referenceBlock name="logo">
        <arguments>
           <argument name="logo_img_width" xsi:type="number">250</argument>
           <argument name="logo_img_height" xsi:type="number">60</argument>
        </arguments>
     </referenceBlock>
     <referenceContainer name="main">
        <container name="content.top" label="Main Content Top" />
        <container name="content" label="Main Content Area" />
        <container name="content.aside" label="Main Content Aside" />
        <container name="content.bottom" label="Main Content Bottom" />
     </referenceContainer>
     <referenceContainer name="page.bottom.container">
        <container name="page.bottom" label="Before Page Footer" htmlTag="div" htmlClass="content" />
     </referenceContainer>
     <referenceContainer name="footer-container">
        <block class="Magento\Cms\Block\Block" name="footer">
           <arguments>
              <argument name="block_id" xsi:type="string">footer</argument>
           </arguments>
        </block>
        <block class="Magento\Theme\Block\Html\Footer" name="copyright" template="html/copyright.phtml" />
     </referenceContainer>
     <referenceContainer name="content">
        <block class="Magento\Framework\View\Element\FormKey" name="formkey" />
     </referenceContainer>
     <move element="copyright" destination="before.body.end" />
  </body>

Best Answer

It's possible that there is another layout file somewhere which is supposed to reference the above.header.msg container that's defined here and add a block element named customer, but isn't doing so for some reason.

This file is overriding vendor/magento/module-theme/view/frontend/layout/default.xml , and the above.header.msg is the only container declaration in the default.xml override file you've provided, that isn't in vendor/magento/module-theme/view/frontend/layout/default.xml . Also, there is a block named top.links in this base default.xml file.

I'd first start by removing the <move element="copyright" destination="before.body.end" /> declaration, since the error is related to the moveElementInStructure. If that works, I'd investigate the existence of the copyright element being referred to.

Otherwise, I'd look through the custom code for a customer block to see if there's one in a layout file, if so, try and figure out why it's not behaving correctly. Next, I'd look through custom blocks to see if there's any block creation logic that's not behaving. Finally, I'd see if there was a layout which was in fact removing a customer block, thereby causing this issue.

That's what comes to mind right now. It's hard to say more without more context.

I would be interested in your findings.

Good luck

Doc reference to the default.xml file: basic layouts

UPDATE There's a reference to these types of critical messages being logged while in developer mode here: Issue:#3507. There's also a recently opened issue here: Issue:#7715.