[TYPO3-mvc] DateTiime Fields / configuring the new property manager

Matthias Krappitz matthias at nospam.aemka.de
Thu Oct 27 17:20:55 CEST 2011


Hi,

I just kickstarted (with latest extension_builder) a new extbase extension, 
where one domain object hast datetime fields. I also created the CRUD 
operations for having new, create, update, delete actions and templates in 
extension_builder. When creating a new domain object in the frontend form, 
that has datetime fields, it can never be saved. This is because the domain 
object can never be instansiated from the request arguments of the form, 
which of course contain a string (like "28.10.2010") for each date time 
field and not of objects of  type  DateTime. You always get an error message 
for each date time field in the  frontend form errors and blank fields 
marked with red color. I tried several  stuff and began to read through the 
extbase source code, when I got the idea  to switch to the new property 
manager of typo3 4.6 / extbase 1.4 by setting 
config.tx_extbase.features.rewrittenPropertyMapper = 1. This just brings an 
exception instead of the form errors before:
Uncaught TYPO3 Exception
#1297759968: Exception while property mapping at property path 
"startdatetime":The string"2011-10-22" could not be converted to DateTime 
with format "Y-m-d\TH:i:sP" (More information)

So my first question is, where and how do I configure for my datetime 
properties of my domain object in which format (I want "d.m.Y") they will 
get  written by the user in the frontend form, so that they can get 
converted  into datetime objects correctly?
My second question is, what can I do that the user does not get an 
exception, whenevery he mistypes the date format.
I would also be happy about a solution without the new porperty manager.

Is there any documentation out there? All I can find via google for this 
topic are just dirty workarounds.

This is my property of my domain model:

....

/**
* Start Time
*
* @var DateTime
* @validate NotEmpty
*/
protected $startdatetime;

/**
* Returns the startdatetime
*
* @return DateTime $startdatetime
*/
public function getStartdatetime() {
return $this->startdatetime;
}

/**
* Sets the startdatetime
*
* @param DateTime $startdatetime
* @return void
*/
public function setStartdatetime($startdatetime) {
$this->startdatetime = $startdatetime;
}
...

This is my form field:

<f:form method="post" action="create"  name="newRessource"
object="{newRessource}">
    ...
 <label for="startdatetime">
	<f:translate key="tx_projectplanner_domain_model_ressource.startdatetime" 
/> <span class="required">(required)</span>
</label><br />
	<f:form.textfield property="startdatetime" 
value="{ressource.startdatetime->f:format.date(format: 'd.m.Y')}" /><br />
<label for="enddatetime">
	<f:translate key="tx_projectplanner_domain_model_ressource.enddatetime" /> 
<span class="required">(required)</span>
</label><br />
	<f:form.textfield property="enddatetime" 
value="{ressource.enddatetime->f:format.date(format: 'd.m.Y')}" /><br />
    ...
    <f:form.submit value="Create new" />
</f:form>

These are the relevant parts of my controller:

...

/**
* action new
*
* @param $newRessource
* @dontvalidate $newRessource
* @return void
*/
public function newAction(Tx_Projectplanner_Domain_Model_Ressource
$newRessource = NULL) {
$this->view->assign('newRessource', $newRessource);
}

/**
* action create
*
* @param $newRessource
* @return void
*/
public function createAction(Tx_Projectplanner_Domain_Model_Ressource
$newRessource) {
$this->ressourceRepository->add($newRessource);
$this->flashMessageContainer->add('Your new Ressource was created.');
$this->redirect('list');
}

...

I'm using the latest stable release of TYPO3 4.6.0.

Best Wishes and many thanks in advance.

Matthias 



More information about the TYPO3-project-typo3v4mvc mailing list