Unverified Commit d7183b4d authored by Nicolas Widart's avatar Nicolas Widart

Merge branch '2.0'

* 2.0: (90 commits)
  Removing old stylist command
  Using ::class notation
  Using ::class notation
  Preparing 2.5.0 versions
  Preparing 2.5.0 changelogs
  CLosing css stack
  Using the @push js stacks over the scripts section
  Using the @push css stacks over the styles section
  New changelog item
  Remove the ckeditor inclusion on create/edit view stubs
  Adding changelog item
  Adding back the correct old input for the body field
  Adding changelog item for core module
  Creating a non translatable textarea component and make it usable with same @editor directive
  Fixing field name variable echo
  Moving assets inclusion to component
  Using new blade directives
  Bringing back the js and css stacks on main views
  Moving css and js stacks outside the component. Making field and label name dynamic
  Create a blade directive to use @editor
  ...
parents 91a20564 35c1d5ba
......@@ -10,6 +10,7 @@ $finder = PhpCsFixer\Finder::create()
'bootstrap',
'tests',
'node_modules',
'views',
])
->notPath('server.php')
;
......
<?php
namespace Modules\Core\Blade;
class AsgardEditorDirective
{
private $content;
private $lang;
private $fieldName;
private $labelName;
public function show($arguments)
{
$this->extractArguments($arguments);
if ($this->lang !== null) {
return asgard_i18n_editor($this->fieldName, $this->labelName, $this->content, $this->lang);
}
return asgard_editor($this->fieldName, $this->labelName, $this->content);
}
/**
* Extract the possible arguments as class properties
* @param array $arguments
*/
private function extractArguments(array $arguments)
{
$this->fieldName = array_get($arguments, 0);
$this->labelName = array_get($arguments, 1);
$this->content = array_get($arguments, 2);
$this->lang = array_get($arguments, 3);
}
}
<?php
namespace Modules\Core\Blade\Facades;
use Illuminate\Support\Facades\Facade;
class AsgardEditorDirective extends Facade
{
protected static function getFacadeAccessor()
{
return 'core.asgard.editor';
}
}
......@@ -4,6 +4,8 @@ namespace Modules\Core\Composers;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Modules\Core\Events\CollectingAssets;
use Modules\Core\Events\EditorIsRendering;
use Modules\Core\Foundation\Asset\Manager\AssetManager;
use Modules\Core\Foundation\Asset\Pipeline\AssetPipeline;
use Modules\Core\Foundation\Asset\Types\AssetTypeFactory;
......@@ -48,7 +50,11 @@ class AssetsViewComposer
$this->assetPipeline->requireCss(config('asgard.core.core.admin-required-assets.css'));
$this->assetPipeline->requireJs(config('asgard.core.core.admin-required-assets.js'));
event($editor = new EditorIsRendering($this->assetPipeline));
event(new CollectingAssets($this->assetPipeline));
$view->with('cssFiles', $this->assetPipeline->allCss());
$view->with('jsFiles', $this->assetPipeline->allJs());
$view->with('editor', $editor);
}
}
......@@ -13,6 +13,9 @@ return [
'workshop',
'setting',
'media',
'tag',
'page',
'translation',
],
/*
......
......@@ -32,6 +32,18 @@ return [
*/
'skin' => 'skin-blue',
/*
|--------------------------------------------------------------------------
| WYSIWYG Backend Editor
|--------------------------------------------------------------------------
| Define which editor you would like to use for the backend wysiwygs.
| These classes are event handlers, listening to EditorIsRendering
| you can define your own handlers and use them here
| Options:
| - \Modules\Core\Events\Handlers\LoadCkEditor::class
| - \Modules\Core\Events\Handlers\LoadSimpleMde::class
*/
'wysiwyg-handler' => \Modules\Core\Events\Handlers\LoadCkEditor::class,
/*
|--------------------------------------------------------------------------
| Custom CKeditor configuration file
......@@ -84,6 +96,7 @@ return [
'selectize-default.css' => ['module' => 'core:vendor/selectize/dist/css/selectize.default.css'],
'animate.css' => ['theme' => 'vendor/animate.css/animate.min.css'],
'pace.css' => ['theme' => 'vendor/admin-lte/plugins/pace/pace.min.css'],
'simplemde.css' => ['theme' => 'vendor/simplemde/dist/simplemde.min.css'],
// Javascript
'bootstrap.js' => ['theme' => 'vendor/bootstrap/dist/js/bootstrap.min.js'],
'mousetrap.js' => ['theme' => 'js/vendor/mousetrap.min.js'],
......@@ -110,6 +123,7 @@ return [
'pace.js' => ['theme' => 'vendor/admin-lte/plugins/pace/pace.min.js'],
'moment.js' => ['theme' => 'vendor/admin-lte/plugins/daterangepicker/moment.min.js'],
'clipboard.js' => ['theme' => 'vendor/clipboard/dist/clipboard.min.js'],
'simplemde.js' => ['theme' => 'vendor/simplemde/dist/simplemde.min.js'],
],
/*
......
<?php
namespace Modules\Core\Contracts;
interface EntityIsChanging
{
/**
* Get the attributes used to create or modify an entity
* @return array
*/
public function getAttributes();
/**
* Set the attributes used to create or modify an entity
* @param array $attributes
*/
public function setAttributes(array $attributes);
/**
* Get the original attributes untouched by other listeners
* @return array
*/
public function getOriginal();
}
<?php
namespace Modules\Core\Events;
abstract class AbstractEntityHook
{
/**
* Contains the attributes which can be changed by other listeners
* @var array
*/
private $attributes;
/**
* Contains the original attributes which cannot be changed
* @var array
*/
private $original;
public function __construct(array $attributes)
{
$this->attributes = $attributes;
$this->original = $attributes;
}
/**
* @return array
*/
public function getAttributes()
{
return $this->attributes;
}
/**
* @param string $attribute
* @param null $default
* @return string|null
*/
public function getAttribute($attribute, $default = null)
{
return data_get($this->attributes, $attribute, $default);
}
/**
* @param array $attributes
*/
public function setAttributes(array $attributes)
{
$this->attributes = array_replace_recursive($this->attributes, $attributes);
}
/**
* @param string|null $key
* @param string|null $default
* @return array
*/
public function getOriginal($key = null, $default = null)
{
if ($key !== null) {
return data_get($this->original, $key, $default);
}
return $this->original;
}
}
<?php
namespace Modules\Core\Events;
use Modules\Core\Foundation\Asset\Pipeline\AssetPipeline;
class CollectingAssets
{
/**
* @var AssetPipeline
*/
private $assetPipeline;
public function __construct(AssetPipeline $assetPipeline)
{
$this->assetPipeline = $assetPipeline;
}
/**
* @param string $asset
* @return AssetPipeline
*/
public function requireJs($asset)
{
return $this->assetPipeline->requireJs($asset);
}
/**
* @param string $asset
* @return AssetPipeline
*/
public function requireCss($asset)
{
return $this->assetPipeline->requireCss($asset);
}
/**
* Match a single route
* @param string|array $route
* @return bool
*/
public function onRoute($route)
{
$request = request();
return str_is($route, $request->route()->getName());
}
/**
* Match multiple routes
* @param array $routes
* @return bool
*/
public function onRoutes(array $routes)
{
$request = request();
foreach ($routes as $route) {
if (str_is($route, $request->route()->getName()) === true) {
return true;
}
}
return false;
}
}
<?php
namespace Modules\Core\Events;
use Modules\Core\Foundation\Asset\Pipeline\AssetPipeline;
class EditorIsRendering
{
/**
* @var AssetPipeline
*/
private $assetPipeline;
private $editorClass;
private $editorJsPartial;
private $editorCssPartial;
private $editorComponents = [
'i18n' => 'core::components.i18n.textarea',
'normal' => 'core::components.textarea',
];
public function __construct(AssetPipeline $assetPipeline)
{
$this->assetPipeline = $assetPipeline;
}
public function addJs($asset)
{
$this->assetPipeline->requireJs($asset);
return $this;
}
public function addCss($asset)
{
$this->assetPipeline->requireCss($asset);
return $this;
}
/**
* @return mixed
*/
public function getEditorClass()
{
return $this->editorClass;
}
/**
* @param mixed $editorClass
*/
public function setEditorClass($editorClass)
{
$this->editorClass = $editorClass;
}
/**
* @return mixed
*/
public function getEditorJsPartial()
{
return $this->editorJsPartial;
}
/**
* @param mixed $editorJsPartial
*/
public function setEditorJsPartial($editorJsPartial)
{
$this->editorJsPartial = $editorJsPartial;
}
/**
* @return mixed
*/
public function getEditorCssPartial()
{
return $this->editorCssPartial;
}
/**
* @param mixed $editorCssPartial
*/
public function setEditorCssPartial($editorCssPartial)
{
$this->editorCssPartial = $editorCssPartial;
}
public function getI18nComponentName()
{
return $this->editorComponents['i18n'];
}
public function setI18nComponentName($componentName)
{
$this->editorComponents['i18n'] = $componentName;
}
public function getComponentName()
{
return $this->editorComponents['normal'];
}
public function setComponentName($componentName)
{
$this->editorComponents['normal'] = $componentName;
}
}
<?php
namespace Modules\Core\Events\Handlers;
use Modules\Core\Events\EditorIsRendering;
class LoadCkEditor
{
public function handle(EditorIsRendering $editor)
{
$editor->addJs('ckeditor.js');
$editor->setEditorClass('ckeditor');
return false;
}
}
<?php
namespace Modules\Core\Events\Handlers;
use Modules\Core\Events\EditorIsRendering;
class LoadSimpleMde
{
public function handle(EditorIsRendering $editor)
{
$editor->addJs('simplemde.js')->addCss('simplemde.css');
$editor->setEditorClass('simplemde');
$editor->setEditorJsPartial('core::partials.simplemde');
return false;
}
}
<?php
namespace Modules\Core\Events\Handlers;
use League\CommonMark\CommonMarkConverter;
use Modules\Page\Events\ContentIsRendering;
class RenderMarkdown
{
public function handle(ContentIsRendering $event)
{
$converter = new CommonMarkConverter();
$html = $converter->convertToHtml($event->getOriginal());
$event->setBody($html);
}
}
......@@ -7,11 +7,13 @@ use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;
use Modules\Core\Blade\AsgardEditorDirective;
use Modules\Core\Console\DeleteModuleCommand;
use Modules\Core\Console\DownloadModuleCommand;
use Modules\Core\Console\InstallCommand;
use Modules\Core\Console\PublishModuleAssetsCommand;
use Modules\Core\Console\PublishThemeAssetsCommand;
use Modules\Core\Events\EditorIsRendering;
use Modules\Core\Foundation\Theme\ThemeManager;
use Modules\Core\Traits\CanPublishConfiguration;
use Nwidart\Modules\Module;
......@@ -53,6 +55,7 @@ class CoreServiceProvider extends ServiceProvider
$this->registerModuleResourceNamespaces();
$this->bladeDirectives();
$this->app['events']->listen(EditorIsRendering::class, config('asgard.core.core.wysiwyg-handler'));
}
/**
......@@ -72,6 +75,10 @@ class CoreServiceProvider extends ServiceProvider
$this->registerCommands();
$this->registerServices();
$this->setLocalesConfigurations();
$this->app->bind('core.asgard.editor', function () {
return new AsgardEditorDirective();
});
}
/**
......@@ -305,6 +312,10 @@ class CoreServiceProvider extends ServiceProvider
*/
public function bladeDirectives()
{
if (app()->environment() === 'testing') {
return;
}
/**
* Set variable.
* Usage: @set($variable, value)
......@@ -314,6 +325,10 @@ class CoreServiceProvider extends ServiceProvider
return "<?php {$variable} = {$value}; ?>";
});
$this->app['blade.compiler']->directive('editor', function ($value) {
return "<?php echo AsgardEditorDirective::show([$value]); ?>";
});
}
/**
......
@component($editor->getI18nComponentName(), compact('lang', 'fieldName', 'labelName'))
{!! $content !!}
@endcomponent
@if ($editor->getEditorCssPartial() !== null)
@if (Cache::store('array')->add('textareaCssLoaded', true, 100))
@include($editor->getEditorCssPartial())
@endif
@endif
<div class='{{ $errors->has("{$lang}.{$fieldName}") ? ' has-error' : '' }}'>
{!! Form::label("{$lang}[{$fieldName}]", $labelName) !!}
<textarea class="{{ $editor->getEditorClass() }}" name="{{$lang}}[{{$fieldName}}]" rows="10" cols="80">{{ $slot }}</textarea>
{!! $errors->first("{$lang}.{$fieldName}", '<span class="help-block">:message</span>') !!}
</div>
@if ($editor->getEditorJsPartial() !== null)
@if (Cache::store('array')->add('textareaJsLoaded', true, 100))
@include($editor->getEditorJsPartial())
@endif
@endif
@component($editor->getComponentName(), compact('fieldName', 'labelName'))
{!! $content !!}
@endcomponent
@if ($editor->getEditorCssPartial() !== null)
@if (Cache::store('array')->add('textareaCssLoaded', true, 100))
@include($editor->getEditorCssPartial())
@endif
@endif
<div class='{{ $errors->has($fieldName) ? ' has-error' : '' }}'>
{!! Form::label($fieldName, $labelName) !!}
<textarea class="{{ $editor->getEditorClass() }}" name="{{ $fieldName }}" rows="10" cols="80">{{ $slot }}</textarea>
{!! $errors->first($fieldName, '<span class="help-block">:message</span>') !!}
</div>
@if ($editor->getEditorJsPartial() !== null)
@if (Cache::store('array')->add('textareaJsLoaded', true, 100))
@include($editor->getEditorJsPartial())
@endif
@endif
@push('js-stack')
<script>
$( document ).ready(function() {
$('.simplemde').each(function () {
var simplemde = new SimpleMDE({
element: this,
});
simplemde.render();
});
});
</script>
@endpush
url: https://github.com/AsgardCms/Platform
versions:
"2.5.0@unreleased":
added:
- Adding a <code>EntityIsChanging</code> interface to use on events which are triggered before a create / update action
- Create an <code>AbstractEntityHook</code> containing base logic for entity hooks
- Trigger the <code>EditorIsRendering</code> event on assets view composer and send editor variable to view
- New configuration value <code>wysiwyg-handler</code> in <code>config/asgard/core/core.php</code> to change the editor in backend
- New handler <code>RenderMarkdown</code> if you want to render markdown on a <code>ContentIsRendering</code> event
- New <code>@editor('fieldname', 'fieldlabel, 'content', 'locale')</code> blade directive to include a textarea. The last <code>locale</code> parameter is optional and can be omitted for non translatable textarea.
changed:
- Adding more core modules (tag, translation and page). Preventing them to be disabled.
"2.3.0":
added:
- New command <code>php artisan asgard:download:module asgardcms/contact --migrations --seeds --assets</code>
......
......@@ -7,4 +7,4 @@ view()->composer('core::fields.select-theme', \Modules\Core\Composers\ThemeCompo
view()->composer('core::fields.select-locales', \Modules\Core\Composers\SettingLocalesComposer::class);
view()->composer('*', \Modules\Core\Composers\LocaleComposer::class);
view()->composer('*', \Modules\Core\Composers\CurrentUserViewComposer::class);
view()->composer('layouts.master', \Modules\Core\Composers\AssetsViewComposer::class);
view()->composer('*', \Modules\Core\Composers\AssetsViewComposer::class);
......@@ -33,3 +33,18 @@ if (! function_exists('is_core_module')) {
return in_array(strtolower($module), app('asgard.ModulesList'));
}
}
if (! function_exists('asgard_i18n_editor')) {
function asgard_i18n_editor($fieldName, $labelName, $content, $lang)
{
return view('core::components.i18n.textarea-wrapper', compact('fieldName','labelName', 'content', 'lang'));
}
}
if (! function_exists('asgard_editor')) {
function asgard_editor($fieldName, $labelName, $content)
{
return view('core::components.textarea-wrapper', compact('fieldName','labelName', 'content'));
}
}
......@@ -4,7 +4,7 @@
"description": "The core module with all base classes and logic.",
"keywords": [],
"require": {},
"version": "2.0.0",
"version": "2.5.0",
"active": 1,
"order": 0,
"providers": [
......@@ -20,7 +20,8 @@
"aliases": {
"Form": "Collective\\Html\\FormFacade",
"Flash": "Laracasts\\Flash\\Flash",
"LaravelLocalization": "Mcamara\\LaravelLocalization\\Facades\\LaravelLocalization"
"LaravelLocalization": "Mcamara\\LaravelLocalization\\Facades\\LaravelLocalization",
"AsgardEditorDirective": "Modules\\Core\\Blade\\Facades\\AsgardEditorDirective"
},
"files": [
"start.php",
......
var gulp = require("gulp");
var shell = require('gulp-shell');
var elixir = require('laravel-elixir');
var themeInfo = require('./theme.json');
var Task = elixir.Task;
elixir.extend('stylistPublish', function() {
new Task('stylistPublish', function() {
return gulp.src("").pipe(shell("php ../../artisan stylist:publish " + themeInfo.name));
});
});
......@@ -12,13 +12,13 @@
<div class="clearfix"></div>
@stop
@section('styles')
@push('css-stack')
<style>
.grid-stack-item {
padding-right: 20px !important;
}
</style>
@stop
@endpush
@section('content')
......@@ -46,7 +46,7 @@
</div>
@stop
@section('scripts')
@push('js-stack')
@parent
<script type="text/javascript">
$(document).ready(function () {
......@@ -157,4 +157,4 @@
});
</script>
@stop
@endpush
url: https://github.com/AsgardCms/Platform
versions:
"2.5.0@unreleased":
changed:
- Using the @push js stacks over the scripts section
- Using the @push css stacks over the styles section
"2.0.0":
added:
- Laravel 5.4 compatibility
......
......@@ -3,7 +3,7 @@
"alias": "dashboard",
"description": "The module responsible for the admin dashboard page.",
"keywords": [],
"version": "2.0.0",
"version": "2.5.0",
"active": 1,
"order": 1,
"providers": [
......
<?php
namespace Modules\Media\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
final class FileIsCreating extends AbstractEntityHook implements EntityIsChanging
{
}
<?php
namespace Modules\Media\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
use Modules\Media\Entities\File;
final class FileIsUpdating extends AbstractEntityHook implements EntityIsChanging
{
/**
* @var File
*/
private $file;
public function __construct(File $file, array $attributes)
{
$this->file = $file;
parent::__construct($attributes);
}
/**
* @return File
*/
public function getFile()
{
return $this->file;
}
}
<?php
namespace Modules\Media\Events;
use Modules\Media\Entities\File;
class FileWasCreated
{
/**
* @var File
*/
public $file;
public function __construct(File $file)
{
$this->file = $file;
}
}
<?php
namespace Modules\Media\Events;
use Modules\Media\Entities\File;
class FileWasUpdated
{
/**
* @var File
*/
public $file;
public function __construct(File $file)
{
$this->file = $file;
}
}
......@@ -5,6 +5,10 @@ namespace Modules\Media\Repositories\Eloquent;
use Illuminate\Database\Eloquent\Collection;
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
use Modules\Media\Entities\File;
use Modules\Media\Events\FileIsCreating;
use Modules\Media\Events\FileIsUpdating;
use Modules\Media\Events\FileWasCreated;
use Modules\Media\Events\FileWasUpdated;
use Modules\Media\Helpers\FileHelper;
use Modules\Media\Repositories\FileRepository;
use Symfony\Component\HttpFoundation\File\UploadedFile;
......@@ -19,10 +23,13 @@ class EloquentFileRepository extends EloquentBaseRepository implements FileRepos
*/
public function update($file, $data)
{
$file->update($data);
event($event = new FileIsUpdating($file, $data));
$file->update($event->getAttributes());
$file->setTags(array_get($data, 'tags', []));
event(new FileWasUpdated($file));
return $file;
}
......@@ -41,14 +48,21 @@ class EloquentFileRepository extends EloquentBaseRepository implements FileRepos
$fileName = $this->getNewUniqueFilename($fileName);
}
return $this->model->create([
$data = [
'filename' => $fileName,
'path' => config('asgard.media.config.files-path') . "{$fileName}",
'extension' => substr(strrchr($fileName, "."), 1),
'extension' => substr(strrchr($fileName, '.'), 1),
'mimetype' => $file->getClientMimeType(),
'filesize' => $file->getFileInfo()->getSize(),
'folder_id' => 0,
]);
];
event($event = new FileIsCreating($data));
$file = $this->model->create($event->getAttributes());
event(new FileWasCreated($file));
return $file;
}
public function destroy($file)
......
......@@ -75,7 +75,7 @@
</dl>
@stop
@section('scripts')
@push('js-stack')
<script>
$( document ).ready(function() {
$(document).keypressAction({
......@@ -85,4 +85,4 @@
});
});
</script>
@stop
@endpush
......@@ -10,7 +10,7 @@
</ol>
@stop
@section('styles')
@push('css-stack')
<link href="{!! Module::asset('media:css/dropzone.css') !!}" rel="stylesheet" type="text/css" />
<style>
.dropzone {
......@@ -19,7 +19,7 @@
margin-bottom: 20px;
}
</style>
@stop
@endpush
@section('content')
<div class="row">
......@@ -91,7 +91,7 @@
@include('core::partials.delete-modal')
@stop
@section('scripts')
@push('js-stack')
<script src="{!! Module::asset('media:js/dropzone.js') !!}"></script>
<?php $config = config('asgard.media.config'); ?>
<script>
......@@ -117,4 +117,4 @@
});
});
</script>
@stop
@endpush
......@@ -2,13 +2,18 @@
namespace Modules\Media\Tests;
use Illuminate\Support\Facades\Event;
use Mockery;
use Modules\Media\Entities\File;
use Modules\Media\Events\FileIsCreating;
use Modules\Media\Events\FileIsUpdating;
use Modules\Media\Events\FileWasCreated;
use Modules\Media\Events\FileWasUpdated;
use Modules\Media\Repositories\FileRepository;
use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\HttpFoundation\File\UploadedFile;
class FileRepositoryTest extends MediaTestCase
class EloquentFileRepositoryTest extends MediaTestCase
{
/**
* @var FileRepository
......@@ -114,6 +119,99 @@ class FileRepositoryTest extends MediaTestCase
$this->assertCount(0, $this->file->all());
}
/** @test */
public function it_triggers_event_when_file_was_created()
{
Event::fake();
$file = $this->file->createFromFile(\Illuminate\Http\UploadedFile::fake()->image('myfile.jpg'));
Event::assertDispatched(FileWasCreated::class, function ($e) use ($file) {
return $e->file->id === $file->id;
});
}
/** @test */
public function it_triggers_event_when_file_is_creating()
{
Event::fake();
$file = $this->file->createFromFile(\Illuminate\Http\UploadedFile::fake()->image('myfile.jpg'));
Event::assertDispatched(FileIsCreating::class, function ($e) use ($file) {
return $e->getAttribute('filename') === $file->filename;
});
}
/** @test */
public function it_can_change_data_when_it_is_creating_event()
{
Event::listen(FileIsCreating::class, function (FileIsCreating $event) {
$event->setAttributes(['filename' => 'imabettername.jpg']);
});
$file = $this->file->createFromFile(\Illuminate\Http\UploadedFile::fake()->image('myfile.jpg'));
$this->assertEquals('imabettername.jpg', $file->filename);
}
/** @test */
public function it_triggers_event_when_file_was_updated()
{
Event::fake();
$file = $this->file->createFromFile(\Illuminate\Http\UploadedFile::fake()->image('myfile.jpg'));
$this->file->update($file, []);
Event::assertDispatched(FileWasUpdated::class, function ($e) use ($file) {
return $e->file->id === $file->id;
});
}
/** @test */
public function it_triggers_event_when_file_is_updating()
{
Event::fake();
$file = $this->file->createFromFile(\Illuminate\Http\UploadedFile::fake()->image('myfile.jpg'));
$this->file->update($file, [
'en' => [
'description' => 'My cool file!',
'alt_attribute' => 'My cool file!',
'keywords' => 'My cool file!',
]
]);
Event::assertDispatched(FileIsUpdating::class, function ($e) use ($file) {
return $e->getFile()->id === $file->id &&
$e->getAttribute('en.description') === 'My cool file!';
});
}
/** @test */
public function it_can_change_properties_before_update()
{
Event::listen(FileIsUpdating::class, function (FileIsUpdating $event) {
$event->setAttributes([
'filename' => 'bettername.jpg',
'en' => [
'description' => 'Hello World',
]
]);
});
$file = $this->file->createFromFile(\Illuminate\Http\UploadedFile::fake()->image('myfile.jpg'));
$this->file->update($file, [
'en' => [
'description' => 'My cool file!',
'alt_attribute' => 'My cool file!',
'keywords' => 'My cool file!',
]
]);
$this->assertEquals('bettername.jpg', $file->filename);
$this->assertEquals('Hello World', $file->translate('en')->description);
}
private function createFile($fileName = 'random/name.jpg')
{
return File::create([
......
url: https://github.com/AsgardCms/Platform
versions:
"2.5.0@unreleased":
added:
- <code>FileWasCreated</code> event
- <code>FileWasUpdated</code> event
- <code>FileIsCreating</code> hookable event
- <code>FileIsUpdating</code> hookable event
changed:
- Using the @push js stacks over the scripts section
- Using the @push css stacks over the styles section
"2.4.0":
added:
- new blade directive for thumbnails <code>@thumbnail('path', 'thumbnailName')</code>
......
......@@ -3,7 +3,7 @@
"alias": "media",
"description": "A media library, used throughout the CMS.",
"keywords": [],
"version": "2.0.0",
"version": "2.5.0",
"active": 1,
"order": 1,
"providers": [
......
<?php
namespace Modules\Menu\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
class MenuIsCreating extends AbstractEntityHook implements EntityIsChanging
{
}
<?php
namespace Modules\Menu\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
use Modules\Menu\Entities\Menu;
class MenuIsUpdating extends AbstractEntityHook implements EntityIsChanging
{
/**
* @var Menu
*/
private $menu;
public function __construct(Menu $menu, $attributes)
{
$this->menu = $menu;
parent::__construct($attributes);
}
/**
* @return Menu
*/
public function getMenu()
{
return $this->menu;
}
}
<?php
namespace Modules\Menu\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
class MenuItemIsCreating extends AbstractEntityHook implements EntityIsChanging
{
}
<?php
namespace Modules\Menu\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
use Modules\Menu\Entities\Menuitem;
class MenuItemIsUpdating extends AbstractEntityHook implements EntityIsChanging
{
/**
* @var Menuitem
*/
private $menuItem;
public function __construct(Menuitem $menuItem, $attributes)
{
parent::__construct($attributes);
$this->menuItem = $menuItem;
}
/**
* @return Menuitem
*/
public function getMenuItem()
{
return $this->menuItem;
}
}
<?php
namespace Modules\Menu\Events;
use Modules\Menu\Entities\Menuitem;
class MenuItemWasUpdated
{
/**
* @var Menuitem
*/
public $menuItem;
public function __construct(Menuitem $menuItem)
{
$this->menuItem = $menuItem;
}
}
<?php
namespace Modules\Menu\Events;
use Modules\Menu\Entities\Menu;
class MenuWasUpdated
{
/**
* @var Menu
*/
public $menu;
public function __construct(Menu $menu)
{
$this->menu = $menu;
}
}
......@@ -68,31 +68,25 @@ class MenuServiceProvider extends ServiceProvider
*/
private function registerBindings()
{
$this->app->bind(
'Modules\Menu\Repositories\MenuRepository',
function () {
$repository = new EloquentMenuRepository(new Menu());
$this->app->bind(MenuRepository::class, function () {
$repository = new EloquentMenuRepository(new Menu());
if (! config('app.cache')) {
return $repository;
}
return new CacheMenuDecorator($repository);
if (! config('app.cache')) {
return $repository;
}
);
$this->app->bind(
'Modules\Menu\Repositories\MenuItemRepository',
function () {
$repository = new EloquentMenuItemRepository(new Menuitem());
return new CacheMenuDecorator($repository);
});
if (! config('app.cache')) {
return $repository;
}
$this->app->bind(MenuItemRepository::class, function () {
$repository = new EloquentMenuItemRepository(new Menuitem());
return new CacheMenuItemDecorator($repository);
if (! config('app.cache')) {
return $repository;
}
);
return new CacheMenuItemDecorator($repository);
});
}
/**
......
......@@ -6,14 +6,18 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
use Modules\Menu\Events\MenuItemIsCreating;
use Modules\Menu\Events\MenuItemIsUpdating;
use Modules\Menu\Events\MenuItemWasCreated;
use Modules\Menu\Events\MenuItemWasUpdated;
use Modules\Menu\Repositories\MenuItemRepository;
class EloquentMenuItemRepository extends EloquentBaseRepository implements MenuItemRepository
{
public function create($data)
{
$menuItem = $this->model->create($data);
event($event = new MenuItemIsCreating($data));
$menuItem = $this->model->create($event->getAttributes());
event(new MenuItemWasCreated($menuItem));
......@@ -22,7 +26,10 @@ class EloquentMenuItemRepository extends EloquentBaseRepository implements MenuI
public function update($menuItem, $data)
{
$menuItem->update($data);
event($event = new MenuItemIsUpdating($menuItem, $data));
$menuItem->update($event->getAttributes());
event(new MenuItemWasUpdated($menuItem));
return $menuItem;
}
......
......@@ -5,14 +5,18 @@ namespace Modules\Menu\Repositories\Eloquent;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\App;
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
use Modules\Menu\Events\MenuIsCreating;
use Modules\Menu\Events\MenuIsUpdating;
use Modules\Menu\Events\MenuWasCreated;
use Modules\Menu\Events\MenuWasUpdated;
use Modules\Menu\Repositories\MenuRepository;
class EloquentMenuRepository extends EloquentBaseRepository implements MenuRepository
{
public function create($data)
{
$menu = $this->model->create($data);
event($event = new MenuIsCreating($data));
$menu = $this->model->create($event->getAttributes());
event(new MenuWasCreated($menu));
......@@ -21,7 +25,10 @@ class EloquentMenuRepository extends EloquentBaseRepository implements MenuRepos
public function update($menu, $data)
{
$menu->update($data);
event($event = new MenuIsUpdating($menu, $data));
$menu->update($event->getAttributes());
event(new MenuWasUpdated($menu));
return $menu;
}
......
......@@ -11,9 +11,6 @@
</ol>
@stop
@section('styles')
@stop
@section('content')
{!! Form::open(['route' => ['dashboard.menuitem.store', $menu->id], 'method' => 'post']) !!}
<div class="row">
......@@ -90,7 +87,7 @@
</dl>
@stop
@section('scripts')
@push('js-stack')
<script>
$( document ).ready(function() {
$(document).keypressAction({
......@@ -113,4 +110,4 @@ $( document ).ready(function() {
});
});
</script>
@stop
@endpush
......@@ -11,9 +11,6 @@
</ol>
@stop
@section('styles')
@stop
@section('content')
{!! Form::open(['route' => ['dashboard.menuitem.update', $menu->id, $menuItem->id], 'method' => 'put']) !!}
<div class="row">
......@@ -96,7 +93,7 @@
</dl>
@stop
@section('scripts')
@push('js-stack')
<script>
$( document ).ready(function() {
$(document).keypressAction({
......@@ -129,4 +126,4 @@ $( document ).ready(function() {
});
});
</script>
@stop
@endpush
......@@ -11,9 +11,6 @@
</ol>
@stop
@section('styles')
@stop
@section('content')
{!! Form::open(['route' => ['admin.menu.menu.store'], 'method' => 'post']) !!}
<div class="row">
......@@ -72,7 +69,7 @@
</dl>
@stop
@section('scripts')
@push('js-stack')
<script>
$( document ).ready(function() {
$(document).keypressAction({
......@@ -86,4 +83,4 @@ $( document ).ready(function() {
});
});
</script>
@stop
@endpush
......@@ -11,9 +11,9 @@
</ol>
@stop
@section('styles')
@push('css-stack')
<link href="{!! Module::asset('menu:css/nestable.css') !!}" rel="stylesheet" type="text/css" />
@stop
@endpush
@section('content')
{!! Form::open(['route' => ['admin.menu.menu.update', $menu->id], 'method' => 'put']) !!}
......@@ -89,7 +89,7 @@
</dl>
@stop
@section('scripts')
@push('js-stack')
<script>
$( document ).ready(function() {
$(document).keypressAction({
......@@ -160,4 +160,4 @@ $( document ).ready(function() {
});
});
</script>
@stop
@endpush
......@@ -107,7 +107,7 @@
</dl>
@stop
@section('scripts')
@push('js-stack')
<?php $locale = App::getLocale(); ?>
<script type="text/javascript">
$( document ).ready(function() {
......@@ -132,4 +132,4 @@
});
});
</script>
@stop
@endpush
......@@ -9,10 +9,13 @@ use Maatwebsite\Sidebar\SidebarServiceProvider;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
use Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider;
use Modules\Core\Providers\CoreServiceProvider;
use Modules\Menu\Providers\EventServiceProvider;
use Modules\Menu\Providers\MenuServiceProvider;
use Modules\Menu\Repositories\MenuItemRepository;
use Modules\Menu\Repositories\MenuRepository;
use Modules\Page\Providers\PageServiceProvider;
use Modules\Setting\Providers\SettingServiceProvider;
use Modules\Setting\Repositories\SettingRepository;
use Modules\Tag\Providers\TagServiceProvider;
use Nwidart\Modules\LaravelModulesServiceProvider;
use Orchestra\Testbench\TestCase;
......@@ -39,6 +42,9 @@ abstract class BaseMenuTest extends TestCase
$this->menu = app(MenuRepository::class);
$this->menuItem = app(MenuItemRepository::class);
app(SettingRepository::class)->createOrUpdate([
'core::locales' => ['en', 'fr',]
]);
}
protected function getPackageProviders($app)
......@@ -48,6 +54,8 @@ abstract class BaseMenuTest extends TestCase
CoreServiceProvider::class,
TagServiceProvider::class,
PageServiceProvider::class,
SettingServiceProvider::class,
EventServiceProvider::class,
MenuServiceProvider::class,
LaravelLocalizationServiceProvider::class,
SidebarServiceProvider::class,
......@@ -96,6 +104,10 @@ abstract class BaseMenuTest extends TestCase
'--database' => 'sqlite',
'--path' => 'Modules/Tag/Database/Migrations',
]);
$this->artisan('migrate', [
'--database' => 'sqlite',
'--path' => 'Modules/Setting/Database/Migrations',
]);
}
public function createMenu($name, $title)
......
......@@ -2,6 +2,12 @@
namespace Modules\Menu\Tests;
use Illuminate\Support\Facades\Event;
use Modules\Menu\Events\MenuItemIsCreating;
use Modules\Menu\Events\MenuItemIsUpdating;
use Modules\Menu\Events\MenuItemWasCreated;
use Modules\Menu\Events\MenuItemWasUpdated;
class EloquentMenuItemRepositoryTest extends BaseMenuTest
{
public function setUp()
......@@ -53,8 +59,105 @@ class EloquentMenuItemRepositoryTest extends BaseMenuTest
$secondaryItem2 = $this->createMenuItemForMenu($menu2->id, 1);
$secondaryItem3 = $this->createMenuItemForMenu($menu2->id, 3);
$this->assertEquals(6, $this->menuItem->all()->count());
$this->assertEquals(8, $this->menuItem->all()->count());
$this->menuItem->destroy($item2);
$this->assertEquals(5, $this->menuItem->all()->count());
$this->assertEquals(7, $this->menuItem->all()->count());
}
/** @test */
public function it_triggers_event_when_menu_item_was_created()
{
Event::fake();
$menu = $this->createMenu('main', 'Main Menu');
$item1 = $this->createMenuItemForMenu($menu->id, 0);
Event::assertDispatched(MenuItemWasCreated::class, function ($e) use ($item1) {
return $e->menuItem->id === $item1->id;
});
}
/** @test */
public function it_triggers_event_when_menu_item_is_creating()
{
Event::fake();
$menu = $this->createMenu('main', 'Main Menu');
$item1 = $this->createMenuItemForMenu($menu->id, 0);
Event::assertDispatched(MenuItemIsCreating::class, function ($e) use ($item1) {
return $e->getAttribute('target') === $item1->target;
});
}
/** @test */
public function it_can_change_data_when_it_is_creating_event()
{
Event::listen(MenuItemIsCreating::class, function (MenuItemIsCreating $event) {
$event->setAttributes([
'target' => '_blank',
'en' => [
'title' => 'My Title',
],
]);
});
$menu = $this->createMenu('main', 'Main Menu');
$item = $this->createMenuItemForMenu($menu->id, 0);
$this->assertEquals('_blank', $item->target);
$this->assertEquals('My Title', $item->translate('en')->title);
}
/** @test */
public function it_triggers_event_when_menu_item_is_updated()
{
Event::fake();
$menu = $this->createMenu('main', 'Main Menu');
$item1 = $this->createMenuItemForMenu($menu->id, 0);
$this->menuItem->update($item1, []);
Event::assertDispatched(MenuItemWasUpdated::class, function ($e) use ($item1) {
return $e->menuItem->id === $item1->id;
});
}
/** @test */
public function it_triggers_event_when_menu_item_is_updating()
{
Event::fake();
$menu = $this->createMenu('main', 'Main Menu');
$item1 = $this->createMenuItemForMenu($menu->id, 0);
$this->menuItem->update($item1, []);
Event::assertDispatched(MenuItemIsUpdating::class, function ($e) use ($item1) {
return $e->getMenuItem()->id === $item1->id;
});
}
/** @test */
public function it_can_change_data_before_updating_menu_item()
{
Event::listen(MenuItemIsUpdating::class, function (MenuItemIsUpdating $event) {
$event->setAttributes([
'target' => '_blank',
'en' => [
'title' => 'My Title',
],
]);
});
$menu = $this->createMenu('main', 'Main Menu');
$item1 = $this->createMenuItemForMenu($menu->id, 0);
$this->menuItem->update($item1, [
'en' => ['title' => 'This one!'],
]);
$this->assertEquals('My Title', $item1->translate('en')->title);
}
}
<?php
namespace Modules\Menu\Tests;
use Illuminate\Support\Facades\Event;
use Modules\Menu\Events\MenuIsCreating;
use Modules\Menu\Events\MenuIsUpdating;
use Modules\Menu\Events\MenuWasCreated;
use Modules\Menu\Events\MenuWasUpdated;
class EloquentMenuRepositoryTest extends BaseMenuTest
{
/** @test */
public function it_creates_menu()
{
$menu = $this->createMenu('main', 'Main Menu');
$this->assertEquals(1, $this->menu->find($menu->id)->count());
$this->assertEquals($menu->name, $this->menu->find($menu->id)->name);
}
/** @test */
public function it_triggers_event_when_menu_was_created()
{
Event::fake();
$menu = $this->createMenu('main', 'Main Menu');
Event::assertDispatched(MenuWasCreated::class, function ($e) use ($menu) {
return $e->menu->id === $menu->id;
});
}
/** @test */
public function it_triggers_event_when_menu_is_creating()
{
Event::fake();
$menu = $this->createMenu('main', 'Main Menu');
Event::assertDispatched(MenuIsCreating::class, function ($e) use ($menu) {
return $e->getAttribute('name') === $menu->name;
});
}
/** @test */
public function it_can_change_data_when_it_is_creating_event()
{
Event::listen(MenuIsCreating::class, function (MenuIsCreating $event) {
$event->setAttributes(['name' => 'MAIN']);
});
$menu = $this->createMenu('main', 'Main Menu');
$this->assertEquals('MAIN', $menu->name);
}
/** @test */
public function it_triggers_event_when_menu_item_was_updated()
{
Event::fake();
$menu = $this->createMenu('main', 'Main Menu');
$this->menu->update($menu, []);
Event::assertDispatched(MenuWasUpdated::class, function ($e) use ($menu) {
return $e->menu->id === $menu->id;
});
}
/** @test */
public function it_triggers_event_when_menu_is_updating()
{
Event::fake();
$menu = $this->createMenu('main', 'Main Menu');
$this->menu->update($menu, []);
Event::assertDispatched(MenuIsUpdating::class, function ($e) use ($menu) {
return $e->getMenu()->id === $menu->id;
});
}
/** @test */
public function it_can_change_attributes_before_update()
{
Event::listen(MenuIsUpdating::class, function (MenuIsUpdating $event) {
$event->setAttributes(['name' => 'MAIN']);
});
$menu = $this->createMenu('main', 'Main Menu');
$this->menu->update($menu, ['name' => 'better-one']);
$this->assertEquals('MAIN', $menu->name);
}
/** @test */
public function it_should_create_root_item_when_creating_new_menu()
{
$menu = $this->createMenu('main', 'Main Menu');
$items = $this->menuItem->allRootsForMenu($menu->id);
$this->assertCount(1, $items);
}
}
......@@ -2,6 +2,7 @@
namespace Modules\Menu\Tests;
use Illuminate\Support\Facades\Event;
use Modules\Menu\Services\MenuItemUriGenerator;
use Modules\Page\Repositories\PageRepository;
......@@ -42,6 +43,7 @@ class MenuItemUriGeneratorTest extends BaseMenuTest
/** @test */
public function it_generates_uri_with_the_parents_slug()
{
Event::fake();
$this->page->create([
'is_home' => 1,
'template' => 'default',
......@@ -80,6 +82,7 @@ class MenuItemUriGeneratorTest extends BaseMenuTest
/** @test */
public function it_generates_uri_with_multiple_parents()
{
Event::fake();
$this->page->create([
'is_home' => 1,
'template' => 'default',
......@@ -140,6 +143,7 @@ class MenuItemUriGeneratorTest extends BaseMenuTest
/** @test */
public function it_generates_a_uri_if_parent_isnt_a_page()
{
Event::fake();
$this->page->create([
'is_home' => 0,
'template' => 'default',
......
<?php
namespace Modules\Menu\Tests;
class MenuRepositoryTest extends BaseMenuTest
{
/** @test */
public function it_creates_menu()
{
$menu = $this->createMenu('main', 'Main Menu');
$this->assertEquals(1, $this->menu->find($menu->id)->count());
$this->assertEquals($menu->name, $this->menu->find($menu->id)->name);
}
public function it_should_create_root_item_when_creating_new_menu()
{
$menu = $this->createMenu('main', 'Main Menu');
$items = $this->menuItem->allRootsForMenu($menu->id);
}
}
url: https://github.com/AsgardCms/Platform
versions:
"2.5.0@unreleased":
added:
- Trigger event before a menu is created (<code>MenuIsCreating</code>) allow data to be changed
- Trigger event before a menu is updated (<code>MenuIsUpdating</code>) allow data to be changed
- Trigger event before a menu item is created (<code>MenuItemIsCreating</code>) allow data to be changed
- Trigger event before a menu item is updated (<code>MenuItemIsUpdating</code>) allow data to be changed
changed:
- Using the @push js stacks over the scripts section
- Using the @push css stacks over the styles section
"2.2.0":
changed:
- Only registering the menus for the frontend part.
......
......@@ -4,7 +4,7 @@
"description": "Managing menus.",
"keywords": [
],
"version": "2.0.0",
"version": "2.5.0",
"active": 1,
"order": 1,
"providers": [
......
......@@ -3,6 +3,7 @@
namespace Modules\Page\Entities;
use Illuminate\Database\Eloquent\Model;
use Modules\Page\Events\ContentIsRendering;
class PageTranslation extends Model
{
......@@ -20,4 +21,11 @@ class PageTranslation extends Model
'og_image',
'og_type',
];
public function getBodyAttribute($body)
{
event($event = new ContentIsRendering($body));
return $event->getBody();
}
}
<?php
namespace Modules\Page\Events;
class ContentIsRendering
{
/**
* @var string The body of the page to render
*/
private $body;
private $original;
public function __construct($body)
{
$this->body = $body;
$this->original = $body;
}
/**
* @return string
*/
public function getBody()
{
return $this->body;
}
/**
* @param string $body
*/
public function setBody($body)
{
$this->body = $body;
}
/**
* @return mixed
*/
public function getOriginal()
{
return $this->original;
}
public function __toString()
{
return $this->getBody();
}
}
<?php
namespace Modules\Page\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
class PageIsCreating extends AbstractEntityHook implements EntityIsChanging
{
}
<?php
namespace Modules\Page\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
use Modules\Page\Entities\Page;
class PageIsUpdating extends AbstractEntityHook implements EntityIsChanging
{
/**
* @var Page
*/
private $page;
public function __construct(Page $page, array $attributes)
{
$this->page = $page;
parent::__construct($attributes);
}
/**
* @return Page
*/
public function getPage()
{
return $this->page;
}
}
......@@ -20,7 +20,6 @@ class PageController extends AdminBaseController
parent::__construct();
$this->page = $page;
$this->assetPipeline->requireCss('icheck.blue.css');
}
public function index()
......@@ -37,8 +36,6 @@ class PageController extends AdminBaseController
*/
public function create()
{
$this->assetPipeline->requireJs('ckeditor.js');
return view('page::admin.create');
}
......@@ -64,8 +61,6 @@ class PageController extends AdminBaseController
*/
public function edit(Page $page)
{
$this->assetPipeline->requireJs('ckeditor.js');
return view('page::admin.edit', compact('page'));
}
......
......@@ -4,10 +4,12 @@ namespace Modules\Page\Providers;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;
use Modules\Core\Events\CollectingAssets;
use Modules\Core\Traits\CanPublishConfiguration;
use Modules\Page\Entities\Page;
use Modules\Page\Repositories\Cache\CachePageDecorator;
use Modules\Page\Repositories\Eloquent\EloquentPageRepository;
use Modules\Page\Repositories\PageRepository;
use Modules\Page\Services\FinderService;
use Modules\Tag\Repositories\TagManager;
......@@ -38,6 +40,8 @@ class PageServiceProvider extends ServiceProvider
$this->app[TagManager::class]->registerNamespace(new Page());
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
$this->handleAssets();
}
/**
......@@ -56,17 +60,27 @@ class PageServiceProvider extends ServiceProvider
return new FinderService();
});
$this->app->bind(
'Modules\Page\Repositories\PageRepository',
function () {
$repository = new EloquentPageRepository(new Page());
$this->app->bind(PageRepository::class, function () {
$repository = new EloquentPageRepository(new Page());
if (! Config::get('app.cache')) {
return $repository;
}
if (! Config::get('app.cache')) {
return $repository;
}
return new CachePageDecorator($repository);
});
}
return new CachePageDecorator($repository);
/**
* Require iCheck on edit and create pages
*/
private function handleAssets()
{
$this->app['events']->listen(CollectingAssets::class, function (CollectingAssets $event) {
if ($event->onRoutes(['*page*create', '*page*edit'])) {
$event->requireCss('icheck.blue.css');
$event->requireJs('icheck.js');
}
);
});
}
}
......@@ -4,6 +4,8 @@ namespace Modules\Page\Repositories\Eloquent;
use Illuminate\Database\Eloquent\Builder;
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
use Modules\Page\Events\PageIsCreating;
use Modules\Page\Events\PageIsUpdating;
use Modules\Page\Events\PageWasCreated;
use Modules\Page\Events\PageWasDeleted;
use Modules\Page\Events\PageWasUpdated;
......@@ -38,7 +40,9 @@ class EloquentPageRepository extends EloquentBaseRepository implements PageRepos
if (array_get($data, 'is_home') === '1') {
$this->removeOtherHomepage();
}
$page = $this->model->create($data);
event($event = new PageIsCreating($data));
$page = $this->model->create($event->getAttributes());
event(new PageWasCreated($page->id, $data));
......@@ -57,7 +61,9 @@ class EloquentPageRepository extends EloquentBaseRepository implements PageRepos
if (array_get($data, 'is_home') === '1') {
$this->removeOtherHomepage($model->id);
}
$model->update($data);
event($event = new PageIsUpdating($model, $data));
$model->update($event->getAttributes());
event(new PageWasUpdated($model->id, $data));
......
......@@ -11,13 +11,13 @@
</ol>
@stop
@section('styles')
@push('css-stack')
<style>
.checkbox label {
padding-left: 0;
}
</style>
@stop
@endpush
@section('content')
{!! Form::open(['route' => ['admin.page.page.store'], 'method' => 'post']) !!}
......@@ -87,7 +87,7 @@
</dl>
@stop
@section('scripts')
@push('js-stack')
<script>
$( document ).ready(function() {
$(document).keypressAction({
......@@ -101,4 +101,4 @@
});
});
</script>
@stop
@endpush
......@@ -11,13 +11,13 @@
</ol>
@stop
@section('styles')
@push('css-stack')
<style>
.checkbox label {
padding-left: 0;
}
</style>
@stop
@endpush
@section('content')
{!! Form::open(['route' => ['admin.page.page.update', $page->id], 'method' => 'put']) !!}
......@@ -94,7 +94,7 @@
</dl>
@stop
@section('scripts')
@push('js-stack')
<script>
$( document ).ready(function() {
$(document).keypressAction({
......@@ -108,4 +108,4 @@
});
});
</script>
@stop
@endpush
......@@ -98,7 +98,7 @@
</dl>
@stop
@section('scripts')
@push('js-stack')
<?php $locale = App::getLocale(); ?>
<script type="text/javascript">
$( document ).ready(function() {
......@@ -123,4 +123,4 @@
});
});
</script>
@stop
@endpush
......@@ -10,11 +10,9 @@
{!! Form::text("{$lang}[slug]", old("{$lang}.slug"), ['class' => 'form-control slug', 'data-slug' => 'target', 'placeholder' => trans('page::pages.form.slug')]) !!}
{!! $errors->first("{$lang}.slug", '<span class="help-block">:message</span>') !!}
</div>
<div class='{{ $errors->has("{$lang}.body") ? ' has-error' : '' }}'>
{!! Form::label("{$lang}[body]", trans('page::pages.form.body')) !!}
<textarea class="ckeditor" name="{{$lang}}[body]" rows="10" cols="80">{{ old("{$lang}.body") }}</textarea>
{!! $errors->first("{$lang}.body", '<span class="help-block">:message</span>') !!}
</div>
@editor('body', trans('page::pages.form.body'), old("{$lang}.body"), $lang)
<?php if (config('asgard.page.config.partials.translatable.create') !== []): ?>
<?php foreach (config('asgard.page.config.partials.translatable.create') as $partial): ?>
@include($partial)
......
......@@ -12,14 +12,10 @@
{!! Form::text("{$lang}[slug]", old("{$lang}.slug", $old), ['class' => 'form-control slug', 'data-slug' => 'target', 'placeholder' => trans('page::pages.form.slug')]) !!}
{!! $errors->first("{$lang}.slug", '<span class="help-block">:message</span>') !!}
</div>
<div class='{{ $errors->has("{$lang}.body") ? ' has-error' : '' }}'>
{!! Form::label("{$lang}[body]", trans('page::pages.form.body')) !!}
<?php $old = $page->hasTranslation($lang) ? $page->translate($lang)->body : '' ?>
<textarea class="ckeditor" name="{{$lang}}[body]" rows="10" cols="80">
{!! old("$lang.body", $old) !!}
</textarea>
{!! $errors->first("{$lang}.body", '<span class="help-block">:message</span>') !!}
</div>
<?php $old = $page->hasTranslation($lang) ? $page->translate($lang)->body : '' ?>
@editor('body', trans('page::pages.form.body'), old("$lang.body", $old), $lang)
<?php if (config('asgard.page.config.partials.translatable.edit') !== []): ?>
<?php foreach (config('asgard.page.config.partials.translatable.edit') as $partial): ?>
@include($partial)
......
<?php
namespace Modules\Page\Tests;
use Illuminate\Support\Facades\Event;
use Modules\Page\Events\ContentIsRendering;
class ContentIsRenderingTest extends BasePageTest
{
/** @test */
public function it_can_change_final_content()
{
Event::listen(ContentIsRendering::class, function (ContentIsRendering $event) {
$event->setBody('<strong>' . $event->getOriginal() . '</strong>');
});
$page = $this->createPage();
$this->assertEquals('<strong>My Page Body</strong>', $page->body);
}
/** @test */
public function it_doesnt_alter_content_if_no_listeners()
{
$page = $this->createPage();
$this->assertEquals('My Page Body', $page->body);
}
private function createPage()
{
return $this->page->create([
'is_home' => '1',
'template' => 'default',
'en' => [
'title' => 'My Other Page',
'slug' => 'my-other-page',
'body' => 'My Page Body',
],
]);
}
}
......@@ -3,11 +3,13 @@
namespace Modules\Page\Tests;
use Illuminate\Support\Facades\Event;
use Modules\Page\Events\PageIsCreating;
use Modules\Page\Events\PageIsUpdating;
use Modules\Page\Events\PageWasCreated;
use Modules\Page\Events\PageWasDeleted;
use Modules\Page\Events\PageWasUpdated;
class PagesTest extends BasePageTest
class EloquentPageRepositoryTest extends BasePageTest
{
/** @test */
public function it_makes_page_as_homepage()
......@@ -93,6 +95,57 @@ class PagesTest extends BasePageTest
});
}
/** @test */
public function it_triggers_an_event_when_page_is_creating()
{
Event::fake();
$page = $this->createPage();
Event::assertDispatched(PageIsCreating::class, function ($e) use ($page) {
return $e->getAttribute('template') === $page->template;
});
}
/** @test */
public function it_can_change_page_data_before_creating_page()
{
Event::listen(PageIsCreating::class, function (PageIsCreating $event) {
$event->setAttributes(['template' => 'better-tpl']);
});
$page = $this->createPage();
$this->assertEquals('better-tpl', $page->template);
}
/** @test */
public function it_triggers_an_event_when_page_is_updating()
{
Event::fake();
$page = $this->createPage();
$this->page->update($page, ['en' => ['title' => 'Better!']]);
Event::assertDispatched(PageIsUpdating::class, function ($e) use ($page) {
return $e->getPage()->id === $page->id;
});
}
/** @test */
public function it_can_change_page_data_before_updating_page()
{
Event::listen(PageIsUpdating::class, function (PageIsUpdating $event) {
$event->setAttributes(['template' => 'better-tpl']);
});
$page = $this->createPage();
$this->page->update($page, ['template' => 'my-template', 'en' => ['title' => 'Better!']]);
$this->assertEquals('better-tpl', $page->template);
}
/** @test */
public function it_triggers_event_when_page_was_updated()
{
......@@ -135,4 +188,17 @@ class PagesTest extends BasePageTest
return $e->page->id === $page->id;
});
}
private function createPage()
{
return $this->page->create([
'is_home' => '1',
'template' => 'default',
'en' => [
'title' => 'My Other Page',
'slug' => 'my-other-page',
'body' => 'My Page Body',
],
]);
}
}
url: https://github.com/AsgardCms/Platform
versions:
"2.5.0@unreleased":
added:
- Trigger event before a page is created (<code>PageIsCreating</code>) allow data to be changed
- Trigger event before a page is updated (<code>PageIsUpdating</code>) allow data to be changed
changed:
- Requiring the editor assets via hook
- Making editor textarea dynamic
- Using the new <code>@editor</code> blade directive for the body textarea field
- Remove the ckeditor inclusion on create/edit view stubs
- Using the @push js stacks over the scripts section
- Using the @push css stacks over the styles section
"2.2.0":
added:
- Testing event trigger on page deletion
......
......@@ -3,7 +3,7 @@
"alias": "page",
"description": "Managing pages.",
"keywords": [],
"version": "2.0.0",
"version": "2.5.0",
"active": 1,
"order": 9999,
"providers": [
......
<?php
namespace Modules\Setting\Events;
class SettingIsCreating
{
private $settingName;
private $settingValues;
private $original;
public function __construct($settingName, $settingValues)
{
$this->settingName = $settingName;
$this->settingValues = $settingValues;
$this->original = $settingValues;
}
/**
* @return mixed
*/
public function getSettingName()
{
return $this->settingName;
}
/**
* @return mixed
*/
public function getSettingValues()
{
return $this->settingValues;
}
/**
* @param mixed $settingValues
*/
public function setSettingValues($settingValues)
{
$this->settingValues = $settingValues;
}
/**
* @return mixed
*/
public function getOriginal()
{
return $this->original;
}
}
<?php
namespace Modules\Setting\Events;
use Modules\Setting\Entities\Setting;
class SettingIsUpdating
{
private $settingName;
private $settingValues;
private $original;
/**
* @var Setting
*/
private $setting;
public function __construct(Setting $setting, $settingName, $settingValues)
{
$this->settingName = $settingName;
$this->settingValues = $settingValues;
$this->original = $settingValues;
$this->setting = $setting;
}
/**
* @return mixed
*/
public function getSettingName()
{
return $this->settingName;
}
/**
* @return mixed
*/
public function getSettingValues()
{
return $this->settingValues;
}
/**
* @param mixed $settingValues
*/
public function setSettingValues($settingValues)
{
$this->settingValues = $settingValues;
}
/**
* @return mixed
*/
public function getOriginal()
{
return $this->original;
}
/**
* @return Setting
*/
public function getSetting()
{
return $this->setting;
}
}
......@@ -2,30 +2,17 @@
namespace Modules\Setting\Events;
use Modules\Setting\Entities\Setting;
class SettingWasCreated
{
/**
* @var bool
*/
public $isTranslatable;
/**
* @var string Setting name
* @var Setting
*/
public $name;
/**
* @var string|array
*/
public $values;
public $setting;
/**
* @param $name
* @param $isTranslatable
* @param $values
*/
public function __construct($name, $isTranslatable, $values)
public function __construct(Setting $setting)
{
$this->isTranslatable = $isTranslatable;
$this->name = $name;
$this->values = $values;
$this->setting = $setting;
}
}
......@@ -2,30 +2,17 @@
namespace Modules\Setting\Events;
use Modules\Setting\Entities\Setting;
class SettingWasUpdated
{
/**
* @var string The setting name
*/
public $name;
/**
* @var string|array
*/
public $values;
/**
* @var string|array Containing the old values
*/
public $oldValues;
/**
* @var bool
* @var Setting
*/
public $isTranslatable;
public $setting;
public function __construct($name, $isTranslatable, $values, $oldValues = null)
public function __construct(Setting $setting)
{
$this->name = $name;
$this->isTranslatable = $isTranslatable;
$this->values = $values;
$this->oldValues = $oldValues;
$this->setting = $setting;
}
}
......@@ -4,6 +4,9 @@ namespace Modules\Setting\Repositories\Eloquent;
use Illuminate\Support\Facades\Config;
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
use Modules\Setting\Entities\Setting;
use Modules\Setting\Events\SettingIsCreating;
use Modules\Setting\Events\SettingIsUpdating;
use Modules\Setting\Events\SettingWasCreated;
use Modules\Setting\Events\SettingWasUpdated;
use Modules\Setting\Repositories\SettingRepository;
......@@ -77,23 +80,28 @@ class EloquentSettingRepository extends EloquentBaseRepository implements Settin
* Create a setting with the given name
* @param string $settingName
* @param $settingValues
* @return Setting
*/
private function createForName($settingName, $settingValues)
{
event($event = new SettingIsCreating($settingName, $settingValues));
$setting = new $this->model();
$setting->name = $settingName;
if ($this->isTranslatableSetting($settingName)) {
$setting->isTranslatable = true;
$this->setTranslatedAttributes($settingValues, $setting);
event(new SettingWasCreated($settingName, true, $settingValues));
$this->setTranslatedAttributes($event->getSettingValues(), $setting);
} else {
$setting->isTranslatable = false;
$setting->plainValue = $this->getSettingPlainValue($settingValues);
event(new SettingWasCreated($settingName, false, $settingValues));
$setting->plainValue = $this->getSettingPlainValue($event->getSettingValues());
}
return $setting->save();
$setting->save();
event(new SettingWasCreated($setting));
return $setting;
}
/**
......@@ -104,17 +112,18 @@ class EloquentSettingRepository extends EloquentBaseRepository implements Settin
private function updateSetting($setting, $settingValues)
{
$name = $setting->name;
event($event = new SettingIsUpdating($setting, $name, $settingValues));
if ($this->isTranslatableSetting($name)) {
$this->setTranslatedAttributes($settingValues, $setting);
event(new SettingWasUpdated($name, true, $settingValues));
$this->setTranslatedAttributes($event->getSettingValues(), $setting);
} else {
$oldValues = $setting->plainValue;
$setting->plainValue = $this->getSettingPlainValue($settingValues);
event(new SettingWasUpdated($name, false, $settingValues, $oldValues));
$setting->plainValue = $this->getSettingPlainValue($event->getSettingValues());
}
$setting->save();
event(new SettingWasUpdated($setting));
return $setting->save();
return $setting;
}
/**
......
......@@ -79,7 +79,7 @@
{!! Form::close() !!}
@stop
@section('scripts')
@push('js-stack')
<script>
$( document ).ready(function() {
$('input[type="checkbox"].flat-blue, input[type="radio"].flat-blue').iCheck({
......@@ -98,4 +98,4 @@ $( document ).ready(function() {
});
});
</script>
@stop
@endpush
......@@ -2,6 +2,12 @@
namespace Modules\Setting\Tests;
use Illuminate\Support\Facades\Event;
use Modules\Setting\Events\SettingIsCreating;
use Modules\Setting\Events\SettingIsUpdating;
use Modules\Setting\Events\SettingWasCreated;
use Modules\Setting\Events\SettingWasUpdated;
class EloquentSettingRepositoryTest extends BaseSettingTest
{
public function setUp()
......@@ -111,4 +117,147 @@ class EloquentSettingRepositoryTest extends BaseSettingTest
$this->assertEquals('core::locales', $setting->name);
$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';
});
}
/** @test */
public function it_triggers_event_when_setting_is_creating()
{
Event::fake();
$data = [
'core::template' => 'asgard',
'core::site-name' => [
'en' => 'AsgardCMS_en',
'fr' => 'AsgardCMS_fr',
],
];
$this->settingRepository->createOrUpdate($data);
Event::assertDispatched(SettingIsCreating::class, function (SettingIsCreating $e) {
return $e->getSettingName() === 'core::template' && $e->getSettingValues() === 'asgard';
});
}
/** @test */
public function it_can_change_data_when_it_is_creating_event()
{
Event::listen(SettingIsCreating::class, function (SettingIsCreating $event) {
if ($event->getSettingName() === 'core::template') {
$event->setSettingValues('my-template');
}
if ($event->getSettingName() === 'core::site-name') {
$event->setSettingValues([
'en' => 'English AsgardCMS'
]);
}
});
$data = [
'core::template' => 'asgard',
'blog::posts' => 10,
'core::site-name' => [
'en' => 'AsgardCMS_en',
'fr' => 'AsgardCMS_fr',
],
];
$this->settingRepository->createOrUpdate($data);
$this->assertEquals('my-template', $this->settingRepository->findByName('core::template')->plainValue);
$this->assertEquals(10, $this->settingRepository->findByName('blog::posts')->plainValue);
$this->assertEquals('English AsgardCMS', $this->settingRepository->findByName('core::site-name')->translate('en')->value);
}
/** @test */
public function it_triggers_event_when_setting_was_updated()
{
Event::fake();
$data = [
'core::template' => 'asgard',
'core::site-name' => [
'en' => 'AsgardCMS_en',
'fr' => 'AsgardCMS_fr',
],
];
$this->settingRepository->createOrUpdate($data);
$this->settingRepository->createOrUpdate(['core::template' => 'flatly']);
Event::assertDispatched(SettingWasUpdated::class, function ($e) {
return $e->setting->name === 'core::template';
});
}
/** @test */
public function it_triggers_event_when_setting_is_updating()
{
Event::fake();
$data = [
'core::template' => 'asgard',
'core::site-name' => [
'en' => 'AsgardCMS_en',
'fr' => 'AsgardCMS_fr',
],
];
$this->settingRepository->createOrUpdate($data);
$this->settingRepository->createOrUpdate(['core::template' => 'flatly']);
Event::assertDispatched(SettingIsUpdating::class, function ($e) {
return $e->getSetting()->name === 'core::template';
});
}
/** @test */
public function it_can_change_date_when_updating_setting()
{
Event::listen(SettingIsUpdating::class, function (SettingIsUpdating $event) {
if ($event->getSettingName() === 'core::template') {
$event->setSettingValues('my-template');
}
if ($event->getSettingName() === 'core::site-name') {
$event->setSettingValues([
'en' => 'English AsgardCMS'
]);
}
});
$data = [
'core::template' => 'asgard',
'blog::posts' => 10,
'core::site-name' => [
'en' => 'AsgardCMS_en',
'fr' => 'AsgardCMS_fr',
],
];
$this->settingRepository->createOrUpdate($data);
$this->settingRepository->createOrUpdate([
'core::template' => 'flatly',
'core::site-name' => [
'en' => 'The AsgardCMS_en',
'fr' => 'The AsgardCMS_fr',
],
]);
$this->assertEquals('my-template', $this->settingRepository->findByName('core::template')->plainValue);
$this->assertEquals(10, $this->settingRepository->findByName('blog::posts')->plainValue);
$this->assertEquals('English AsgardCMS', $this->settingRepository->findByName('core::site-name')->translate('en')->value);
}
}
url: https://github.com/AsgardCms/Platform
versions:
"2.5.0@unreleased":
changed:
- Normalise the setting was created event
- Normalise the setting was updated event
- Trigger <code>SettingIsCreating</code> hook
- Trigger <code>SettingIsUpdating</code> hook
changed:
- Using the @push js stacks over the scripts section
- Using the @push css stacks over the styles section
"2.0.0":
added:
- Laravel 5.2 compatibility
......
......@@ -6,7 +6,7 @@
"asgardcms",
"settings"
],
"version": "2.0.0",
"version": "2.5.0",
"active": 1,
"order": 1,
"providers": [
......
<?php
namespace Modules\Tag\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
class TagIsCreating extends AbstractEntityHook implements EntityIsChanging
{
}
<?php
namespace Modules\Tag\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
use Modules\Tag\Entities\Tag;
class TagIsUpdating extends AbstractEntityHook implements EntityIsChanging
{
/**
* @var Tag
*/
private $tag;
public function __construct(Tag $tag, $attributes)
{
$this->tag = $tag;
parent::__construct($attributes);
}
/**
* @return Tag
*/
public function getTag()
{
return $this->tag;
}
}
<?php
namespace Modules\Tag\Events;
use Modules\Tag\Entities\Tag;
class TagWasCreated
{
/**
* @var Tag
*/
public $tag;
public function __construct(Tag $tag)
{
$this->tag = $tag;
}
}
<?php
namespace Modules\Tag\Events;
use Modules\Tag\Entities\Tag;
class TagWasUpdated
{
/**
* @var Tag
*/
public $tag;
public function __construct(Tag $tag)
{
$this->tag = $tag;
}
}
......@@ -3,6 +3,10 @@
namespace Modules\Tag\Repositories\Eloquent;
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
use Modules\Tag\Events\TagIsCreating;
use Modules\Tag\Events\TagIsUpdating;
use Modules\Tag\Events\TagWasCreated;
use Modules\Tag\Events\TagWasUpdated;
use Modules\Tag\Repositories\TagRepository;
class EloquentTagRepository extends EloquentBaseRepository implements TagRepository
......@@ -16,4 +20,25 @@ class EloquentTagRepository extends EloquentBaseRepository implements TagReposit
{
return $this->model->with('translations')->where('namespace', $namespace)->get();
}
public function create($data)
{
event($event = new TagIsCreating($data));
$tag = $this->model->create($event->getAttributes());
event(new TagWasCreated($tag));
return $tag;
}
public function update($tag, $data)
{
event($event = new TagIsUpdating($tag, $data));
$tag->update($event->getAttributes());
event(new TagWasUpdated($tag));
return $tag;
}
}
......@@ -11,9 +11,6 @@
</ol>
@stop
@section('styles')
@stop
@section('content')
{!! Form::open(['route' => ['admin.tag.tag.store'], 'method' => 'post']) !!}
<div class="row">
......@@ -61,7 +58,7 @@
</dl>
@stop
@section('scripts')
@push('js-stack')
<script type="text/javascript">
$( document ).ready(function() {
$('.selectize').selectize();
......@@ -80,4 +77,4 @@
});
});
</script>
@stop
@endpush
......@@ -11,10 +11,6 @@
</ol>
@stop
@section('styles')
{!! Theme::script('js/vendor/ckeditor/ckeditor.js') !!}
@stop
@section('content')
{!! Form::open(['route' => ['admin.tag.tag.update', $tag->id], 'method' => 'put']) !!}
<div class="row">
......@@ -62,7 +58,7 @@
</dl>
@stop
@section('scripts')
@push('js-stack')
<script type="text/javascript">
$( document ).ready(function() {
$('.selectize').selectize();
......@@ -81,4 +77,4 @@
});
});
</script>
@stop
@endpush
......@@ -83,7 +83,7 @@
</dl>
@stop
@section('scripts')
@push('js-stack')
<script type="text/javascript">
$( document ).ready(function() {
$(document).keypressAction({
......@@ -110,4 +110,4 @@
});
});
</script>
@stop
@endpush
<?php
namespace Modules\Tag\Tests\Integration;
use Illuminate\Support\Facades\Event;
use Modules\Tag\Events\TagIsCreating;
use Modules\Tag\Events\TagIsUpdating;
use Modules\Tag\Events\TagWasCreated;
use Modules\Tag\Events\TagWasUpdated;
use Modules\Tag\Repositories\TagRepository;
use Modules\Tag\Tests\BaseTestCase;
class EloquentTagRepositoryTest extends BaseTestCase
{
/**
* @var TagRepository
*/
private $tag;
public function setUp()
{
parent::setUp();
$this->tag = app(TagRepository::class);
}
/** @test */
public function it_gets_all_tags_for_a_namespace()
{
$this->tag->create([
'namespace' => 'asgardcms/media',
'en' => [
'slug' => 'media-tag',
'name' => 'media tag',
],
]);
$this->tag->create([
'namespace' => 'asgardcms/media',
'en' => [
'slug' => 'media-tag',
'name' => 'media tag',
],
]);
$this->tag->create([
'namespace' => 'asgardcms/blog',
'en' => [
'slug' => 'media-tag',
'name' => 'media tag',
],
]);
$this->assertCount(1, $this->tag->allForNamespace('asgardcms/blog'));
}
/** @test */
public function it_triggers_event_when_tag_was_created()
{
Event::fake();
$tag = $this->tag->create([
'namespace' => 'asgardcms/media',
'en' => [
'slug' => 'media-tag',
'name' => 'media tag',
],
]);
Event::assertDispatched(TagWasCreated::class, function ($e) use ($tag) {
return $e->tag->id === $tag->id;
});
}
/** @test */
public function it_triggers_event_when_tag_is_creating()
{
Event::fake();
$tag = $this->tag->create([
'namespace' => 'asgardcms/media',
'en' => [
'slug' => 'media-tag',
'name' => 'media tag',
],
]);
Event::assertDispatched(TagIsCreating::class, function ($e) use ($tag) {
return $e->getAttribute('namespace') === $tag->namespace;
});
}
/** @test */
public function it_can_change_data_when_it_is_creating_event()
{
Event::listen(TagIsCreating::class, function (TagIsCreating $event) {
$event->setAttributes(['en' => ['name' => 'MEDIA TAG']]);
});
$tag = $this->tag->create([
'namespace' => 'asgardcms/media',
'en' => [
'slug' => 'media-tag',
'name' => 'media tag',
],
]);
$this->assertEquals('MEDIA TAG', $tag->translate('en')->name);
}
/** @test */
public function it_triggers_event_when_tag_was_updated()
{
Event::fake();
$tag = $this->tag->create([
'namespace' => 'asgardcms/media',
'en' => [
'slug' => 'media-tag',
'name' => 'media tag',
],
]);
$this->tag->update($tag, []);
Event::assertDispatched(TagWasUpdated::class, function ($e) use ($tag) {
return $e->tag->id === $tag->id;
});
}
/** @test */
public function it_can_change_data_when_it_is_updating_event()
{
Event::listen(TagIsUpdating::class, function (TagIsUpdating $event) {
$event->setAttributes(['en' => ['name' => 'MEDIA TAG']]);
});
$tag = $this->tag->create([
'namespace' => 'asgardcms/media',
'en' => [
'slug' => 'media-tag',
'name' => 'media tag',
],
]);
$this->tag->update($tag, []);
$this->assertEquals('MEDIA TAG', $tag->translate('en')->name);
}
}
<?php
namespace Modules\Tag\Tests\Integration;
use Modules\Tag\Repositories\TagRepository;
use Modules\Tag\Tests\BaseTestCase;
class TagRepositoryTest extends BaseTestCase
{
/**
* @var TagRepository
*/
private $tag;
public function setUp()
{
parent::setUp();
$this->tag = app(TagRepository::class);
}
/** @test */
public function it_gets_all_tags_for_a_namespace()
{
$this->tag->create([
'namespace' => 'asgardcms/media',
'en' => [
'slug' => 'media-tag',
'name' => 'media tag',
],
]);
$this->tag->create([
'namespace' => 'asgardcms/media',
'en' => [
'slug' => 'media-tag',
'name' => 'media tag',
],
]);
$this->tag->create([
'namespace' => 'asgardcms/blog',
'en' => [
'slug' => 'media-tag',
'name' => 'media tag',
],
]);
$this->assertCount(1, $this->tag->allForNamespace('asgardcms/blog'));
}
}
url: https://github.com/AsgardCms/Platform
versions:
"2.5.0@unreleased":
added:
- Create and trigger events when tags are created and updated
- Trigger event before a tag is created (<code>TagIsCreating</code>) allow data to be changed
- Trigger event before a tag is updated (<code>TagIsUpdating</code>) allow data to be changed
changed:
- Using the @push js stacks over the scripts section
- Using the @push css stacks over the styles section
"2.1.0":
changed:
- Fixed tags not being removed probably on update & delete
......
......@@ -7,6 +7,7 @@
"AsgardCMS",
"taggable"
],
"version": "2.5.0",
"active": 1,
"order": 1,
"providers": [
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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