Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
07f036e6
Unverified
Commit
07f036e6
authored
Apr 19, 2018
by
Nicolas Widart
Committed by
GitHub
Apr 19, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #522 from darron1217/setting
[Setting Module] Add view type media-single
parents
5de11460
14a18d27
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
89 additions
and
7 deletions
+89
-7
Setting.php
Modules/Setting/Entities/Setting.php
+8
-1
SettingWasCreated.php
Modules/Setting/Events/SettingWasCreated.php
+25
-2
SettingWasUpdated.php
Modules/Setting/Events/SettingWasUpdated.php
+26
-2
EloquentSettingRepository.php
...tting/Repositories/Eloquent/EloquentSettingRepository.php
+12
-2
media-single.blade.php
...Resources/views/admin/fields/plain/media-single.blade.php
+5
-0
media-single.blade.php
...es/views/admin/fields/translatable/media-single.blade.php
+5
-0
Settings.php
Modules/Setting/Support/Settings.php
+4
-0
BaseSettingTest.php
Modules/Setting/Tests/BaseSettingTest.php
+4
-0
No files found.
Modules/Setting/Entities/Setting.php
View file @
07f036e6
...
...
@@ -4,12 +4,19 @@ 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'
];
protected
$table
=
'setting__settings'
;
public
function
isMedia
()
:
bool
{
$value
=
json_decode
(
$this
->
plainValue
,
true
);
return
is_array
(
$value
)
&&
isset
(
$value
[
'medias_single'
]);
}
}
Modules/Setting/Events/SettingWasCreated.php
View file @
07f036e6
...
...
@@ -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
;
}
}
Modules/Setting/Events/SettingWasUpdated.php
View file @
07f036e6
...
...
@@ -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
;
}
}
Modules/Setting/Repositories/Eloquent/EloquentSettingRepository.php
View file @
07f036e6
...
...
@@ -49,6 +49,16 @@ class EloquentSettingRepository extends EloquentBaseRepository implements Settin
$this
->
removeTokenKey
(
$settings
);
foreach
(
$settings
as
$settingName
=>
$settingValues
)
{
// Check if media exists
if
(
$settingName
==
'medias_single'
)
{
// 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
;
}
...
...
Modules/Setting/Resources/views/admin/fields/plain/media-single.blade.php
0 → 100644
View file @
07f036e6
@
php
$setting
=
isset
(
$dbSettings
[
$settingName
])
?
$dbSettings
[
$settingName
]
:
null
;
@
endphp
@
mediaSingle
(
$settingName
,
$setting
,
null
,
trans
(
$moduleInfo
[
'description'
]))
Modules/Setting/Resources/views/admin/fields/translatable/media-single.blade.php
0 → 100644
View file @
07f036e6
@
php
$setting
=
isset
(
$dbSettings
[
$settingName
])
?
$dbSettings
[
$settingName
]
:
null
;
@
endphp
@
mediaSingle
(
$settingName
,
$setting
,
null
,
trans
(
$moduleInfo
[
'description'
]))
Modules/Setting/Support/Settings.php
View file @
07f036e6
...
...
@@ -36,6 +36,10 @@ class Settings implements Setting
return
is_null
(
$default
)
?
$defaultFromConfig
:
$default
;
}
if
(
$setting
->
isMedia
()
&&
$media
=
$setting
->
files
()
->
first
())
{
return
$media
->
path
;
}
if
(
$setting
->
isTranslatable
)
{
if
(
$setting
->
hasTranslation
(
$locale
))
{
return
trim
(
$setting
->
translate
(
$locale
)
->
value
)
===
''
?
$defaultFromConfig
:
$setting
->
translate
(
$locale
)
->
value
;
...
...
Modules/Setting/Tests/BaseSettingTest.php
View file @
07f036e6
...
...
@@ -78,5 +78,9 @@ abstract class BaseSettingTest extends TestCase
$this
->
artisan
(
'migrate'
,
[
'--database'
=>
'sqlite'
,
]);
$this
->
artisan
(
'migrate'
,
[
'--database'
=>
'sqlite'
,
'--path'
=>
'Modules/Media/Database/Migrations'
,
]);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment