I just wrote a news Task to import address sets from an Json file to tt_address. That works great. Now I am stuck on the problem that I am creating new categories. But I couldn't assign them to the address set.
Somebody had a clue how to do this?
$jsondivision ='JsonCategorieName'
$address = 'AddressSet'
$categoryParent = 'PartentUID'
public function checkCategory($jsondivision, $address) {
$extbaseObjectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
$this->addressRepository = $extbaseObjectManager->get('Graphodata\Gdjson2ttaddress\Domain\Repository\GdAddressRepository');
$this->objectStorage = $extbaseObjectManager->get('TYPO3\CMS\Extbase\Persistence\ObjectStorage');
$this->categoryRepository = $extbaseObjectManager->get('Graphodata\Gdjson2ttaddress\Domain\Repository\GdCategoryRepository');
$newCategory = $extbaseObjectManager->get('Graphodata\Gdjson2ttaddress\Domain\Model\GdCategory');
$newCategory->setTitle($jsondivision);
$newCategory->setParent($categoryParent);
$this->categoryRepository->add($newCategory);
$address->addressRepository($newCategory);
}
You obviously already have a Category Model (
Graphodata\Gdjson2ttaddress\Domain\Model\GdCategory
), so you need to set a relation in your Address model like:and add getter, setter and a method to add further categories to your Address model:
Attention: to make this work your TCA settings have to be match some requirements. Take a look at the
news
extension (…/news/Configuration/TCA/tx_news_domain_model_news.php) for example to see how it works. Something like that: