2017-12-15 5 views
0

Jsonファイルからtt_addressにアドレスセットをインポートするためのニュースタスクを書きました。それは素晴らしい作品です。今、私は新しいカテゴリを作成しているという問題に悩まされています。しかし、私はそれらをアドレスセットに割り当てることができませんでした。インポートされたtt_addressに作成された新しいカテゴリをTYPO3で設定しました8.7

誰かがこれを行う手掛かりを持っていましたか?

$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); 
} 
+0

'$ address-> addressRepository($ newCategory);'は何ですか? – Wolfgang

+0

それはAddressSetにCategorieUidを設定します...私は間違っていることを知っていますが、正しく設定する方法はわかりません。 tt_Addressは、m:nの関係を持つtypo3 sys_categorieを使用します。 Typoはカテゴリを適切に設定するためのfunktionを持っているはずです。 – hrdyy

答えて

0

あなたは明らかすでにCategoryモデル(Graphodata\Gdjson2ttaddress\Domain\Model\GdCategory)を持っているので、あなたのようなあなたのアドレスモデルで関係を設定する必要があります。

/** 
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Graphodata\Gdjson2ttaddress\Domain\Model\GdCategory> 
* @lazy 
*/ 
protected $categories; 

とゲッター、セッター、さらにカテゴリを追加するためのメソッドを追加します

/** 
* Get categories 
* 
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Graphodata\Gdjson2ttaddress\Domain\Model\GdCategory> 
*/ 
public function getCategories() 
{ 
    return $this->categories; 
} 

/** 
* Set categories 
* 
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $categories 
*/ 
public function setCategories($categories) 
{ 
    $this->categories = $categories; 
} 

/** 
* Adds a category to this categories. 
* 
* @param \Graphodata\Gdjson2ttaddress\Domain\Model\GdCategory $category 
*/ 
public function addCategory($category) 
{ 
    $this->getCategories()->attach($category); 
} 

注意:これはあなたのTCAの設定がいくつかrequirと一致する必要があります動作させるためにあなたのアドレスモデルへements。 news拡張子(.../news/Configuration/TCA/tx_news_domain_model_news.php)を見て、その動作を確認してください。次のようなものがあります:

… 
'categories' => [ 
    'config' => [ 
     'type' => 'select', 
     … 
     'MM' => 'sys_category_record_mm', 
     'MM_match_fields' => [ 
      'fieldname' => 'categories', 
      'tablenames' => 'tx_gdjson2ttaddress_gdaddress', 
     ], 
     'MM_opposite_field' => 'items', 
     'foreign_table' => 'sys_category', 
     'foreign_table_where' => ' AND (sys_category.sys_language_uid = 0 OR sys_category.l10n_parent = 0) ORDER BY sys_category.sorting', 
     … 
    ] 
] 
+0

ありがとう、今私はこれを持って..しかし、私はアドレスセットにカテゴリを設定できませんでした.. – hrdyy

関連する問題