]> _ Git - cubist_cms-back.git/commitdiff
wip #3473
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 6 Mar 2020 14:57:56 +0000 (15:57 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 6 Mar 2020 14:57:56 +0000 (15:57 +0100)
src/app/Magic/Controllers/CubistMagicController.php
src/app/Magic/Models/CubistMagicAbstractModel.php

index 264a7e403df94487b079f78feb8a9928954c9a97..426787cb55cf9702b3cee8ab9162e48eeb3db9c2 100644 (file)
@@ -96,8 +96,6 @@ class CubistMagicController extends CubistCrudController
         */
         $this->crud->addColumn(['name' => $model->getPrimaryKey(), 'type' => 'number', 'label' => "#", 'searchLogic' => 'text']);
 
-        $this->getModelInstance()->setupButtons($this->crud);
-
         $this->updateFieldsFromModel($model);
     }
 
index 324fe911372ad936bb57b4fa70fdc45d576f07d1..5a6f1b186d820999d82195538a5de2880f65c450 100644 (file)
@@ -604,6 +604,28 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         return $f->filterValue($value);
     }
 
+    /**
+     * @param string $fieldname
+     * @param string|\Symfony\Component\HttpFoundation\File\UploadedFile $filepath
+     * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded\DiskDoesNotExist
+     * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded\FileDoesNotExist
+     * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded\FileIsTooBig
+     */
+    public function addMediaToField($fieldname, $filepath)
+    {
+        $collection = $this->getAttribute($fieldname);
+        $save = false;
+        if (!$collection) {
+            $collection = substr(hash('sha256', uniqid($fieldname, true)), 0, 10);
+            $this->setAttribute($fieldname, $collection);
+            $save = true;
+        }
+        $this->addMedia($filepath)->toMediaCollection($collection);
+        if ($save) {
+            $this->save();
+        }
+    }
+
     public function replicate(array $except = null)
     {