Models and DCA -> load and save_callbacks (Feature)
Hello my dearest Contao Core Developers,
There were several opportunities where it would have been nice if the Models use the defined load and save_callbacks from the dca. I assume you have thought about this one too - and I wonder why you have decided, that this is not implementable - or haven't you thought about this feature?
Small example:
Let's say you have a module that extends tl_news and gives the opportunity to import news from a crappy CMS to awesome contao. Within that interface you get almost every data and assign it to the NewsModel. For example:
$importedNewsEntries = $this->getEntriesFromSomewhere();
foreach($importedNewsEntries as $newsEntry)
{
$newsObj = new NewsModel();
$newsObj->headline = $newsEntry->title;
//.... other stuff like data, subheadline and so on is imported...
//now if you save the $newsObj
$newsObj->save(); //wouldn't it be nice if tl_news->generateAlias() is triggered?
}
Just an idea - do you think this would be a nice feature - that is not too hard to implement? I know, that the Models where designed to replace the usual $this->Database->prepare("UPDATE tl_whatever SET ...") bla bla - but don't you think a connection to the dca would be useful?
Kind regards Daniel
@danielhoover you don´t must save the entry by self. Do return the new value
@baumannsven I'm not sure if I understand fully what you mean? I know, that I can implement the tl_news->generateAlias() feature within the module - but why copying something where the creator of the dca already has taken care of?
@contao/developers What do you think about this?
I totally understand and like the idea. I don't know if there are any issues in case of BC?
The only problem I have is that DCA files are meant to run in the context of a data container like DC_Table and not within a model.
This will never work correctly imho. We should rather target for Doctrine entities to support their lifecycle callbacks.