[TYPO3-dev] M:M relation objects not initialized
Kevin von Spiczak
k.vonspiczak at q4u.de
Fri Aug 14 09:28:53 CEST 2015
Hi guys,
I'm currently learning extbase development. My extension has a class person and a class role. I have a Person-Role-Relationship class which should be holding all the roles related to a person. When I debug the relation in the frontend the person and role objects are NULL. I think it is some naming convention problem or something like that.
Here are my classes:
<?php
namespace Vendor\People\Domain\Model;
/**
* Class Person
* @scope prototype
* @entity
* @package Vendor\People\Domain\Model
*/
class Person extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
public function __construct() {
$this->initStorageObjects();
}
/**
* @return void
*/
protected function initStorageObjects() {
$this->roles = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
/**
* Roles
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\People\Domain\Model\PersonRelation>
*/
protected $roles = NULL;
/**
* the person's first name
* @var string
* @validate StringLength(minimum = 3, maximum = 50)
*/
protected $firstname;
/**
* the person's last name
* @var string
* @validate StringLength(minimum = 3, maximum = 50)
*/
protected $lastname;
/**
* the person's responsibilities within the company
* @var string
*/
protected $role;
/**
* Photo
* @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
protected $photo;
/**
* detail text about the person
* @var string
* @dontvalidate
*/
protected $description;
/**
* @param string $firstname
* @return void
*/
public function setFirstname($firstname) {
$this->firstname = $firstname;
}
/**
* @return string
*/
public function getFirstname() {
return $this->firstname;
}
/**
* @param string $lastname
* @return void
*/
public function setLastname($lastname) {
$this->lastname = $lastname;
}
/**
* @return string
*/
public function getLastname() {
return $this->lastname;
}
/**
* @param string $role
* @return void
*/
public function setRole($role) {
$this->role = $role;
}
/**
* @return string
*/
public function getRole() {
return $this->role;
}
/**
* @param string $description
* @return void
*/
public function setDescription($description) {
$this->description = $description;
}
/**
* @return string
*/
public function getDescription() {
return $this->description;
}
/**
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> $photo
* @return void
*/
public function setPhoto($photo) {
$this->photo = $photo;
}
/**
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
*/
public function getPhoto() {
return $this->photo;
}
/**
* @return\TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\People\Domain\Model\PersonRelation>
*/
public function getRoles() {
return $this->roles;
}
}
?>
<?php
namespace Vendor\People\Domain\Model;
/**
* Class Role
* @scope prototype
* @entity
* @package Vendor\People\Domain\Model
*/
class Role extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
/**
* the role's title
* @var string
* @validate StringLength(minimum = 3, maximum = 50)
*/
protected $name;
public function __construct() {
}
/**
* @param string $name
* @return void
*/
public function setName($name) {
$this->name = $name;
}
/**
* @return string
*/
public function getName() {
return $this->name;
}
}
?>
<?php
namespace Vendor\People\Domain\Model;
/**
* Class PersonRoleRelation
* @scope prototype
* @entity
* @package Vendor\People\Domain\Model
*/
class PersonRelation extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
/**
* @var \Vendor\People\Domain\Model\Person
*/
protected $person;
/**
* @var \Vendor\People\Domain\Model\Role
*/
protected $role;
/**
* @param \Vendor\People\Domain\Model\Person $person
*/
public function setPerson($person) {
$this->person = $person;
}
/**
* @return \Vendor\People\Domain\Model\Person
*/
public function getPerson() {
return $this->person;
}
/**
* @param \Vendor\People\Domain\Model\Role $role
*/
public function setRole($role) {
$this->role = $role;
}
/**
* @return \Vendor\People\Domain\Model\Role
*/
public function getRole() {
return $this->role;
}
}
<?php
namespace Q4U\People\Domain\Repository;
/**
* Class PersonRepository
*
* @package Q4U\People\Domain\Repository
*/
class PersonRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {}
?>
config.tx_extbase {
persistence {
classes {
Q4U\People\Domain\Model\PersonRelation {
mapping {
tableName = tx_people_domain_model_person_role_rel
columns {
uid_local.mapOnProperty = person
uid_foreign.mapOnProperty = role
}
}
}
}
}
}
TCA person table
<?php
return array(
'ctrl' => array(
'title' => 'Person',
'label' => 'firstname',
'label_alt' => ',lastname',
'label_alt_force' => TRUE,
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'dividers2tabs' => TRUE,
'delete' => 'deleted',
'enablecolumns' => array(
'disabled' => 'hidden',
),
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('people') . 'ext_icon.gif'
),
'types' => array(
'1' => array('showitem' => 'firstname, lastname, role, description, photo, roles')
),
'columns' => array(
'hidden' => array(
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.hidden',
'config' => array(
'type' => 'check'
)
),
'firstname' => array(
'exclude' => 0,
'label' => 'Vorname',
'config' => array(
'type' => 'input',
'size' => 225,
)
),
'lastname' => array(
'exclude' => 0,
'label' => 'Nachname',
'config' => array(
'type' => 'input',
'size' => 225,
)
),
'role' => array(
'exclude' => 0,
'label' => 'Rolle',
'config' => array(
'type' => 'input',
'size' => 225,
)
),
'description' => array(
'exclude' => 0,
'label' => 'Beschreibung',
'config' => array(
'type' => 'text',
)
),
'roles' => array(
'label' => 'Rollen',
'config' => array(
'type' => 'select',
'size' => 10,
'maxitems' => 3,
'foreign_table' => 'tx_people_domain_model_role',
'MM' => 'tx_people_domain_model_person_role_rel',
// 'foreign_table' => 'tx_people_domain_model_person_role_rel',
// 'foreign_field' => 'uid_person',
// 'foreign_label' => 'uid_role',
// 'foreign_selector' => 'uid_role',
// 'foreign_unique' => 'uid_role',
// 'foreign_sortby' => 'sorting',
),
),
'photo' => array(
'exclude' => 0,
'label' => 'Foto',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('photo', array(
'appearance' => array(
'createNewRelationLinkTitle' => 'Bild hinzufügen',
'collapseAll' => FALSE,
),
'maxitems' => 1,
), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'])
),
),
);
?>
TCA relation
<?php
return array(
'ctrl' => array(
'title' => 'Relation Table',
'hideTable' => TRUE,
'sortBy' => 'sorting',
// 'tstamp' => 'tstamp',
// 'crdate' => 'crdate',
// 'dividers2tabs' => TRUE,
// 'delete' => 'deleted',
// 'enablecolumns' => array(
// 'disabled' => 'hidden',
// ),
// 'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('people') . 'ext_icon.gif'
),
'types' => array(
'0' => array('showitem' => 'uid_person, uid_role')
),
'palettes' => array(),
'columns' => array(
// 'hidden' => array(
// 'exclude' => 1,
// 'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.hidden',
// 'config' => array(
// 'type' => 'check'
// )
// ),
'uid_local' => array(
'label' => 'Person',
'config' => array(
'type' => 'select',
'MM' => 'tx_people_domain_model_person_role_rel',
'foreign_table' => 'tx_people_domain_model_person',
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
),
),
'uid_foreign' => array(
'label' => 'Rolle',
'config' => array(
'type' => 'select',
'MM' => 'tx_people_domain_model_person_role_rel',
'foreign_table' => 'tx_people_domain_model_role',
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
),
),
),
);
?>
TCA role
<?php
return array(
'ctrl' => array(
'title' => 'Rolle',
'label' => 'name',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'dividers2tabs' => TRUE,
'delete' => 'deleted',
'enablecolumns' => array(
'disabled' => 'hidden',
),
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('people') . 'ext_icon.gif'
),
'types' => array(
'1' => array('showitem' => 'name')
),
'columns' => array(
'hidden' => array(
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.hidden',
'config' => array(
'type' => 'check'
)
),
'name' => array(
'label' => 'Bezeichnung',
'config' => array(
'type' => 'input',
'size' => 225,
)
),
// 'people' => array(
// 'label' => 'Personen',
// 'config' => array(
// 'type' => 'inline',
// 'foreign_table' => 'tx_people_domain_model_person_role_rel',
// 'foreign_field' => 'uid_role',
// 'foreign_label' => 'uid_person'
// ) ,
// )
),
);
?>
thanks in advance
kevin
More information about the TYPO3-dev
mailing list