Commit ccfc2989 authored by Darron Park's avatar Darron Park

Add view type media-single on Setting Module (to resolve logo uploading issue#474)

parent 5de11460
......@@ -4,10 +4,11 @@ namespace Modules\Setting\Entities;
use Dimsav\Translatable\Translatable;
use Illuminate\Database\Eloquent\Model;
use Modules\Media\Support\Traits\MediaRelation;
class Setting extends Model
{
use Translatable;
use Translatable, MediaRelation;
public $translatedAttributes = ['value', 'description'];
protected $fillable = ['name', 'value', 'description', 'isTranslatable', 'plainValue'];
......
......@@ -2,17 +2,40 @@
namespace Modules\Setting\Events;
use Modules\Media\Contracts\StoringMedia;
use Modules\Setting\Entities\Setting;
class SettingWasCreated
class SettingWasCreated implements StoringMedia
{
/**
* @var Setting
*/
public $setting;
public function __construct(Setting $setting)
/**
* @var array
*/
public $data;
public function __construct(Setting $setting, $data)
{
$this->setting = $setting;
$this->data = $data;
}
/**
* @inheritDoc
*/
public function getEntity()
{
return $this->setting;
}
/**
* @inheritDoc
*/
public function getSubmissionData()
{
return $this->data;
}
}
......@@ -2,17 +2,41 @@
namespace Modules\Setting\Events;
use Modules\Media\Contracts\StoringMedia;
use Modules\Setting\Entities\Setting;
class SettingWasUpdated
class SettingWasUpdated implements StoringMedia
{
/**
* @var Setting
*/
public $setting;
public function __construct(Setting $setting)
/**
* @var array
*/
public $data;
public function __construct(Setting $setting, $data)
{
$this->setting = $setting;
$this->data = $data;
}
/**
* @inheritDoc
*/
public function getEntity()
{
return $this->setting;
}
/**
* @inheritDoc
*/
public function getSubmissionData()
{
return $this->data;
}
}
......@@ -49,6 +49,16 @@ class EloquentSettingRepository extends EloquentBaseRepository implements Settin
$this->removeTokenKey($settings);
foreach ($settings as $settingName => $settingValues) {
// Check if media exists
if(in_array($settingName, ['medias_single', 'medias_multiple'])) {
// Get first key of values (Original settingName)
foreach ($settingValues as $key => $value) {
$normalisedValue = [ $settingName => [$key => $value] ];
$settingName = $key;
break;
}
$settingValues = $normalisedValue;
}
if ($setting = $this->findByName($settingName)) {
$this->updateSetting($setting, $settingValues);
continue;
......@@ -99,7 +109,7 @@ class EloquentSettingRepository extends EloquentBaseRepository implements Settin
$setting->save();
event(new SettingWasCreated($setting));
event(new SettingWasCreated($setting, $settingValues));
return $setting;
}
......@@ -121,7 +131,7 @@ class EloquentSettingRepository extends EloquentBaseRepository implements Settin
}
$setting->save();
event(new SettingWasUpdated($setting));
event(new SettingWasUpdated($setting, $settingValues));
return $setting;
}
......
@php
$setting = isset($dbSettings[$settingName]) ? $dbSettings[$settingName] : null;
@endphp
@mediaSingle($settingName, $setting, null, trans($moduleInfo['description']))
@php
$setting = isset($dbSettings[$settingName]) ? $dbSettings[$settingName] : null;
@endphp
@mediaSingle($settingName, $setting, null, trans($moduleInfo['description']))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment