From: Vincent Vanwaelscappel Date: Tue, 15 Mar 2022 11:52:52 +0000 (+0100) Subject: wip #5161 @0.25 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=626458bc5597831f72b8253ac51552c1d63d1e63;p=cubist_cms-back.git wip #5161 @0.25 --- diff --git a/src/app/Magic/Models/CubistMagicTranslatableModel.php b/src/app/Magic/Models/CubistMagicTranslatableModel.php index e971209..4fc8dc3 100644 --- a/src/app/Magic/Models/CubistMagicTranslatableModel.php +++ b/src/app/Magic/Models/CubistMagicTranslatableModel.php @@ -19,6 +19,8 @@ class CubistMagicTranslatableModel extends CubistMagicAbstractModel getAvailableLocales as protected getAvailableLocalesTranslations; } + protected $_translations = []; + /** * @var array */ @@ -56,6 +58,10 @@ class CubistMagicTranslatableModel extends CubistMagicAbstractModel public function getTranslations(string $key = null): array { if ($key !== null) { + if (isset($this->_translations[$key])) { + return $this->_translations[$key]; + } + start_measure('Get translation of ' . $key); $this->guardAgainstNonTranslatableAttribute($key); $attrs = $this->getAttributes(); if (!isset($attrs[$key])) { @@ -71,18 +77,21 @@ class CubistMagicTranslatableModel extends CubistMagicAbstractModel } if ($key === 'slug') { - return array_filter($v, function ($value) { + $res = array_filter($v, function ($value) { return $value !== null; }); } else { - return array_filter($v, function ($value) { + $res = array_filter($v, function ($value) { return $value !== null && $value !== ''; }); } + $this->_translations[$key] = $res; + stop_measure('Get translation of ' . $key); + return $res; } start_measure('Get all translations'); - $res= array_reduce($this->getTranslatableAttributes(), function ($result, $item) { + $res = array_reduce($this->getTranslatableAttributes(), function ($result, $item) { $result[$item] = $this->getTranslations($item); return $result;