]> _ Git - cubist_cms-back.git/commitdiff
wip #4464 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 19 May 2021 10:09:46 +0000 (12:09 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 19 May 2021 10:09:46 +0000 (12:09 +0200)
src/app/Magic/Fields/Field.php
src/app/Magic/Fields/Files.php
src/app/Magic/Models/CubistMagicAbstractModel.php
src/resources/views/fields/dropzone_media.blade.php

index 34e2af541a4065d4a362dfd24596bbbfe7988721..2b2daa6dccbe1e8dac70bd380b10e79484db1e5b 100644 (file)
@@ -151,6 +151,13 @@ class Field implements \ArrayAccess
         $this->init();
     }
 
+    /**
+     * @return string
+     */
+    public function getName(){
+        return $this->getAttribute('name');
+    }
+
     public function getRules()
     {
         return $this->getAttribute('rules', '');
index 9177edce56abc73ebb77eec62b80574541a7baa2..c9809cf9446be88319fe75a4e9a4eadb116cc826 100644 (file)
@@ -12,17 +12,19 @@ class Files extends Field
     protected $_adminType = 'dropzone_media';
     protected $_viewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::fields';
     protected $_databaseType = 'text';
-    protected $_thumbCollection = 'backpack_thumb';
+    protected $_thumbConversion = 'backpack_thumb';
+    protected $_nameAsCollection = false;
     protected $_maxFiles = 1;
 
     public function getDefaultAttributes()
     {
         $collection = '_TBD_';
         return array_merge(parent::getDefaultAttributes(), [
+            'name_as_collection' => $this->_nameAsCollection,
             'form' => 'update',
             'mime_types' => $this->_mimeTypes,
             'collection' => $collection,
-            'thumb_collection' => $this->_thumbCollection,
+            'thumb_conversion' => $this->_thumbConversion,
             'default' => $collection,
             'options' =>
                 [
@@ -36,6 +38,16 @@ class Files extends Field
         ]);
     }
 
+    protected function _postSetAttributes()
+    {
+        parent::_postSetAttributes();
+        if ($this->getAttribute('name_as_collection')) {
+            $name = $this->getAttribute('name');
+            $this->setAttribute('collection', $name);
+            $this->setAttribute('default', $name);
+        }
+    }
+
     protected function _getAttributesAliases()
     {
         return array_merge(parent::_getAttributesAliases(), [
index f5ab86a3c86bd337a11b226f4bbcf2d4c287908e..0cc7058e150cb6f5e6411ae4758e956f376d03f2 100644 (file)
@@ -655,7 +655,12 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         $collection = $this->getAttribute($fieldname);
         $save = false;
         if (!$collection) {
-            $collection = substr(hash('sha256', uniqid($fieldname, true)), 0, 10);
+            $field = $this->getField($fieldname);
+            if ($field->getAttribute('name_as_collection', false)) {
+                $collection = $fieldname;
+            } else {
+                $collection = substr(hash('sha256', uniqid($fieldname, true)), 0, 10);
+            }
             $this->setAttribute($fieldname, $collection);
             $save = true;
         }
index 6f5f19d564dad6b1eead49255c3178184099dd84..34a4dc204701a52e8bfc6e45272dcc8b5a953b7b 100644 (file)
@@ -171,7 +171,7 @@ $collection = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ??
                 }
 
                 try {
-                    $thumb_url = $media->getUrl($field['thumb_collection'] ?? null);
+                    $thumb_url = $media->getUrl($field['thumb_conversion'] ?? null);
                 } catch (Exception $e) {
                     $thumb_url = '';
                 }