]> _ Git - cubist_cms-back.git/commitdiff
wip #5851 @5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 11 Apr 2023 15:58:14 +0000 (17:58 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 11 Apr 2023 15:58:14 +0000 (17:58 +0200)
composer.json
src/app/Magic/MagicObserver.php
src/app/Magic/Models/CubistMagicAbstractModel.php
src/app/Magic/Models/CubistMagicTranslatableModel.php
src/app/Magic/Models/Translate.php

index 49c72b4a83e5f09cb27ac2401d45f227d134b8d5..2010afba7c5aac9cd4430d8db4f8dd32b4cd8da2 100644 (file)
@@ -31,7 +31,7 @@
         "backpack/pro": "^1.6.4",
         "cubist/cms-front": "dev-backpack5",
         "cubist/util": "dev-master",
-        "cubist/locale": "dev-master",
+        "cubist/locale": "dev-backpack5",
         "cubist/laravel-backpack-dropzone-field": "dev-master",
         "spatie/laravel-translatable": "^6.4.0",
         "venturecraft/revisionable": "^1.40.0",
index 318c62d1881a255ea6219be1ed2888037601f83f..efae5b55c0ad7cdc8f72233b3f346dabcd3e03cc 100644 (file)
@@ -57,6 +57,11 @@ class MagicObserver
         return $this->_trigger($model, 'restored');
     }
 
+    function retrieved(CubistMagicAbstractModel $model){
+        return $this->_trigger($model, 'retrieved');
+    }
+
+
     protected function _trigger($model, $event)
     {
         $event = Str::camel('on_' . $event);
index 347011b9570e66c1bf7a8200c37d21aedef82684..27a6e8806af678e212cd265fe72d1311978c3e21 100644 (file)
@@ -160,7 +160,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia
     public function __construct(array $attributes = [])
     {
         $this->setup();
-
         parent::__construct($attributes);
 
     }
@@ -170,10 +169,11 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         if (null !== $this->connection) {
             $this->setConnection($this->connection);
         }
-        start_measure('Set form fields');
+        $label = 'Set '.get_class($this).' form fields';
+        start_measure($label);
         $this->setFields();
         $this->postSetFields();
-        stop_measure('Set form fields');
+        stop_measure($label);
     }
 
     /**
@@ -192,19 +192,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia
 
     }
 
-    public function newFromBuilder($attributes = [], $connection = null)
-    {
-        $res = parent::newFromBuilder($attributes, $connection);
-        $this->onRetreived();
-        return $res;
-    }
-
-
-    public function onRetreived()
-    {
-
-    }
-
     public function getPrimaryKey()
     {
         return $this->primaryKey;
@@ -1281,6 +1268,11 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         return $nb;
     }
 
+    public function onRetrieved(): bool
+    {
+        return true;
+    }
+
     public function onSaved(): bool
     {
         return true;
index f0d3067be30f0c33f948a44a5a84862f9ff517db..7f9b897f4fc9ea38b490dc2fc46440d062abb170 100644 (file)
@@ -55,13 +55,15 @@ class CubistMagicTranslatableModel extends CubistMagicAbstractModel
         return $field;
     }
 
-    public function getTranslations(string $key = null): array
+    public function getTranslations(string $key = null, array $allowedLocales = null): array
     {
         if ($key !== null) {
             if (isset($this->_translations[$key])) {
                 return $this->_translations[$key];
             }
-            start_measure('Get translation of ' . $key);
+            $measure_label = 'Get translation of ' . get_class($this) . '::' . $key;
+            throw new \Error(':(');
+            start_measure($measure_label);
             $this->guardAgainstNonTranslatableAttribute($key);
             $attrs = $this->getAttributes();
             if (!isset($attrs[$key])) {
@@ -86,14 +88,13 @@ class CubistMagicTranslatableModel extends CubistMagicAbstractModel
                 });
             }
             $this->_translations[$key] = $res;
-            stop_measure('Get translation of ' . $key);
+            stop_measure($measure_label);
             return $res;
         }
 
         start_measure('Get all translations');
         $res = array_reduce($this->getTranslatableAttributes(), function ($result, $item) {
             $result[$item] = $this->getTranslations($item);
-
             return $result;
         });
         stop_measure('Get all translations');
@@ -137,8 +138,8 @@ class CubistMagicTranslatableModel extends CubistMagicAbstractModel
             $value = $this->_migrateTranslation($key);
         }
 
-        if(str_starts_with($key,'t_') && !$value){
-            $value='';
+        if (str_starts_with($key, 't_') && !$value) {
+            $value = '';
         }
 
         if (null === $f) {
index 9a771e0f8555c41663f19d86681b0bf284844542..7c9bed09e650f7ac37b5a74339b4babb85dd5804 100644 (file)
@@ -57,6 +57,7 @@ class Translate extends CubistMagicTranslatableModel
         $currentSection = '-';
         $sections = [$currentSection => []];
 
+
         foreach ($translate->getStringToTranslate() as $sectionLabel => $strings) {
             $toTranslate = [];
             foreach ($strings as $string) {
@@ -121,12 +122,17 @@ class Translate extends CubistMagicTranslatableModel
         }
     }
 
+    public function onRetrieved(): bool
+    {
+        $res = parent::onRetrieved();
+        return $res;
+    }
+
     protected static function _encodeKey($string)
     {
         return 't_' . base64_encode($string);
     }
 
-
     public function onSaving(): bool
     {
         $this->saveLanguageFile();