codefog / contao-haste

Haste is a collection of tools and classes to ease working with Contao
http://codefog.pl/extension/haste.html
MIT License
43 stars 24 forks source link

onGetContentElement requires ContentModel #105

Closed richardhj closed 7 years ago

richardhj commented 7 years ago

Your onGetContentElement wants argument 1 to be a ContentModel. However, I use a custom model, which indeed uses the functionality of tl_content but is no child of ContentModel.

For instance, I use Controller::getContentElement() for my purposes, using my custom model, causing the following error:

Fatal error: Uncaught exception TypeError with message Argument 1 passed to Haste\EventListener\AjaxReloadListener::onGetContentElement() must be an instance of Contao\ContentModel, instance of EPost\Model\LetterContent given, called in /Users/richard/Sites/sjr-beta/system/modules/core/library/Contao/Controller.php on line 491 thrown in composer/vendor/codefog/contao-haste/library/Haste/EventListener/AjaxReloadListener.php on line 22
#0 system/modules/core/library/Contao/Controller.php(491): Haste\EventListener\AjaxReloadListener->onGetContentElement(Object(EPost\Model\LetterContent), '\n
qzminski commented 7 years ago

Does your model extend \Contao\Model? I am not sure if we should change that though because Contao should expect ContentModel by default. @Toflar @aschempp

richardhj commented 7 years ago

Does your model extend \Contao\Model?

Exactly.

Toflar commented 7 years ago

It must extend ContentModel. There are many, many other places where this code would fail otherwise (e.g. the isVisibleElement hook where you MUST check for an instance of content element or front end module). So nothing to do here imho.

qzminski commented 7 years ago

Yup, I think so too. @richardhj I suggest that you extend ContentModel and have some method that works as a proxy for all the stuff you currently have in your custom model.