Skip to content

Commit

Permalink
Create transaltion entities using $table->newEntity() instead of new …
Browse files Browse the repository at this point in the history
…Entity().
  • Loading branch information
robertpustulka committed Jul 2, 2015
1 parent 4019f6f commit 314cb7d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/ORM/Behavior/TranslateBehavior.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@


use ArrayObject; use ArrayObject;
use Cake\Collection\Collection; use Cake\Collection\Collection;
use Cake\Datasource\EntityInterface;
use Cake\Event\Event; use Cake\Event\Event;
use Cake\I18n\I18n; use Cake\I18n\I18n;
use Cake\ORM\Behavior; use Cake\ORM\Behavior;
Expand Down Expand Up @@ -247,11 +248,11 @@ public function beforeFind(Event $event, Query $query, $options)
* in the database too. * in the database too.
* *
* @param \Cake\Event\Event $event The beforeSave event that was fired * @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 * @param \ArrayObject $options the options passed to the save method
* @return void * @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(); $locale = $entity->get('_locale') ?: $this->locale();
$newOptions = [$this->_translationTable->alias() => ['validate' => false]]; $newOptions = [$this->_translationTable->alias() => ['validate' => false]];
Expand Down Expand Up @@ -303,10 +304,10 @@ public function beforeSave(Event $event, Entity $entity, ArrayObject $options)
* Unsets the temporary `_i18n` property after the entity has been saved * Unsets the temporary `_i18n` property after the entity has been saved
* *
* @param \Cake\Event\Event $event The beforeSave event that was fired * @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 * @return void
*/ */
public function afterSave(Event $event, Entity $entity) public function afterSave(Event $event, EntityInterface $entity)
{ {
$entity->unsetProperty('_i18n'); $entity->unsetProperty('_i18n');
} }
Expand Down Expand Up @@ -443,10 +444,11 @@ public function groupTranslations($results)


$result = []; $result = [];
foreach ($grouped->combine('field', 'content', 'locale') as $locale => $keys) { foreach ($grouped->combine('field', 'content', 'locale') as $locale => $keys) {
$translation = new Entity($keys + ['locale' => $locale], [ $translation = $this->_table->newEntity($keys + ['locale' => $locale], [
'markNew' => false, 'markNew' => false,
'useSetters' => false, 'useSetters' => false,
'markClean' => true 'markClean' => true,
'validate' => false
]); ]);
$result[$locale] = $translation; $result[$locale] = $translation;
} }
Expand All @@ -464,7 +466,7 @@ public function groupTranslations($results)
* out of the data found in the `_translations` property in the passed * out of the data found in the `_translations` property in the passed
* entity. The result will be put into its `_i18n` property * entity. The result will be put into its `_i18n` property
* *
* @param \Cake\ORM\Entity $entity Entity * @param \Cake\Datasource\EntityInterface $entity Entity
* @return void * @return void
*/ */
protected function _bundleTranslatedFields($entity) protected function _bundleTranslatedFields($entity)
Expand Down

0 comments on commit 314cb7d

Please sign in to comment.