I’ve been trying to extend tt_address with a mm_relation with not much luck so far. Anything I can find online is just for a regular relation, where the ID is saved directly into the same table, not an extra _mm table.
The backend looks fine so far, the way I want it with a selectMultipleSideBySide renderType. It also saves the relations to the database.
Typo3 12.4.16 // TT_Address 8.1.0 // extender 10.1.1
…/extensions/wiwa/Configuration/TCA/Overrides/tt_address.php
<?php
defined('TYPO3') or die();
use TYPO3CMSCoreUtilityExtensionManagementUtility;
(static function () {
ExtensionManagementUtility::addTCAcolumns('tt_address',
[
'product_groups' => [
'exclude' => true,
'label' => 'LLL:EXT:wiwa/Resources/Private/Language/locallang_db.xlf:tx_wiwa_domain_model_product.product_group',
'description' => 'Auswahl der WIWA-Produktkategorie',
'config' => [
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'foreign_table' => 'tx_wiwa_domain_model_productgroup',
'MM' => 'tt_address_productgroup_mm',
'default' => 0,
'size' => 10,
'autoSizeMax' => 30,
'maxitems' => 3,
'multiple' => true,
'fieldControl' => [
'editPopup' => [
'disabled' => false,
],
'addRecord' => [
'disabled' => false,
],
'listModule' => [
'disabled' => true,
],
],
],
],
],
);
ExtensionManagementUtility::addToAllTCAtypes(
'tt_address',
'product_groups',
'',
'before:name'
);
})();
I followed Extend models of tt_address
.../extensions/wiwa/ext_tables.sql
CREATE TABLE tt_address_productgroup_mm (
uid_local int(11) unsigned DEFAULT '0' NOT NULL,
uid_foreign int(11) unsigned DEFAULT '0' NOT NULL,
sorting int(11) unsigned DEFAULT '0' NOT NULL,
sorting_foreign int(11) unsigned DEFAULT '0' NOT NULL,
PRIMARY KEY (uid_local,uid_foreign),
KEY uid_local (uid_local),
KEY uid_foreign (uid_foreign)
);
CREATE TABLE tt_address (
product_groups int(11) unsigned DEFAULT '0',
);
…/extensions/wiwa/Classes/Extending/Domain/Model/Address.php
<<?php
declare(strict_types=1);
namespace ReplicareWiwaExtendingDomainModel;
class Address extends FriendsOfTYPO3TtAddressDomainModelAddress
{
/**
* productGroups
*
* @var TYPO3CMSExtbasePersistenceObjectStorage<ReplicareWiwaDomainModelProductGroup>
*/
protected $productGroups = null;
/**
*
* @return void
*/
public function __construct()
{
$this->productGroups = $this->productGroups ?: new TYPO3CMSExtbasePersistenceObjectStorage();
}
/**
* Adds a productGroup
*
* @param ReplicareWiwaDomainModelProductGroup $productGroup
* @return void
*/
public function addProductGroup(ReplicareWiwaDomainModelProductGroup $productGroup)
{
$this->productGroups->attach($productGroup);
}
/**
* Removes a productGroup
*
* @param ReplicareWiwaDomainModelproductGroup $productGroupToRemove The productGroup to be removed
* @return void
*/
public function removeProductGroup(ReplicareWiwaDomainModelProductGroup $productGroupToRemove)
{
$this->productGroups->detach($productGroupToRemove);
}
/**
* Returns the productGroups
*
* @return TYPO3CMSExtbasePersistenceObjectStorage<ReplicareWiwaDomainModelProductGroup> $productGroups
*/
public function getProductGroups()
{
return $this->productGroups;
}
/**
* Sets the productGroups
*
* @param TYPO3CMSExtbasePersistenceObjectStorage<ReplicareWiwaDomainModelProductGroup> $productGroups
* @return void
*/
public function setProductGroups(TYPO3CMSExtbasePersistenceObjectStorage $productGroups)
{
$this->productGroups = $productGroups;
}
}
Changes in ext_localconf.php are not needed anymore: Changelog extender
and I have configured extender in services.yaml following the instructions in the extender manual.
# Configuration/Services.yaml
services:
_defaults:
autowire: true
autoconfigure: true
public: false
ReplicareWiwaExtendingDomainModelAddress:
tags:
-
name: 'extender.extends'
class: FriendsOfTYPO3TtAddressDomainModelAddress
The problem I’m having now is getting these relations in my fluid templates. The variable location.product_groups just contains the integer number of related objects, instead of the list of objects.
Extbase Variable Dump
How can I get the product_groups that are associated with that location in fluid, with an m:m relation?
Sebastian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5