Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #615 from doctrine/pre_bind_translation

Added preBind translation
  • Loading branch information...
commit d3c78087fe50d84d5fdc1f91ae88d9595ad232fb 2 parents 69cfbdc + b8e3519
@dbu dbu authored
View
2  lib/Doctrine/ODM/PHPCR/Event.php
@@ -40,6 +40,7 @@
const postLoadTranslation = 'postLoadTranslation';
const preCreateTranslation = 'preCreateTranslation';
+ const preUpdateTranslation = 'preUpdateTranslation';
const preRemoveTranslation = 'preRemoveTranslation';
const postRemoveTranslation = 'postRemoveTranslation';
@@ -55,6 +56,7 @@
self::postLoad => self::postLoad,
self::postLoadTranslation => self::postLoadTranslation,
self::preCreateTranslation => self::preCreateTranslation,
+ self::preUpdateTranslation => self::preUpdateTranslation,
self::preRemoveTranslation => self::preRemoveTranslation,
self::postRemoveTranslation => self::postRemoveTranslation,
);
View
8 lib/Doctrine/ODM/PHPCR/UnitOfWork.php
@@ -753,6 +753,14 @@ private function doBindTranslation($document, $locale, ClassMetadata $class)
new LifecycleEventArgs($document, $this->dm),
$invoke
);
+ } elseif ($invoke = $this->eventListenersInvoker->getSubscribedSystems($class, Event::preUpdateTranslation)) {
+ $this->eventListenersInvoker->invoke(
+ $class,
+ Event::preUpdateTranslation,
+ $document,
+ new LifecycleEventArgs($document, $this->dm),
+ $invoke
+ );
}
$this->setLocale($document, $class, $locale);
View
12 tests/Doctrine/Tests/ODM/PHPCR/Functional/EventComputingTest.php
@@ -116,6 +116,7 @@ public function testComputingBetweenEventsWithTranslation()
->addEventListener(
array(
Event::preCreateTranslation,
+ Event::preUpdateTranslation,
Event::postLoadTranslation,
Event::preRemoveTranslation,
Event::postRemoveTranslation,
@@ -142,8 +143,13 @@ public function testComputingBetweenEventsWithTranslation()
// name had been changed pre binding translation
$this->assertEquals('preCreateTranslation', $user->name);
+ $this->dm->bindTranslation($user, 'en');
+ // name has been changed when translation was updated
+ $this->assertEquals('preUpdateTranslation', $user->name);
+
$this->dm->name = 'neuer Name';
$this->dm->bindTranslation($user, 'de');
+
$this->dm->flush();
$this->dm->clear();
@@ -215,6 +221,12 @@ public function preCreateTranslation(LifecycleEventArgs $e)
$document->name = 'preCreateTranslation';
}
+ public function preUpdateTranslation(LifecycleEventArgs $e)
+ {
+ $document = $e->getObject();
+ $document->name = 'preUpdateTranslation';
+ }
+
public function postLoadTranslation(LifecycleEventArgs $e)
{
$document = $e->getObject();
Please sign in to comment.
Something went wrong with that request. Please try again.