0

I've been comparing two versions of a website I'm working on -- one is fine and the other has a broken layout -- and the main difference I've found between them is the following file:

generated/code/Magento/Theme/Block/Html/Topmenu/Interceptor.php

My question is: where in the codebase is Magento 2 being directed to create this file? If I delete it and refresh the website, it's automatically generated again.

2 Answers 2

0

it's generated as soon as somewhere a plugin for this class is registered. At least one plugin is added in the Magento_Catalog module under etc/di.xml to add the categories to the top navigation

https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Catalog/etc/di.xml#L76

you can read more about plugins in the devdocs: http://devdocs.magento.com/guides/v2.2/extension-dev-guide/plugins.html

0

Code is generated when the Magento application cannot find a class when executing code.

A Factory class creates instances of a type. See Instantiating objects with factories for more information. Factories are directly referenced within application code.

You can designate a Proxy to be generated for a type in order to ensure the type is not instantiated until it is needed. See Proxies for more information. Proxies are directly referenced within DI configuration.

Interceptor classes are automatically generated to facilitate Magento’s plugin system. An interceptor class extends a type and is returned by the Object Manager to allow multiple plugin classes to inject logic into different methods. Interceptors work behind the scenes and are not directly referenced in application code.

Why should you regenerate code?

Suppose a Customer or Proxy class for a Customer class is generated and the Customer class has new methods added to it. Because a Customer or Proxy exists on the file system, it is not regenerated. However, the Customer or Proxy implementation is incomplete now because it does not have the new methods. In this case, you must regenerate the Customer or Proxy class.

If the code generator implementation itself is changed, you must regenerate all the classes. This is rare, however.

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.