Last active
September 22, 2022 16:19
-
-
Save bwaidelich/9617211 to your computer and use it in GitHub Desktop.
A simple example showing how doctrine behaviors (in this chase soft-deleteable) can be used within TYPO3 Flow.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
... | |
"require": { | |
"typo3/flow": "2.0.*", | |
"gedmo/doctrine-extensions": "2.3.*" | |
}, | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TYPO3: | |
Flow: | |
# disable reflection for non psr-0 compliant 3rd party packages | |
object: | |
excludeClasses: | |
'gedmo.doctrineextensions' : ['Gedmo\\.*'] | |
# register soft deletable filter & event listeners | |
persistence: | |
doctrine: | |
filters: | |
soft-deletable: 'Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter' | |
eventListeners: | |
- | |
events: ['onFlush', 'loadClassMetadata'] | |
listener: 'Gedmo\SoftDeleteable\SoftDeleteableListener' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Your\Package\Domain\Model; | |
use TYPO3\Flow\Annotations as Flow; | |
use Doctrine\ORM\Mapping as ORM; | |
use Gedmo\Mapping\Annotation as Gedmo; | |
/** | |
* Trait for soft-deletable entities. | |
* Usage: | |
* | |
* * Add @Gedmo\SoftDeleteable(fieldName="deletedAt") annotation to your entity | |
* * add "use SoftDeletableTrait;" to your entity | |
*/ | |
trait SoftDeletableTrait { | |
/** | |
* DateTime when this entity was deleted (used for "Soft-Delete behaviour") | |
* | |
* @var \DateTime | |
* @ORM\Column(nullable=true) | |
*/ | |
protected $deletedAt; | |
/** | |
* @return \DateTime | |
*/ | |
public function getDeletedAt() { | |
return $this->deletedAt; | |
} | |
/** | |
* @param \DateTime $deletedAt | |
* @return void | |
*/ | |
public function setDeletedAt(\DateTime $deletedAt) { | |
$this->deletedAt = $deletedAt; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Your\Package\Domain\Model; | |
use TYPO3\Flow\Annotations as Flow; | |
use Doctrine\ORM\Mapping as ORM; | |
use Gedmo\Mapping\Annotation as Gedmo; | |
/** | |
* Some Entity | |
* | |
* @Flow\Entity | |
* @Gedmo\SoftDeleteable(fieldName="deletedAt") | |
*/ | |
class SomeEntity { | |
use SoftDeletableTrait; | |
/** ..other properties ..*/ | |
} | |
?> |
Anyone knows how to mix softdeleteable
and blameable
in proper way? I want to update deleted_by
field when "removing" entity.
As I stumbled upon it:
Please notice the different spellings of "deleteable" and "deletable" (with/without additional "e") in the example. ;-)
Adding @Gedmo\SoftDeleteable(fieldName="deletedAt") annotation to your entity
to every entity is quite a hustle 😅
While using 'deletedAt' column name for soft deletion, one can use the SoftDeleteableEntity
which doesn't require annotations.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Worked like a charm! Thanks for sharing.
Unfortunately, my Flow version is yet outdate (shame on me), so I've done some extra patch on EntityManagerFactory (i.e.g: also added the buildEventManager).