将创建的新类别添加到Typo3 8.7中导入的TT_ADDRESS设置中



我刚刚写了一个新闻任务,以将地址集从JSON文件导入到TT_ADDRESS。效果很好。现在,我遇到了我正在创建新类别的问题。但是我无法将它们分配到地址集。

有人知道该怎么做?

$jsondivision ='JsonCategorieName' 
$address = 'AddressSet'
$categoryParent = 'PartentUID'
public function checkCategory($jsondivision, $address) {
    $extbaseObjectManager = GeneralUtility::makeInstance('TYPO3CMSExtbaseObjectObjectManager');
    $this->addressRepository = $extbaseObjectManager->get('GraphodataGdjson2ttaddressDomainRepositoryGdAddressRepository');
    $this->objectStorage = $extbaseObjectManager->get('TYPO3CMSExtbasePersistenceObjectStorage');
    $this->categoryRepository = $extbaseObjectManager->get('GraphodataGdjson2ttaddressDomainRepositoryGdCategoryRepository');
    $newCategory = $extbaseObjectManager->get('GraphodataGdjson2ttaddressDomainModelGdCategory');
    $newCategory->setTitle($jsondivision);
    $newCategory->setParent($categoryParent);
    $this->categoryRepository->add($newCategory);
    $address->addressRepository($newCategory);
}

您显然已经有一个类别模型(GraphodataGdjson2ttaddressDomainModelGdCategory),因此您需要在地址模型中设置一个关系:

/**
 * @var TYPO3CMSExtbasePersistenceObjectStorage<GraphodataGdjson2ttaddressDomainModelGdCategory>
 * @lazy
 */
protected $categories;

并添加getter,setter和一种将更多类别添加到地址模型的方法:

/**
 * Get categories
 *
 * @return TYPO3CMSExtbasePersistenceObjectStorage<GraphodataGdjson2ttaddressDomainModelGdCategory>
 */
public function getCategories()
{
    return $this->categories;
}
/**
 * Set categories
 *
 * @param  TYPO3CMSExtbasePersistenceObjectStorage $categories
 */
public function setCategories($categories)
{
    $this->categories = $categories;
}
/**
 * Adds a category to this categories.
 *
 * @param GraphodataGdjson2ttaddressDomainModelGdCategory $category
 */
public function addCategory($category)
{
    $this->getCategories()->attach($category);
}

注意力:要使这项工作您的TCA设置必须符合某些要求。看看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',
      …
   ]
]

相关内容

  • 没有找到相关文章

最新更新