3

I wanted to ask this question a long time ago)
It is A very simple thing - modify any property for data object dynamically (product,category or something else).

Frankly I always used the observer class for this purpose.

But corresponding to a magento technical guidlines:

4.3. Plugins SHOULD NOT be added to data objects.
14.3. Events SHOULD NOT change a state of observable objects.

Can anybody explain how should I add timestamp, say, to the product meta_title property on the front conforming to these rules?

P.S. Please, do not suggest to change meta title in the template)
Let's assume, I need this modified meta_title in many places.

[Edited]
P.S.2 Formally the class rewrite (or reference) is a solution in this situation, but we know it is a bad practice overall and also it is too excessive to use reference to modify one property.

1 Answer 1

0

To conform to both those guidelines you are able to create a preference for the Magento\Cms\Api\Data\PageInterface via a di.xml preference which then substitutes the behaviour of getMetaTitle().

But as these are guidelines only I would rate using an after plugin more favourable to the above, ie afterGetMetaTitle().

The word observe usually implies that no action is done on what is being observed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.