[TYPO3-mvc] 1.4 property mapping fails with empty relations?

Tim Schoch | GSTALTIG tim.schoch at gstaltig.ch
Sat Sep 24 16:49:54 CEST 2011


Hello, it's a me, Tim (sorry, too much coke - the brown liquid - has side effects ;] )

I found a way to allow empty values for DateTime and Objects in Editforms and would like to know your opinion on this.
By implementing my own Converters I first check if the value is empty, a zero (extbase objects can't have a 0 as uid)
 or -1 (we use this for some other stuff, you can ignore this) and if not pass it to the default converter. 
Here is how the Object Converter looks. The DateTime converter looks exaktly the same.

/**
 * allows for empty values - in this case it will return NULL
 *
 * To enable this in your extension, add the following to you ext_localconf.php
 *  // Register type converters
 * Tx_Extbase_Utility_Extension::registerTypeConverter( 'Tx_Gstbase_Property_TypeConverter_PersistentObjectConverter' );
 */
class Tx_Gstbase_Property_TypeConverter_PersistentObjectConverter extends Tx_Extbase_Property_TypeConverter_PersistentObjectConverter {

    /**
     * @var integer
     */
    protected $priority = 2;

    public function canConvertFrom($source, $targetType) {
      if ( '' === $source || -1 === intval( $source ) || 0 === intval( $source ) ) {
        return TRUE;
      } else {
        return parent::canConvertFrom( $source, $targetType );
      }
    }

    public function convertFrom($source, $targetType, array $convertedChildProperties = array(), Tx_Extbase_Property_PropertyMappingConfigurationInterface $configuration = NULL) {
      if ( '' === $source || -1 === intval( $source ) || 0 === intval( $source ) ) {
        return NULL;
      } else {
        return parent::convertFrom( $source, $targetType, $convertedChildProperties, $configuration );
      }
    }
}

It still works with @validate NotEmpty as expected.
I am not sure if this has any side effects and probably flow3 handles this differently, but it seems to work =]
Now its up to you and the devs - what do you think of, could this be integrated into extbase? is there a better way of doing it?

Tim

ps: *burp*


More information about the TYPO3-project-typo3v4mvc mailing list