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

Matthias Krappitz matthias at nospam.aemka.de
Thu Oct 27 19:41:07 CEST 2011


> if you don't want to use JS for any reason you may try to detect the 
> format in the initialize*Action. Not sure if this works and it does not 
> seem really clean - but i guess it should work. Maybe someone else has 
> solved this issue?

I couldn't resist to figure out a quite clean solution for this in the 
initialize*Action:

            /**
	 * action initializeCreate
	 * @todo: do the same for update!
	 *
	 * @return void
	 */
	public function initializeCreateAction() {
		$requestArguments = $this->request->getArguments();
		if (!strtotime($requestArguments['newRessource']['startdatetime'])
			|| !strtotime($requestArguments['newRessource']['enddatetime'])) {
			$requestArguments['newRessource']['startdatetime'] = '01.01.1970';
			$requestArguments['newRessource']['enddatetime'] = '01.01.1970';
			$this->flashMessageContainer->add('Please enter all dates in format 
"d.m.Y".');
			$this->forward('new', NULL, NULL, $requestArguments);
		}

		// this configures the parsing
		$this->arguments['newRessource']
  			->getPropertyMappingConfiguration()
			->forProperty('startdatetime')
			->setTypeConverterOption('Tx_Extbase_Property_TypeConverter_DateTimeConverter', 
Tx_Extbase_Property_TypeConverter_DateTimeConverter::CONFIGURATION_DATE_FORMAT, 
'd.m.Y');
		$this->arguments['newRessource']
  			->getPropertyMappingConfiguration()
			->forProperty('enddatetime')
			->setTypeConverterOption('Tx_Extbase_Property_TypeConverter_DateTimeConverter', 
Tx_Extbase_Property_TypeConverter_DateTimeConverter::CONFIGURATION_DATE_FORMAT, 
'd.m.Y');
	}

	/**
	 * 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');
	}

Anyway. I'm not convinced by writing so much code and researching such a 
long time in the frameworks source code for such basic groundwork. A good 
framework should be able to deal with all this in a smarter way. Maybe a 
special form viewhelper for dates with a dateformat attribute would be a 
much better approach. Another bummer is, that extbase can't handle empty 
values for the datetime values, why I had to set it to 01.01.1970 in the 
code above. At least in my case the fields need to be filled in, so I don't 
have to deal with this.

Matthias 



More information about the TYPO3-project-typo3v4mvc mailing list