Skip to content

Commit

Permalink
Return no-EntityInterface $row earlier.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpustulka committed Jul 30, 2015
1 parent 0fe7060 commit dc10f87
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions src/ORM/Behavior/TranslateBehavior.php
Expand Up @@ -439,26 +439,27 @@ protected function _rowMapper($results, $locale)
public function groupTranslations($results)
{
return $results->map(function ($row) {
if ($row instanceof EntityInterface) {
$translations = (array)$row->get('_i18n');
$grouped = new Collection($translations);

$result = [];
foreach ($grouped->combine('field', 'content', 'locale') as $locale => $keys) {
$entityClass = $this->_table->entityClass();
$translation = new $entityClass($keys + ['locale' => $locale], [
'markNew' => false,
'useSetters' => false,
'markClean' => true
]);
$result[$locale] = $translation;
}

$options = ['setter' => false, 'guard' => false];
$row->set('_translations', $result, $options);
unset($row['_i18n']);
$row->clean();
if (!$row instanceof EntityInterface) {
return $row;
}
$translations = (array)$row->get('_i18n');
$grouped = new Collection($translations);

$result = [];
foreach ($grouped->combine('field', 'content', 'locale') as $locale => $keys) {
$entityClass = $this->_table->entityClass();
$translation = new $entityClass($keys + ['locale' => $locale], [
'markNew' => false,
'useSetters' => false,
'markClean' => true
]);
$result[$locale] = $translation;
}

$options = ['setter' => false, 'guard' => false];
$row->set('_translations', $result, $options);
unset($row['_i18n']);
$row->clean();
return $row;
});
}
Expand Down

0 comments on commit dc10f87

Please sign in to comment.