How can you identify the files responsible for some functionality in Magento 2?

• If possible, start by finding the template that renders this information. Find a class name on that element that seems unique. Search the entire Magento root for this string. That should take you to a template. Once you find the template, search for that template’s file name. This should bring you to a Layout XML file (or possibly a PHP file). In that Layout XML file, you should see the block or view model. The Layout XML file will also tell you what handle is being used and you can find the controller from that (more on this later).

• You can also set a breakpoint (with a debugger tool such as xdebug) on a line in this template. Refresh the page, or complete the action again. Once the breakpoint Architecture, 14 triggers, you can review the call stack to find relevant code. Set breakpoints through the call stack. Cancel the request and repeat it. Step through each breakpoint you just set to get more context on this problem.

• The above doesn’t always work in every situation.

You can enable Block Hints with the bin/magento dev:template-hints:enable . This only works in Developer mode.

• As you grow in understanding of Magento, you will find that autocomplete is one of the best inventions since sliced bread. For example, if you need to load all data in an order, you know that repositories are the preferred interface for loading data.

You would then add to your constructor (and autocomplete) an OrderRepositoryInterface .

• Template Path Hints



Ready to elevate your e-commerce business?

Discuss your business objectives with us. Get in touch today to explore ways we can assist in reaching them.

Copyright © 2021-2024 ArmMage LLC. All rights reserved.