Related
I can't get the ADD NEW ITEM Button to that opens the modal with Inline create
But, strangely, in the primary class, I see the items that are related, inside a box, showed as buttons with an [x] to delete them.
Primary Class (FairCrudController.php)
namespace App\Http\Controllers\Admin;
use App\Http\Requests\FairRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
/**
* Class FairCrudController
* #package App\Http\Controllers\Admin
* #property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class FairCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\InlineCreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\FetchOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\BulkDeleteOperation;
use \Backpack\EditableColumns\Http\Controllers\Operations\MinorUpdateOperation;
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* #return void
*/
public function setup()
{
CRUD::setModel(\App\Models\Fair::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/fair');
CRUD::setEntityNameStrings('feria', 'Ferias');
}
/**
* Define what happens when the List operation is loaded.
*
* #see https://backpackforlaravel.com/docs/crud-operation-list-entries
* #return void
*/
protected function setupListOperation()
{
CRUD::addColumn([
'name' => 'name',
'type' => 'editable_text',
'label' => 'Nombre',
'underlined' => true,
'min_width' => '120px',
'select_on_click' => false,
'save_on_focusout' => false,
'auto_update_row' => true,
]);
CRUD::column('hero_image')->label('Imagen')->type('image');
CRUD::column('start_at')->label('Empieza');
CRUD::column('end_at')->label('Termina');
CRUD::column('date_limit')->label('Límite');
CRUD::addColumn([
'name' => 'status',
'label' => 'Activada',
'type' => 'editable_switch',
'color' => 'success',
'onLabel' => '✓',
'offLabel' => '✕',
]);
$this->crud->enableBulkActions();
$this->crud->setDefaultPageLength(100);
$this->crud->orderBy('start_at', 'DESC');
}
/**
* Define what happens when the Create operation is loaded.
*
* #see https://backpackforlaravel.com/docs/crud-operation-create
* #return void
*/
protected function setupCreateOperation()
{
CRUD::setValidation(FairRequest::class);
CRUD::field('name')->label('Nombre');
CRUD::field('website')->label('Sitio Web');
CRUD::field('invoice_prefix')->label('Prefijo de Facturas');
CRUD::field('address')->label('Dirección');
CRUD::field('city')->label('Ciudad');
CRUD::field('state')->label('Estado/Provincia');
CRUD::field('zip_code')->label('Código Postal');
CRUD::field('country')->label('Pais');
CRUD::field('contactperson')->type('relationship')->label('Personas de Contacto');
CRUD::field('contact_persons_copy')->label('Poner en copia de los emails (separados por punto y coma)');
CRUD::field('start_at')->label('Comienza');
CRUD::field('end_at')->label('Termina');
CRUD::field('date_limit')->label('Límite');
$this->crud->addField([
'label' => "Imagen de Presentación",
'name' => "hero_image",
'type' => 'image',
'crop' => true,
'aspect_ratio' => 0,
]);
$this->crud->addField([
'type' => "relationship",
'name' => 'images',
'label' => 'Imágenes',
'ajax' => true,
'inline_create' => true,
]);
$this->crud->addField([
'type' => "relationship",
'name' => 'dossiers',
'ajax' => true,
'inline_create' => [ 'entity' => 'dossier' ],
'data_source' => backpack_url('fair/fetch/dossier')
]);
$this->crud->addField([
'type' => "relationship",
'name' => 'newsletters',
'ajax' => true,
'inline_create' => true,
]);
CRUD::field('stands')->type('relationship')->label('Stands');
CRUD::field('status')->label('Activa')->default(1);
}
/**
* Define what happens when the Update operation is loaded.
*
* #see https://backpackforlaravel.com/docs/crud-operation-update
* #return void
*/
protected function setupUpdateOperation()
{
$this->setupCreateOperation();
}
/**
* Define what happens when the View operation is loaded.
*
* #see https://backpackforlaravel.com/docs/5.x/crud-operation-show
* #return void
*/
protected function setupShowOperation()
{
CRUD::column('name')->label('Nombre');
CRUD::column('website')->label('Sitio Web');
CRUD::column('invoice_prefix')->label('Prefijo de Facturas');
CRUD::column('address')->label('Dirección');
CRUD::column('city')->label('Ciudad');
CRUD::column('state')->label('Estado/Provincia');
CRUD::column('zip_code')->label('Código Postal');
CRUD::column('country')->label('Pais');
CRUD::column('contact_persons_copy')->label('Poner en copia de los emails (separados por punto y coma)');
CRUD::column('start_at')->label('Comienza');
CRUD::column('end_at')->label('Termina');
CRUD::column('date_limit')->label('Límite');
CRUD::column('hero_image')->label('Imagen')->type('image');
CRUD::column('status')->label('Activada')->type('check');
}
public function setupInlineCreateOperation() {
$this->setupCreateOperation();
}
protected function fetchDossier()
{
return $this->fetch(\App\Models\Dossier::class);
}
}
Secondary Class (DossierCrudController.php)
namespace App\Http\Controllers\Admin;
use App\Http\Requests\DossierRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
/**
* Class DossierCrudController
* #package App\Http\Controllers\Admin
* #property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class DossierCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\InlineCreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\BulkDeleteOperation;
use \Backpack\EditableColumns\Http\Controllers\Operations\MinorUpdateOperation;
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* #return void
*/
public function setup()
{
CRUD::setModel(\App\Models\Dossier::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/dossier');
CRUD::setEntityNameStrings('dossier de la feria', 'dossiers de la feria');
}
/**
* Define what happens when the List operation is loaded.
*
* #see https://backpackforlaravel.com/docs/crud-operation-list-entries
* #return void
*/
protected function setupListOperation()
{
CRUD::addColumn([
'name' => 'fair_id',
'label' => 'Feria',
'type' => 'editable_select',
'options' => \App\Models\Fair::all()->pluck('name', 'id')->toArray(),
'underlined' => true,
'save_on_focusout' => true,
'save_on_change' => true,
'auto_update_row' => true,
]);
CRUD::addColumn([
'name' => 'name',
'type' => 'editable_text',
'label' => 'Nombre',
'underlined' => true,
'min_width' => '120px',
'select_on_click' => false,
'save_on_focusout' => false,
'auto_update_row' => true,
]);
CRUD::addColumn([
'name' => 'status',
'label' => 'Activado',
'type' => 'editable_switch',
'color' => 'success',
'onLabel' => '✓',
'offLabel' => '✕',
]);
$this->crud->enableBulkActions();
$this->crud->setDefaultPageLength(100);
$this->crud->orderBy('fair_id', 'ASC');
}
/**
* Define what happens when the Create operation is loaded.
*
* #see https://backpackforlaravel.com/docs/crud-operation-create
* #return void
*/
protected function setupCreateOperation()
{
CRUD::setValidation(DossierRequest::class);
CRUD::field('fair')->type('select')->label('Feria');
CRUD::field('name')->label('Nombre');
CRUD::field('status')->label('Activo')->default(1);
$this->crud->addField([
'label' => "Archivo (Tamaño: 16MB máx.)",
'name' => "file",
'upload' => true,
'type' => 'upload',
]);
}
/**
* Define what happens when the Update operation is loaded.
*
* #see https://backpackforlaravel.com/docs/crud-operation-update
* #return void
*/
protected function setupUpdateOperation()
{
$this->setupCreateOperation();
}
protected function setupShowOperation()
{
CRUD::column('fair')->label('Feria');
CRUD::column('name')->label('Nombre');
CRUD::column('file')->label('Archivo')->type('file');
CRUD::column('status')->label('Activado')->type('check');
}
public function setupInlineCreateOperation() {
$this->setupCreateOperation();
}
}
/routes/backpack/custom.php
....
Route::get('fair/fetch/dossier', [DossierCrudController::class, "fetchDossier"]);
....
Fair.php Model
use App\Models\Dossier;
...
public function dossiers()
{
return $this->hasMany(Dossier::class);
}
....
Dossier.php Model
use App\Models\Fair;
...
public function fair()
{
return $this->belongsTo(Fair::class);
}
....
I have a typo3 extension which allows to create Content Elements within the extension - in typo3 v9 it works fine but on typo3 v10 it doesn’t, when I debug in the template i got this result:
contentElements => protected TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorageprototypeobject (empty)
The Content Element is created and in the backend also correctly visible within the Dataset
I also tried to have a look at tx_news which implements a simular behaiver but I doesn’t have a clue, for me it seems that I done right but yeah … , following some code snippets I used, may you have an Idea:
In the setup.typoscript:
lib.contenttabs_fecontenttabs.contentElementRendering = RECORDS
lib.contenttabs_fecontenttabs.contentElementRendering {
tables = tt_content
source.current = 1
dontCheckPid = 1
}
In the Model (I tried to use the sam as news):
/**
* Get content elements
*
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
*/
public function getContentElements()
{
return $this->contentElements;
}
/**
* Set content element list
*
* #param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $contentElements content elements
*/
public function setContentElements($contentElements)
{
$this->contentElements = $contentElements;
}
/**
* Adds a content element to the record
*
* #param \Moc\Contenttabs\Domain\Model\TtContent $contentElement
*/
public function addContentElement(\Moc\Contenttabs\Domain\Model\TtContent $contentElement)
{
if ($this->getContentElements() === null) {
$this->contentElements = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
$this->contentElements->attach($contentElement);
}
/**
* Get id list of content elements
*
* #return string
*/
public function getContentElementIdList()
{
return $this->getIdOfContentElements();
}
/**
* Get translated id list of content elements
*
* #return string
*/
public function getTranslatedContentElementIdList()
{
return $this->getIdOfContentElements(false);
}
/**
* Collect id list
*
* #param bool $original
* #return string
*/
protected function getIdOfContentElements($original = true)
{
$idList = [];
$contentElements = $this->getContentElements();
if ($contentElements) {
foreach ($this->getContentElements() as $contentElement) {
if ($contentElement->getColPos() >= 0) {
$idList[] = $original ? $contentElement->getUid() : $contentElement->_getProperty('_localizedUid');
}
}
}
return implode(',', $idList);
}
In the Template:
<f:cObject typoscriptObjectPath="lib.contenttabs_fecontenttabs.contentElementRendering">
{tab.contentElementIdList}
</f:cObject>
Some of the TCA Code (which seems to works fine):
'content_elements' => [
'exclude' => 1,
'l10n_mode' => 'mergeIfNotBlank',
'label' => 'Content Elements',
'config' => [
'type' => 'inline',
'allowed' => 'tt_content',
'foreign_table' => 'tt_content',
'foreign_sortby' => 'sorting',
'foreign_field' => 'tx_tabs_content_elements',
'minitems' => 0,
'maxitems' => 99,
'overrideChildTca' => [
'columns' => [
'colPos' => [
'config' => [
'default' => 99
]
],
'CType' => [
'config' => [
'default' => 'textmedia'
]
]
]
],
'appearance' => [
'collapseAll' => 1,
'expandSingle' => 1,
'levelLinksPosition' => 'bottom',
'useSortable' => 1,
'showPossibleLocalizationRecords' => 1,
'showRemovedLocalizationRecords' => 1,
'showAllLocalizationLink' => 1,
'showSynchronizationLink' => 1,
'enabledControls' => [
'info' => false,
]
]
]
],
Thanks in advance!
I have in my TYPO3 an object called Location where I store informations about a city, including a pdf file.
In the backend I can upload a pdf without problem, but when I try to display it, I get NULL. The value of 'pdf' in the database is not NULL, but when I debug <f:debug>{location}</f:debug> I get pdf => NULL !!!
Here is my TCA/LOCATION :
$GLOBALS['TCA']['tx_locations_domain_model_location'] = array(
'ctrl' => $GLOBALS['TCA']['tx_locations_domain_model_location']['ctrl'],
....
'columns' => array(
...
'pdf' => array(
'exclude' => 1,
'label' => 'LLL:EXT:locations/Resources/Private/Language/locallang_db.xlf:tx_locations_domain_model_location.pdf',
'config' => array (
'type' => 'group',
'internal_type' => 'file',
'allowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
'max_size' => $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'],
'uploadfolder' => 'uploads/pics',
'show_thumbs' => 1,
'size' => 1,
'minitems' => 0,
'maxitems' => 1
)
),
...
The Getter and Setter should be fine in typo3conf/ext/locations/Classes/Domain/Model/Location.php :
/**
* Returns the pdf
*
* #return \TYPO3\CMS\Extbase\Domain\Model\FileReference $pdf
*/
public function getPdf() {
return $this->pdf;
}
/**
* Sets the pdf
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $pdf
* #return void
*/
public function setPdf(\TYPO3\CMS\Extbase\Domain\Model\FileReference $pdf) {
$this->pdf = $pdf;
}
You can see the debug gives pdf=> NULL from below:
My pdf column is not empty :
Did I miss something ??
UPDATE :
After the answer of Pavin, I can see something in PDF, but I can't get the name of the file in href tag , maybe I need to change something after the new answer.
I can see things changed in the Database, the pdf field now is boolean. that's why maybe I get pdf0.originalResource NULL, but in the backend I can upload files and see then after save and refresh !!!:
<p><f:translate key="tx_locations_domain_model_location.downloadpdf" /> <a class="download" target="_blank" title="Initiates file download" href="{location.pdf.originalResource.publicUrl}"><f:translate key="tx_locations_domain_model_location.here" />..</a></p>
UPDATE 2
my new Model/Location.php
/**
* pdf
*
* #var string
*/
protected $pdf = NULL;
...
/**
* Returns the pdf
*
* #return string $pdf
*/
public function getPdf() {
return $this->pdf;
}
/**
* Sets the pdf
*
* #param string $pdf
* #return void
*/
public function setPdf($pdf) {
$this->pdf = $pdf;
}
My TCA/Location.php
'pdf' => array(
'exclude' => 1,
'label' => 'LLL:EXT:locations/Resources/Private/Language/locallang_db.xlf:tx_locations_domain_model_location.pdf',
'config' => array (
'type' => 'group',
'internal_type' => 'file',
'allowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
'max_size' => $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'],
'uploadfolder' => 'uploads/pics',
'show_thumbs' => 1,
'size' => 1,
'minitems' => 0,
'maxitems' => 1
)
),
You can use below TCA configuration for Doc types records. also add Getter and Setter methods in modle file.
'pdf' => array(
'exclude' => 0,
'label' => 'LLL:EXT:ext_key/Resources/Private/Language/locallang_db.xlf:label_key.files',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'pdf',
array('minitems' => 0,'maxitems' => 10),
'pdf,doc,docx'
),
),
For Model.php files.
/**
* pdf
*
*#var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
*/
protected $pdf;
initStorageObjects Methods :
protected function initStorageObjects() {
$this->files = new ObjectStorage();
parent::initializeObject();
}
Getter And Setter Method:
/**
* Returns the pdf
*
* #return ObjectStorage
*/
public function getPdf() {
return $this->pdf;
}
/**
* Sets the pdf
*
*/
public function setPdf($pdf) {
$this->pdf = $pdf;
}
See attached image for pdf name. Please add pdf title. For Pdf title you can use {location.pdf.title}
You use group as the type for saving the file in the TCA, so the property $pdf in your model must be string and not \TYPO3\CMS\Extbase\Domain\Model\FileReference
FileReference only work for FAL (File Abstraction Layer)
I'm currently learning extbase and fluid. I read along this SO post TYPO3 extbase & IRRE: add existing records with 'foreign_selector' to set up a relation in my extension. I got roles and people. N people can have M roles. Now everything works fine in the backend. While in the frontend I don't see the objects when I use f:debug. My problem is that the relation isn't correctly resolved by extbase (I think?).
This is my relation class:
<?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;
}
}
This is entity person:
<?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;
}
}
?>
and this is role:
<?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;
}
}
?>
ext_tables.sql:
CREATE TABLE tx_people_domain_model_person (
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
tstamp int(11) DEFAULT '0' NOT NULL,
crdate int(11) DEFAULT '0' NOT NULL,
deleted tinyint(4) DEFAULT '0' NOT NULL,
hidden tinyint(4) DEFAULT '0' NOT NULL,
firstname varchar(225) DEFAULT '' NOT NULL,
lastname varchar(225) DEFAULT '' NOT NULL,
role varchar(225) DEFAULT '' NOT NULL,
roles int(11) unsigned DEFAULT '0' NOT NULL,
description mediumtext DEFAULT '' NOT NULL,
photo mediumblob NOT NULL,
PRIMARY KEY (uid),
KEY parent (pid)
) ENGINE=InnoDB;
CREATE TABLE tx_people_domain_model_role (
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
tstamp int(11) DEFAULT '0' NOT NULL,
crdate int(11) DEFAULT '0' NOT NULL,
deleted tinyint(4) DEFAULT '0' NOT NULL,
hidden tinyint(4) DEFAULT '0' NOT NULL,
name varchar(225) DEFAULT '' NOT NULL,
PRIMARY KEY (uid)
KEY parent (pid)
) ENGINE=InnoDB;
CREATE TABLE tx_people_domain_model_person_role_rel (
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,
KEY uid_local (uid_local),
KEY uid_foreign (uid_foreign)
) ENGINE=InnoDB;
TCA config:
tx_people_domain_model_person.php:
<?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'])
),
),
);
?>
tx_domain_model_person_role_rel.php:
<?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,
),
),
),
);
?>
tx_domain_model_role.php:
<?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'
// ) ,
// )
),
);
?>
ext_typoscript_setup.txt:
config.tx_extbase {
persistence {
classes {
Domain\People\Domain\Model\PersonRelation {
mapping {
tableName = tx_people_domain_model_person_role_rel
columns {
uid_local.mapOnProperty = person
uid_foreign.mapOnProperty = role
}
}
}
}
}
}
update debug output:
Domain\People\Domain\Model\Personprototypepersistent entity (uid=1, pid=18)
roles => TYPO3\CMS\Extbase\Persistence\ObjectStorageprototypeobject (3 items)
000000001bb500c600007fe33c9a2f36 => Domain\People\Domain\Model\PersonRelationprototypepersistent entity (uid=1, pid=20)
person => NULL
role => NULL
uid => 1 (integer)
_localizedUid => 1 (integer)modified
_languageUid => NULL
_versionedUid => 1 (integer)modified
pid => 20 (integer)
000000001bb5002400007fe33c9a2f36 => Domain\People\Domain\Model\PersonRelationprototypepersistent entity (uid=2, pid=20)
person => NULL
role => NULL
uid => 2 (integer)
_localizedUid => 2 (integer)modified
_languageUid => NULL
_versionedUid => 2 (integer)modified
pid => 20 (integer)
000000001bb500d100007fe33c9a2f36 => Domain\People\Domain\Model\PersonRelationprototypepersistent entity (uid=3, pid=20)
person => NULL
role => NULL
uid => 3 (integer)
_localizedUid => 3 (integer)modified
_languageUid => NULL
_versionedUid => 3 (integer)modified
pid => 20 (integer)
firstname => 'Max' (3 chars)
lastname => 'Mustermann' (10 chars)
role => 'Rolle' (5 chars)
photo => TYPO3\CMS\Extbase\Domain\Model\FileReferenceprototypepersistent entity (uid=25, pid=18)
description => 'Beschreibungstext' (17 chars)
uid => 1 (integer)
_localizedUid => 1 (integer)modified
_languageUid => NULL
_versionedUid => 1 (integer)modified
pid => 18 (integer)
So the problem is that I need to access those related objects (or the roles of a person) in the frontend.
edit: I think I'm a bit confused about the type of relation I need at all right now. 1 Person can have n roles. I don't want to relate people to roles later on anyways. I just want to create roles and later on assign roles to different people. So it would be a 1:n relation I guess. If that makes it any easier.
The solution was to add the following methods and variables in my Person class:
/**
* roles
*
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Domain\People\Domain\Model\Role>
*/
protected $roles = NULL;
/**
* __construct
*/
public function __construct() {
//Do not remove the next line: It would break the functionality
$this->initStorageObjects();
}
/**
* Initializes all ObjectStorage properties
* Do not modify this method!
* It will be rewritten on each save in the extension builder
* You may modify the constructor of this class instead
*
* #return void
*/
protected function initStorageObjects() {
$this->roles = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
/**
* Adds a Role
*
* #param \Domain\People\Domain\Model\Role $role
* #return void
*/
public function addRole(\Domain\People\Domain\Model\Role $role) {
$this->roles->attach($role);
}
/**
* Removes a Role
*
* #param \Domain\People\Domain\Model\Role $roleToRemove The Role to be removed
* #return void
*/
public function removeRole(\Domain\People\Domain\Model\Role $roleToRemove) {
$this->roles->detach($roleToRemove);
}
/**
* Returns the roles
*
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Domain\People\Domain\Model\Role> $roles
*/
public function getRoles() {
return $this->roles;
}
/**
* Sets the roles
*
* #param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Domain\People\Domain\Model\Role> $roles
* #return void
*/
public function setRoles(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $roles) {
$this->roles = $roles;
}
I create a extbase Plugin in TYPO3 6.2. In one table i have a field "fuid" where i want to store the fe_users uid, to know which user can edit this record.
I set the "fuid" in createAction:
$newLocation->setFuID((int) $GLOBALS['TSFE']->fe_user->user['uid']);
This work. In the Database is the right UID.
But in the editAction:
$location->getFuID()
returns null
Why?
TCA:
fu_i_d' => array(
'exclude' => 1,
'label' => 'LLL:EXT:pitss24/Resources/Private/Language/locallang_db.xlf:tx_pitss24_domain_model_location.fu_i_d',
'config' => array(
'type' => 'select',
'items' => array (
array('',0),
),
'foreign_table' => 'fe_users',
'foreign_class' => '\TYPO3\CMS\Extbase\Domain\Model\FrontendUser',
'minitems' => 0,
'maxitems' => 1,
'size' => 10,
'appearance' => array(
'collapseAll' => 0,
'levelLinksPosition' => 'top',
'showSynchronizationLink' => 1,
'showPossibleLocalizationRecords' => 1,
'showAllLocalizationLink' => 1
),
),
),
In the Backend / TYPO3 is all OK!
In Model File.
/**
* feuseruid
*
* #var \TYPO3\CMS\Extbase\Domain\Model\FrontendUser
*/
protected $feuseruid;
// GET and SET Methods
/**
* Returns the feuseruid
*
* #return \TYPO3\CMS\Extbase\Domain\Model\FrontendUser feuseruid
*/
public function getFeuseruid() {
return $this->feuseruid;
}
/*
* Sets the feuseruid
*
* #param string $feuseruid
* #return \TYPO3\CMS\Extbase\Domain\Model\FrontendUser feuseruid
*/
public function setFeuseruid(\TYPO3\CMS\Extbase\Domain\Model\FrontendUser $feuseruid) {
$this->feuseruid = $feuseruid;
}
In TCA File
'feuseruid' => array(
'exclude' => 1,
'label' => 'Feuser Id',
'config' => array(
'type' => 'inline',
'foreign_table' => 'fe_users',
'minitems' => 0,
'maxitems' => 1,
'appearance' => array(
'collapseAll' => 0,
'levelLinksPosition' => 'top',
'showSynchronizationLink' => 1,
'showPossibleLocalizationRecords' => 1,
'showAllLocalizationLink' => 1
),
),
),
In Sql.php
feuseruid int(11) unsigned DEFAULT '0' NOT NULL,
In Controller
/**
* User Repository
*
* #var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
* #inject
*/
protected $userRepository;
$userObject = $this->userRepository->findByUid($GLOBALS['TSFE']->fe_user->user['uid']);
$orders->setFeuseruid($userObject);
$this->yourRepository->add($orders);
i found the Error! The extensionBuilder writes wrong Data in the Model:
the right values are:
Model:
/*
*
* #var TYPO3\CMS\Extbase\Domain\Model\FrontendUser
*/
protected $fuID = NULL;
...
...
...
/**
* Returns the fuID
*
* #return TYPO3\CMS\Extbase\Domain\Model\FrontendUser fuID
*/
public function getFuID() {
return $this->fuID;
}
/*
* Sets the fuID
*
* #param string $fuID
* #return TYPO3\CMS\Extbase\Domain\Model\FrontendUser fuID
*/
public function setFuID(TYPO3\CMS\Extbase\Domain\Model\FrontendUser $fuID) {
$this->fuID = $fuID;
}
Controller:
/**
* User Repository
*
* #var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
* #inject
*/
protected $userRepository;
/**
* Den aktuell angemeldeten User auslesen
*
* #return \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
*/
public function getCurrentUser() {
if ($this->currentUser == NULL && $GLOBALS['TSFE']->fe_user->user['uid'] > 0) {
$this->currentUser = $this->userRepository->findByUid($GLOBALS['TSFE']->fe_user->user['uid']);
}
return $this->currentUser;
}
Hard to say without the appropriate view of your model. It's very likely, that you have a mismatch between your model and your TCA: On the one hand you are using an integer (setFuID()), on the other hand you have an object (foreign_table/foreign_class). Maybe it's working after you have adjusted this to be the same.