Skip to content
Permalink
Browse files

Create transaltion entities using $table->newEntity() instead of new …

…Entity().
  • Loading branch information...
robertpustulka committed Jul 2, 2015
1 parent 4019f6f commit 314cb7d1d5c72cecfa845875b0adcb687bdc59ad
Showing with 9 additions and 7 deletions.
  1. +9 −7 src/ORM/Behavior/TranslateBehavior.php
@@ -16,6 +16,7 @@
use ArrayObject;
use Cake\Collection\Collection;
use Cake\Datasource\EntityInterface;
use Cake\Event\Event;
use Cake\I18n\I18n;
use Cake\ORM\Behavior;
@@ -247,11 +248,11 @@ public function beforeFind(Event $event, Query $query, $options)
* in the database too.
*
* @param \Cake\Event\Event $event The beforeSave event that was fired
* @param \Cake\ORM\Entity $entity The entity that is going to be saved
* @param \Cake\Datasource\EntityInterface $entity The entity that is going to be saved
* @param \ArrayObject $options the options passed to the save method
* @return void
*/
public function beforeSave(Event $event, Entity $entity, ArrayObject $options)
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options)
{
$locale = $entity->get('_locale') ?: $this->locale();
$newOptions = [$this->_translationTable->alias() => ['validate' => false]];
@@ -303,10 +304,10 @@ public function beforeSave(Event $event, Entity $entity, ArrayObject $options)
* Unsets the temporary `_i18n` property after the entity has been saved
*
* @param \Cake\Event\Event $event The beforeSave event that was fired
* @param \Cake\ORM\Entity $entity The entity that is going to be saved
* @param \Cake\Datasource\EntityInterface $entity The entity that is going to be saved
* @return void
*/
public function afterSave(Event $event, Entity $entity)
public function afterSave(Event $event, EntityInterface $entity)
{
$entity->unsetProperty('_i18n');
}
@@ -443,10 +444,11 @@ public function groupTranslations($results)
$result = [];
foreach ($grouped->combine('field', 'content', 'locale') as $locale => $keys) {
$translation = new Entity($keys + ['locale' => $locale], [
$translation = $this->_table->newEntity($keys + ['locale' => $locale], [
'markNew' => false,
'useSetters' => false,
'markClean' => true
'markClean' => true,
'validate' => false
]);
$result[$locale] = $translation;
}
@@ -464,7 +466,7 @@ public function groupTranslations($results)
* out of the data found in the `_translations` property in the passed
* entity. The result will be put into its `_i18n` property
*
* @param \Cake\ORM\Entity $entity Entity
* @param \Cake\Datasource\EntityInterface $entity Entity
* @return void
*/
protected function _bundleTranslatedFields($entity)

0 comments on commit 314cb7d

Please sign in to comment.
You can’t perform that action at this time.