Extending news at custom extension, Error: Typed property GeorgRinger\News\Domain\Model\News::$commentRepository must not be accessed before initialization #2153
When extending news with some additional code in my siteconfig
class News extends \GeorgRinger\News\Domain\Model\News {
protected CommentRepository $commentRepository;
public function __construct(CommentRepository $commentRepository)
{
$this->commentRepository = $commentRepository;
}
/**
* @return \T3\PwComments\Domain\Model\Comment
*/
public function getLatestComment() {
//some code
return = $this->commentRepository->findByUid($row['uid']);
}
}
in the cached files the construct method always is at the end of the file (e.g. typo3temp/var/cache/code/news/tx_news_domain_model_news.php) together with the other constructions out of the standard news extension and after my custom function (getLatestComment()). So I can understand the error message but wonder how this can be fixed. Do you have any hint?
This is, what is in the consolidated cached file (excerpt form the end):
protected CommentRepository $commentRepository;
/**
* @return \T3\PwComments\Domain\Model\Comment
*/
public function getLatestComment() {
//some code
return = $this->commentRepository->findByUid($row['uid']);
}
/**
* Initialize categories and media relation
*
* @return \GeorgRinger\News\Domain\Model\News
*/
public function __construct()
{
$this->categories = new ObjectStorage();
$this->contentElements = new ObjectStorage();
$this->relatedLinks = new ObjectStorage();
$this->falMedia = new ObjectStorage();
$this->falRelatedFiles = new ObjectStorage();
$this->tags = new ObjectStorage();
$this->commentRepository = $commentRepository;
}
having a repository in the model is really not the way to go. if this is a proper relation in tca, there is no need for such hack - otherwise use a VH to fetch the comments
When extending news with some additional code in my siteconfig
in the cached files the construct method always is at the end of the file (e.g. typo3temp/var/cache/code/news/tx_news_domain_model_news.php) together with the other constructions out of the standard news extension and after my custom function (getLatestComment()). So I can understand the error message but wonder how this can be fixed. Do you have any hint?
This is, what is in the consolidated cached file (excerpt form the end):