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
ac6bc7cd
Unverified
Commit
ac6bc7cd
authored
Jul 12, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Normalise the setting was created event
parent
875b402d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
22 deletions
+35
-22
SettingWasCreated.php
Modules/Setting/Events/SettingWasCreated.php
+6
-19
EloquentSettingRepository.php
...tting/Repositories/Eloquent/EloquentSettingRepository.php
+7
-3
EloquentSettingRepositoryTest.php
Modules/Setting/Tests/EloquentSettingRepositoryTest.php
+22
-0
No files found.
Modules/Setting/Events/SettingWasCreated.php
View file @
ac6bc7cd
...
@@ -2,30 +2,17 @@
...
@@ -2,30 +2,17 @@
namespace
Modules\Setting\Events
;
namespace
Modules\Setting\Events
;
use
Modules\Setting\Entities\Setting
;
class
SettingWasCreated
class
SettingWasCreated
{
{
/**
/**
* @var bool
* @var Setting
*/
public
$isTranslatable
;
/**
* @var string Setting name
*/
*/
public
$name
;
public
$setting
;
/**
* @var string|array
*/
public
$values
;
/**
public
function
__construct
(
Setting
$setting
)
* @param $name
* @param $isTranslatable
* @param $values
*/
public
function
__construct
(
$name
,
$isTranslatable
,
$values
)
{
{
$this
->
isTranslatable
=
$isTranslatable
;
$this
->
setting
=
$setting
;
$this
->
name
=
$name
;
$this
->
values
=
$values
;
}
}
}
}
Modules/Setting/Repositories/Eloquent/EloquentSettingRepository.php
View file @
ac6bc7cd
...
@@ -4,6 +4,7 @@ namespace Modules\Setting\Repositories\Eloquent;
...
@@ -4,6 +4,7 @@ namespace Modules\Setting\Repositories\Eloquent;
use
Illuminate\Support\Facades\Config
;
use
Illuminate\Support\Facades\Config
;
use
Modules\Core\Repositories\Eloquent\EloquentBaseRepository
;
use
Modules\Core\Repositories\Eloquent\EloquentBaseRepository
;
use
Modules\Setting\Entities\Setting
;
use
Modules\Setting\Events\SettingWasCreated
;
use
Modules\Setting\Events\SettingWasCreated
;
use
Modules\Setting\Events\SettingWasUpdated
;
use
Modules\Setting\Events\SettingWasUpdated
;
use
Modules\Setting\Repositories\SettingRepository
;
use
Modules\Setting\Repositories\SettingRepository
;
...
@@ -77,6 +78,7 @@ class EloquentSettingRepository extends EloquentBaseRepository implements Settin
...
@@ -77,6 +78,7 @@ class EloquentSettingRepository extends EloquentBaseRepository implements Settin
* Create a setting with the given name
* Create a setting with the given name
* @param string $settingName
* @param string $settingName
* @param $settingValues
* @param $settingValues
* @return Setting
*/
*/
private
function
createForName
(
$settingName
,
$settingValues
)
private
function
createForName
(
$settingName
,
$settingValues
)
{
{
...
@@ -86,14 +88,16 @@ class EloquentSettingRepository extends EloquentBaseRepository implements Settin
...
@@ -86,14 +88,16 @@ class EloquentSettingRepository extends EloquentBaseRepository implements Settin
if
(
$this
->
isTranslatableSetting
(
$settingName
))
{
if
(
$this
->
isTranslatableSetting
(
$settingName
))
{
$setting
->
isTranslatable
=
true
;
$setting
->
isTranslatable
=
true
;
$this
->
setTranslatedAttributes
(
$settingValues
,
$setting
);
$this
->
setTranslatedAttributes
(
$settingValues
,
$setting
);
event
(
new
SettingWasCreated
(
$settingName
,
true
,
$settingValues
));
}
else
{
}
else
{
$setting
->
isTranslatable
=
false
;
$setting
->
isTranslatable
=
false
;
$setting
->
plainValue
=
$this
->
getSettingPlainValue
(
$settingValues
);
$setting
->
plainValue
=
$this
->
getSettingPlainValue
(
$settingValues
);
event
(
new
SettingWasCreated
(
$settingName
,
false
,
$settingValues
));
}
}
return
$setting
->
save
();
$setting
->
save
();
event
(
new
SettingWasCreated
(
$setting
));
return
$setting
;
}
}
/**
/**
...
...
Modules/Setting/Tests/EloquentSettingRepositoryTest.php
View file @
ac6bc7cd
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
namespace
Modules\Setting\Tests
;
namespace
Modules\Setting\Tests
;
use
Illuminate\Support\Facades\Event
;
use
Modules\Setting\Events\SettingWasCreated
;
class
EloquentSettingRepositoryTest
extends
BaseSettingTest
class
EloquentSettingRepositoryTest
extends
BaseSettingTest
{
{
public
function
setUp
()
public
function
setUp
()
...
@@ -111,4 +114,23 @@ class EloquentSettingRepositoryTest extends BaseSettingTest
...
@@ -111,4 +114,23 @@ class EloquentSettingRepositoryTest extends BaseSettingTest
$this
->
assertEquals
(
'core::locales'
,
$setting
->
name
);
$this
->
assertEquals
(
'core::locales'
,
$setting
->
name
);
$this
->
assertEquals
(
'["su","bi","bs"]'
,
$setting
->
plainValue
);
$this
->
assertEquals
(
'["su","bi","bs"]'
,
$setting
->
plainValue
);
}
}
/** @test */
public
function
it_triggers_event_when_setting_was_created
()
{
Event
::
fake
();
$data
=
[
'core::template'
=>
'asgard'
,
'core::site-name'
=>
[
'en'
=>
'AsgardCMS_en'
,
'fr'
=>
'AsgardCMS_fr'
,
],
];
$this
->
settingRepository
->
createOrUpdate
(
$data
);
Event
::
assertDispatched
(
SettingWasCreated
::
class
,
function
(
$e
)
{
return
$e
->
setting
->
name
===
'core::template'
;
});
}
}
}
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