Reputation: 634
I'm having a form in the frontend which creates an object of the model Question
. Each question needs to be assigned one Category
, which is selected in the form (via <f:form.select>
) and then submitted like so:
tx_qa_questionform[question][category] = 1
basically submitting the Category
's UID. After submitting the form I get an exception though:
#1297759968 TYPO3\CMS\Extbase\Property\Exception
Exception while property mapping at property path "category": Could not find a suitable type converter for "Category" because no such class or interface exists.
So it seems that the PropertyMapper
can't identify the domain Category
although being defined within the extension. Shouldn't this happen by itself? Or is there any configuration I missed to set up?
Model/Question.php
namespace Vendor\QA\Domain\Model;
class Question extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
/**
* @var Category $category
*/
protected $category;
/**
* @var string $name
*/
protected $name = '';
/**
* @var string $mail
*/
protected $mail = '';
/**
* @var string $content
*/
protected $content = '';
public function __construct(Category $category, string $name, string $mail, string $content) {
$this->setCategory($category);
$this->setName($name);
$this->setMail($mail);
$this->setContent($content);
}
public function setCategory(Category $category): void {
$this->category = $category;
}
public function getCategory(): Category {
return $this->category;
}
public function setName(string $name): void {
$this->name = $name;
}
public function getName(): string {
return $this->name;
}
public function setMail(string $mail): void {
$this->mail = $mail;
}
public function getMail(): string {
return $this->mail;
}
public function setContent(string $content): void {
$this->content = $content;
}
public function getContent(): string {
return $this->content;
}
}
Model/Category.php
namespace Vendor\QA\Domain\Model;
class Category extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
/**
* @var string $name
*/
protected $name;
public function __construct(string $name) {
$this->setName($name);
}
public function setName(string $name): void {
$this->name = $name;
}
public function getName(): string {
return $this->name;
}
}
Controller/FrontendController.php
namespace Vendor\QA\Controller;
use Vendor\QA\Domain\Model\Question;
use Vendor\QA\Domain\Repository\QuestionRepository;
use Vendor\QA\Domain\Repository\CategoryRepository;
class FrontendController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
private $questionRepository;
private $categoryRepository;
public function injectQuestionRepository(QuestionRepository $questionRepository) {
$this->questionRepository = $questionRepository;
}
public function injectCategoryRepository(CategoryRepository $categoryRepository) {
$this->categoryRepository = $categoryRepository;
}
public function formAction() {
$categories = $this->categoryRepository->findAll();
$this->view->assign('categories', $categories);
$this->view->assign('newQuestion', null);
}
public function createQuestionAction(Question $question) {
$this->questionRepository->add($question);
}
}
Upvotes: 0
Views: 869
Reputation: 2921
You need @phpdoc annotations in your controller action functions. See for example the showAction
here: https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/7-Controllers/1-Creating-Controllers-and-Actions.html#flow-pattern-display-a-single-domain-object
After changing phpdoc annotations, clear the system caches.
Upvotes: 1