Skip to content

Instantly share code, notes, and snippets.

@NamelessCoder
Last active November 25, 2015 14:02
Show Gist options
  • Save NamelessCoder/b1899122d1997ff31a0a to your computer and use it in GitHub Desktop.
Save NamelessCoder/b1899122d1997ff31a0a to your computer and use it in GitHub Desktop.
Example of using annotations to generate TCA configuration based on a Model class.
<?php
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
\FluidTYPO3\Flux\Core::registerAutoFormForModelObjectClassName('FluidTYPO3\Demo\Domain\Model\Mymodel');
\FluidTYPO3\Flux\Core::registerAutoFormForModelObjectClassName('FluidTYPO3\Demo\Domain\Model\Tag');
#
# Table structure for table 'tx_demo_domain_model_mymodel'
#
CREATE TABLE tx_demo_domain_model_mymodel (
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,
cruser_id int(11) DEFAULT '0' NOT NULL,
t3ver_oid int(11) DEFAULT '0' NOT NULL,
t3ver_id int(11) DEFAULT '0' NOT NULL,
t3ver_wsid int(11) DEFAULT '0' NOT NULL,
t3ver_label varchar(30) DEFAULT '' NOT NULL,
t3ver_state tinyint(4) DEFAULT '0' NOT NULL,
t3ver_stage tinyint(4) DEFAULT '0' NOT NULL,
t3ver_count int(11) DEFAULT '0' NOT NULL,
t3ver_tstamp int(11) DEFAULT '0' NOT NULL,
t3_origuid int(11) DEFAULT '0' NOT NULL,
editlock tinyint(4) DEFAULT '0' NOT NULL,
sys_language_uid int(11) DEFAULT '0' NOT NULL,
l10n_parent int(11) DEFAULT '0' NOT NULL,
l10n_diffsource mediumtext,
deleted tinyint(4) DEFAULT '0' NOT NULL,
hidden tinyint(4) DEFAULT '0' NOT NULL,
starttime int(11) DEFAULT '0' NOT NULL,
endtime int(11) DEFAULT '0' NOT NULL,
sorting int(11) DEFAULT '0' NOT NULL,
fe_group varchar(100) DEFAULT '0' NOT NULL,
title tinytext,
summary mediumtext,
confirmed tinyint(1) unsigned DEFAULT '0' NOT NULL,
tags int(11) unsigned DEFAULT '0' NOT NULL,
PRIMARY KEY (uid),
KEY parent (pid)
);
#
# Table structure for table 'tx_demo_domain_model_tag'
#
CREATE TABLE tx_demo_domain_model_tag (
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,
cruser_id int(11) DEFAULT '0' NOT NULL,
t3ver_oid int(11) DEFAULT '0' NOT NULL,
t3ver_id int(11) DEFAULT '0' NOT NULL,
t3ver_wsid int(11) DEFAULT '0' NOT NULL,
t3ver_label varchar(30) DEFAULT '' NOT NULL,
t3ver_state tinyint(4) DEFAULT '0' NOT NULL,
t3ver_stage tinyint(4) DEFAULT '0' NOT NULL,
t3ver_count int(11) DEFAULT '0' NOT NULL,
t3ver_tstamp int(11) DEFAULT '0' NOT NULL,
t3_origuid int(11) DEFAULT '0' NOT NULL,
editlock tinyint(4) DEFAULT '0' NOT NULL,
sys_language_uid int(11) DEFAULT '0' NOT NULL,
l10n_parent int(11) DEFAULT '0' NOT NULL,
l10n_diffsource mediumtext,
deleted tinyint(4) DEFAULT '0' NOT NULL,
hidden tinyint(4) DEFAULT '0' NOT NULL,
starttime int(11) DEFAULT '0' NOT NULL,
endtime int(11) DEFAULT '0' NOT NULL,
sorting int(11) DEFAULT '0' NOT NULL,
fe_group varchar(100) DEFAULT '0' NOT NULL,
name tinytext,
PRIMARY KEY (uid),
KEY parent (pid)
);
#
# Table structure for table 'tx_demo_mymodel_tag_mm'
#
#
CREATE TABLE tx_demo_mymodel_tag_mm (
uid_local int(11) DEFAULT '0' NOT NULL,
uid_foreign int(11) DEFAULT '0' NOT NULL,
tablenames varchar(30) DEFAULT '' NOT NULL,
sorting int(11) DEFAULT '0' NOT NULL,
KEY uid_local (uid_local),
KEY uid_foreign (uid_foreign)
);
<?php
namespace FluidTYPO3\Demo\Domain\Model;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
/**
* Domain Model: Simple entry with tag relations.
*
* The annotations on the class-level doc comment define
* the resulting TCA CONTROLS like hidden, deleted,
* starttime, endtime - and annotations on each property
* define the TCA FIELD variables like field type,
* which Sheet it belongs to and options for the field.
*
* Annotations are either simple values or a Fluid inline
* syntax, e.g. @Annotation parameter(foo: '123', bar: 'abc').
*
* Flux TCA based model
*
* @Flux\Icon icon(path: 'ext_icon.gif')
* @Flux\Control\Hide
* @Flux\Control\Delete
* @Flux\Control\StartTime
* @Flux\Control\EndTime
* @package FluidTYPO3\Demo\Domain\Model
*/
class MyModel extends AbstractEntity {
/**
* @Flux\Label
* @Flux\Form\Field input(size: 100)
* @Flux\Form\Sheet options
* @validate NotEmpty
* @validate Text
* @var string
*/
protected $title;
/**
* @Flux\Form\Field text
* @Flux\Form\Sheet options
* @validate NotEmpty
* @validate Text
* @var string
*/
protected $summary;
/**
* @Flux\Form\Field checkbox
* @Flux\Form\Sheet options
* @var boolean
*/
protected $confirmed = FALSE;
/**
* @Flux\Form\Field relation(size: 5, maxItems: 99, manyToMany: 'tx_demo_mymodel_tag_mm', table: 'tx_fluidshare_domain_model_tag')
* @Flux\Form\Sheet options
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\FluidTYPO3\Demo\Domain\Model\Tag>
*/
protected $tags;
/**
* Constructor
*/
public function __construct() {
$this->tags = new ObjectStorage();
}
/**
* @param string $title
* @return void
*/
public function setTitle($title) {
$this->title = $title;
}
/**
* @return string
*/
public function getTitle() {
return $this->title;
}
/**
* @param string $summary
* @return void
*/
public function setSummary($summary) {
$this->summary = $summary;
}
/**
* @return string
*/
public function getSummary() {
return $this->summary;
}
/**
* @param boolean $confirmed
* @return void
*/
public function setConfirmed($confirmed) {
$this->confirmed = $confirmed;
}
/**
* @return boolean
*/
public function isConfirmed() {
return $this->confirmed;
}
/**
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\FluidTYPO3\Fluidshare\Domain\Model\Tag> $tags
* @return void
*/
public function setTags($tags) {
$this->tags = $tags;
}
/**
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\FluidTYPO3\Fluidshare\Domain\Model\Tag>
*/
public function getTags() {
return $this->tags;
}
}
<?php
namespace FluidTYPO3\Demo\Domain\Model;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
/**
* Domain Model: Tag record
*
* Flux TCA based model
*
* @Flux\Icon icon(path: 'ext_icon.gif')
* @Flux\Control\Hide
* @Flux\Control\Delete
* @package FluidTYPO3\Demo\Domain\Model
*/
class Tag extends AbstractEntity {
/**
* @Flux\Label
* @Flux\Form\Field input
* @Flux\Form\Sheet options
* @validate NotEmpty
* @validate Text
* @var string
*/
protected $name;
/**
* @param string $name
* @return void
*/
public function setName($name) {
$this->name = $name;
}
/**
* @return string
*/
public function getName() {
return $this->name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment