Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***********************************************
- *
- * Change Setter in DomainObject
- *
- **********************************************/
- /**
- * Sets the Related Property
- *
- * @param Tx_Myext_Domain_Model_RelatedObject $relatedObject
- * @return Tx_Myext_Domain_Model_ParentObject
- */
- public function setRelatedObject( $relatedObject = NULL ) {
- // reset the object if something other then a valid object is passed
- if ( ! $relatedObject instanceof Tx_Myext_Domain_Model_RelatedObject ) {
- $relatedObject = NULL;
- }
- $this->relatedObject = $relatedObject;
- return $this;
- }
- /***********************************************
- *
- * custom Converter
- * To enable this in your extension, add the following to you ext_localconf.php
- * Tx_Extbase_Utility_Extension::registerTypeConverter( 'Tx_Myext_Property_TypeConverter_PersistentObjectConverter' );
- *
- **********************************************/
- /**
- * 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_Myext_Property_TypeConverter_PersistentObjectConverter' );
- */
- class Tx_Myext_Property_TypeConverter_PersistentObjectConverter extends Tx_Extbase_Property_TypeConverter_PersistentObjectConverter {
- /**
- * @var integer
- */
- protected $priority = 2;
- /**
- * We can only convert if the $targetType is either tagged with entity or value object.
- * Empty strings CAN NOT be converted BUT will return NULL
- *
- * @param mixed $source
- * @param string $targetType
- * @return boolean
- */
- public function canConvertFrom($source, $targetType) {
- if ( is_array( $source ) && isset( $source['__identity'] ) && 1 === count( $source ) && 0 >= intval( $source['__identity'] ) ) {
- return TRUE;
- }
- elseif ( '' === $source || -1 === intval( $source ) || 0 === intval( $source ) ) {
- return TRUE;
- } else {
- return parent::canConvertFrom( $source, $targetType );
- }
- }
- /**
- * Convert an object from $source to an entity or a value object.
- * Empty strings CAN NOT be converted BUT will return NULL
- *
- * @param mixed $source
- * @param string $targetType
- * @param array $convertedChildProperties
- * @param Tx_Extbase_Property_PropertyMappingConfigurationInterface $configuration
- * @return object the target type
- */
- public function convertFrom($source, $targetType, array $convertedChildProperties = array(), Tx_Extbase_Property_PropertyMappingConfigurationInterface $configuration = NULL) {
- if ( is_array( $source ) && isset( $source['__identity'] ) && 1 === count( $source ) && 0 >= intval( $source['__identity'] ) ) {
- return 0;
- }
- elseif ( '' === $source || -1 === intval( $source ) || 0 === intval( $source ) ) {
- return 0;
- } else {
- return parent::convertFrom( $source, $targetType, $convertedChildProperties, $configuration );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement