Unverified Commit 9c5dfb6e authored by Nicolas Widart's avatar Nicolas Widart

Merge branch '2.0'

* 2.0: (81 commits)
  Make PHP < 7 happy
  Immediately call closure after binding
  Bind current object to the dynamic relations closure
  Fixing @return types
  Adding logout and loginUsingId methods on the sentinal guard
  Adding changelog item
  Removing obsolete files
  Abstract csv download inside Response macro
  Make TranslationController slim
  Move AsgardCms class to the foundation namespace
  Read core module version from the AsgardCms class other modules keep same logic.
  Removing the version number in composer.json
  Added an AsgardCms class containing the current cms version
  Always load migrations
  Preparing 2.5.2 release
  Fixing CLI issue not having the translation repository bound
  Preparing 2.5.1 release
  Adding changelog item
  Add missing `id` attribute to editor's textarea (#359)
  Renaming hook ContentIsRendering to PageContentIsRendering
  ...
parents d7183b4d 62efe73a
......@@ -13,6 +13,7 @@ DB_USERNAME=homestead
DB_PASSWORD=secret
CACHE_DRIVER=array
TRANSLATIONS_CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
......
<?php
$finder = Symfony\CS\Finder\DefaultFinder::create()
->exclude('Modules')
->exclude('vendor')
->in(__DIR__)
;
return Symfony\CS\Config\Config::create()
->setUsingCache(true)
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers(array(
// Concatenation should be used with at least one whitespace around.
'concat_with_spaces',
// Unused use statements must be removed.
'ordered_use',
// Removes extra empty lines.
'extra_empty_lines',
// Removes line breaks between use statements.
'remove_lines_between_uses',
// An empty line feed should precede a return statement.
'return',
// Unused use statements must be removed.
'unused_use',
// Remove trailing whitespace at the end of blank lines.
'whitespacy_lines',
// There MUST be one blank line after the namespace declaration.
'line_after_namespace',
// There should be exactly one blank line before a namespace declaration.
'single_blank_line_before_namespace',
// Each namespace use MUST go on its own line and there MUST be one blank line after the use statements block.
'single_line_after_imports',
// Ensure there is no code on the same line as the PHP open tag and it is followed by a blankline.
'blankline_after_open_tag',
// Remove duplicated semicolons.
'duplicate_semicolon',
// PHP multi-line arrays should have a trailing comma.
'multiline_array_trailing_comma',
// There should be no empty lines after class opening brace.
'no_blank_lines_after_class_opening',
// There should not be blank lines between docblock and the documented element.
'no_empty_lines_after_phpdocs',
// Phpdocs should start and end with content, excluding the very first and last line of the docblocks.
'phpdoc_trim',
// Removes line breaks between use statements.
'remove_lines_between_uses',
))
->finder($finder);
......@@ -16,6 +16,7 @@ class AsgardEditorDirective
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);
}
......
......@@ -2,63 +2,16 @@
namespace Modules\Core\Composers;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Modules\Core\Foundation\AsgardCms;
class ApplicationVersionViewComposer
{
/**
* @var Filesystem
*/
private $filesystem;
/**
* @var Repository
*/
private $cache;
/**
* @var Request
*/
private $request;
public function __construct(Filesystem $filesystem, Repository $cache, Request $request)
{
$this->filesystem = $filesystem;
$this->cache = $cache;
$this->request = $request;
}
public function compose(View $view)
{
if (app('asgard.onBackend') === false) {
return;
}
$view->with('version', $this->getAppVersion());
}
/**
* @return string
*/
private function getAppVersion()
{
$composerFile = $this->getComposerFile();
return isset($composerFile->version) ? $composerFile->version : '1.0';
}
/**
* Get the decoded contents from the main composer.json file
* @return object
*/
private function getComposerFile()
{
$appName = str_slug(config('app.name'));
$composerFile = $this->cache->remember("app.version.$appName", 1440, function () {
return $this->filesystem->get('composer.json');
});
return json_decode($composerFile);
$view->with('version', AsgardCms::VERSION);
}
}
......@@ -5,7 +5,6 @@ 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;
......@@ -50,11 +49,9 @@ 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);
}
}
<?php
namespace Modules\Core\Composers;
use Illuminate\Contracts\View\View;
use Modules\Core\Events\EditorIsRendering;
use Modules\Core\Foundation\Asset\Pipeline\AssetPipeline;
class EditorViewComposer
{
/**
* @var AssetPipeline
*/
private $assetPipeline;
public function __construct(AssetPipeline $assetPipeline)
{
$this->assetPipeline = $assetPipeline;
}
public function compose(View $view)
{
if (app('asgard.onBackend') === false) {
return;
}
event($editor = new EditorIsRendering($this->assetPipeline));
$view->with('editor', $editor);
}
}
......@@ -83,7 +83,7 @@ class ConfigureDatabase implements SetupScript
*/
protected function askDatabaseHost()
{
$host = $this->command->ask('Enter your database host', 'localhost');
$host = $this->command->ask('Enter your database host', '127.0.0.1');
return $host;
}
......
......@@ -15,12 +15,12 @@ class EnvFileWriter
* @var array
*/
protected $search = [
"DB_CONNECTION=mysql",
"DB_PORT=3306",
"DB_HOST=localhost",
"DB_DATABASE=homestead",
"DB_USERNAME=homestead",
"DB_PASSWORD=secret",
'DB_CONNECTION=mysql',
'DB_PORT=3306',
'DB_HOST=127.0.0.1',
'DB_DATABASE=homestead',
'DB_USERNAME=homestead',
'DB_PASSWORD=secret',
];
/**
......
<?php
namespace Modules\Core\Events;
use Maatwebsite\Sidebar\Menu;
/**
* Hook BuildingSidebar
* Triggered when building the backend sidebar
* Use this hook to add your sidebar items
* @package Modules\Core\Events
*/
class BuildingSidebar
{
/**
* @var Menu
*/
private $menu;
public function __construct(Menu $menu)
{
$this->menu = $menu;
}
/**
* Add a menu group to the menu
* @param Menu $menu
*/
public function add(Menu $menu)
{
$this->menu->add($menu);
}
/**
* Get the current Laravel-Sidebar menu
* @return Menu
*/
public function getMenu()
{
return $this->menu;
}
}
......@@ -60,6 +60,7 @@ class CollectingAssets
return true;
}
}
return false;
}
}
<?php
namespace Modules\Core\Events\Handlers;
use Maatwebsite\Sidebar\Group;
use Maatwebsite\Sidebar\Menu;
use Modules\Core\Sidebar\AbstractAdminSidebar;
class RegisterCoreSidebar extends AbstractAdminSidebar
{
/**
* Method used to define your sidebar menu groups and items
* @param Menu $menu
* @return Menu
*/
public function extendWith(Menu $menu)
{
$menu->group(trans('core::sidebar.content'), function (Group $group) {
$group->weight(50);
$group->authorize(
$this->auth->hasAccess('core.sidebar.group')
);
});
return $menu;
}
}
......@@ -3,11 +3,11 @@
namespace Modules\Core\Events\Handlers;
use League\CommonMark\CommonMarkConverter;
use Modules\Page\Events\ContentIsRendering;
use Modules\Page\Events\PageContentIsRendering;
class RenderMarkdown
{
public function handle(ContentIsRendering $event)
public function handle(PageContentIsRendering $event)
{
$converter = new CommonMarkConverter();
......
<?php
namespace Modules\Core\Foundation;
class AsgardCms
{
/**
* The AsgardCms version.
* @var string
*/
const VERSION = '2.5.2';
}
......@@ -13,14 +13,17 @@ use Modules\Core\Console\DownloadModuleCommand;
use Modules\Core\Console\InstallCommand;
use Modules\Core\Console\PublishModuleAssetsCommand;
use Modules\Core\Console\PublishThemeAssetsCommand;
use Modules\Core\Events\BuildingSidebar;
use Modules\Core\Events\EditorIsRendering;
use Modules\Core\Events\Handlers\RegisterCoreSidebar;
use Modules\Core\Foundation\Theme\ThemeManager;
use Modules\Core\Traits\CanGetSidebarClassForModule;
use Modules\Core\Traits\CanPublishConfiguration;
use Nwidart\Modules\Module;
class CoreServiceProvider extends ServiceProvider
{
use CanPublishConfiguration;
use CanPublishConfiguration, CanGetSidebarClassForModule;
/**
* Indicates if loading of the provider is deferred.
*
......@@ -79,6 +82,11 @@ class CoreServiceProvider extends ServiceProvider
$this->app->bind('core.asgard.editor', function () {
return new AsgardEditorDirective();
});
$this->app['events']->listen(
BuildingSidebar::class,
$this->getSidebarClassForModule('core', RegisterCoreSidebar::class)
);
}
/**
......@@ -248,7 +256,7 @@ class CoreServiceProvider extends ServiceProvider
*/
private function setLocalesConfigurations()
{
if (! $this->app['asgard.isInstalled']) {
if ($this->app['asgard.isInstalled'] === false || $this->app->runningInConsole() === true) {
return;
}
......
......@@ -6,7 +6,7 @@
<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>
<textarea class="{{ $editor->getEditorClass() }}" name="{{$lang}}[{{$fieldName}}]" id="{{$lang}}[{{$fieldName}}]" rows="10" cols="80">{{ $slot }}</textarea>
{!! $errors->first("{$lang}.{$fieldName}", '<span class="help-block">:message</span>') !!}
</div>
......
......@@ -6,7 +6,7 @@
<div class='{{ $errors->has($fieldName) ? ' has-error' : '' }}'>
{!! Form::label($fieldName, $labelName) !!}
<textarea class="{{ $editor->getEditorClass() }}" name="{{ $fieldName }}" rows="10" cols="80">{{ $slot }}</textarea>
<textarea class="{{ $editor->getEditorClass() }}" name="{{ $fieldName }}" id="{{ $fieldName }}" rows="10" cols="80">{{ $slot }}</textarea>
{!! $errors->first($fieldName, '<span class="help-block">:message</span>') !!}
</div>
......
<?php
namespace Modules\Core\Sidebar;
use Maatwebsite\Sidebar\Menu;
use Modules\Core\Events\BuildingSidebar;
use Modules\User\Contracts\Authentication;
use Maatwebsite\Sidebar\SidebarExtender;
abstract class AbstractAdminSidebar implements SidebarExtender
{
/**
* @var Authentication
*/
protected $auth;
/**
* @param Authentication $auth
*
* @internal param Guard $guard
*/
public function __construct(Authentication $auth)
{
$this->auth = $auth;
}
public function handle(BuildingSidebar $sidebar)
{
$sidebar->add($this->extendWith($sidebar->getMenu()));
}
/**
* Method used to define your sidebar menu groups and items
* @param Menu $menu
* @return Menu
*/
abstract public function extendWith(Menu $menu);
}
......@@ -7,6 +7,7 @@ use Maatwebsite\Sidebar\Menu;
use Maatwebsite\Sidebar\ShouldCache;
use Maatwebsite\Sidebar\Sidebar;
use Maatwebsite\Sidebar\Traits\CacheableTrait;
use Modules\Core\Events\BuildingSidebar;
use Nwidart\Modules\Contracts\RepositoryInterface;
class AdminSidebar implements Sidebar, ShouldCache
......@@ -44,6 +45,8 @@ class AdminSidebar implements Sidebar, ShouldCache
*/
public function build()
{
event($event = new BuildingSidebar($this->menu));
foreach ($this->modules->enabled() as $module) {
$lowercaseModule = strtolower($module->get('name'));
if ($this->hasCustomSidebar($lowercaseModule) === true) {
......
<?php
namespace Modules\Core\Traits;
trait CanGetSidebarClassForModule
{
/**
* @param string $module
* @param string $default
* @return string
*/
public function getSidebarClassForModule($module, $default)
{
if ($this->hasCustomSidebar($module)) {
$class = config("asgard.{$module}.config.custom-sidebar");
if (class_exists($class) === false) {
return $default;
}
return $class;
}
return $default;
}
private function hasCustomSidebar($module)
{
$config = config("asgard.{$module}.config.custom-sidebar");
return $config !== null;
}
}
url: https://github.com/AsgardCms/Platform
versions:
"2.5.0@unreleased":
"2.x.x@unreleased":
added:
- Added an <code>AsgardCms</code> class containing the current cms version
"2.5.2":
changed:
- Fixing CLI issue not having the translation repository bound
"2.5.1":
changed:
- Add missing <code>id</code> attribute to editor's textarea
"2.5.0":
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
......@@ -8,8 +17,13 @@ versions:
- 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.
- New <code>BuildingSidebar</code> hook used to add sidebar elements (backend) this will replace the <code>SidebarExtender</code> classes
- Creating helper trait <code>CanGetSidebarClassForModule</code>, to get the sidebar class for a module
- Adding Docker support. Run `./dcp up` to get started.
changed:
- Adding more core modules (tag, translation and page). Preventing them to be disabled.
- Splitting up the <code>EditorIsRendering</code> hook to its own view composer, avoiding binding the (expensive) <code>AssetsViewComposer</code> on every view & partial
- Stop making DB queries on console mode
"2.3.0":
added:
- New command <code>php artisan asgard:download:module asgardcms/contact --migrations --seeds --assets</code>
......
......@@ -7,4 +7,5 @@ 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('*', \Modules\Core\Composers\AssetsViewComposer::class);
view()->composer('layouts.master', \Modules\Core\Composers\AssetsViewComposer::class);
view()->composer('*', \Modules\Core\Composers\EditorViewComposer::class);
......@@ -37,14 +37,13 @@ if (! function_exists('is_core_module')) {
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'));
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'));
return view('core::components.textarea-wrapper', compact('fieldName', 'labelName', 'content'));
}
}
......@@ -345,3 +345,11 @@ Form::macro('normalSelect', function ($name, $title, ViewErrorBag $errors, array
return new HtmlString($string);
});
Response::macro('csv', function ($file, $filename, $status = 200, $headers = []) {
return response($file, $status, array_merge([
'Content-Type' => 'application/csv',
'Content-Disposition' => "attachment; filename={$filename}",
'Pragma' => 'no-cache',
], $headers));
});
<?php
namespace Modules\Dashboard\Sidebar;
namespace Modules\Dashboard\Events\Handlers;
use Maatwebsite\Sidebar\Group;
use Maatwebsite\Sidebar\Item;
use Maatwebsite\Sidebar\Menu;
use Modules\User\Contracts\Authentication;
use Modules\Core\Sidebar\AbstractAdminSidebar;
class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
class RegisterDashboardSidebar extends AbstractAdminSidebar
{
/**
* @var Authentication
*/
protected $auth;
/**
* @param Authentication $auth
*
* @internal param Guard $guard
*/
public function __construct(Authentication $auth)
{
$this->auth = $auth;
}
/**
* @param Menu $menu
*
* @return Menu
*/
public function extendWith(Menu $menu)
......
......@@ -3,8 +3,11 @@
namespace Modules\Dashboard\Providers;
use Illuminate\Support\ServiceProvider;
use Modules\Core\Events\BuildingSidebar;
use Modules\Core\Traits\CanGetSidebarClassForModule;
use Modules\Core\Traits\CanPublishConfiguration;
use Modules\Dashboard\Entities\Widget;
use Modules\Dashboard\Events\Handlers\RegisterDashboardSidebar;
use Modules\Dashboard\Repositories\Cache\CacheWidgetDecorator;
use Modules\Dashboard\Repositories\Eloquent\EloquentWidgetRepository;
use Modules\Dashboard\Repositories\WidgetRepository;
......@@ -12,7 +15,7 @@ use Modules\Workshop\Manager\StylistThemeManager;
class DashboardServiceProvider extends ServiceProvider
{
use CanPublishConfiguration;
use CanPublishConfiguration, CanGetSidebarClassForModule;
/**
* Indicates if loading of the provider is deferred.
*
......@@ -36,6 +39,11 @@ class DashboardServiceProvider extends ServiceProvider
return new CacheWidgetDecorator($repository);
});
$this->app['events']->listen(
BuildingSidebar::class,
$this->getSidebarClassForModule('dashboard', RegisterDashboardSidebar::class)
);
}
public function boot(StylistThemeManager $theme)
......
url: https://github.com/AsgardCms/Platform
versions:
"2.5.0@unreleased":
"2.5.0":
added:
- New Sidebar event handler class replacing the old <code>SidebarExtender</code> class
changed:
- Using the @push js stacks over the scripts section
- Using the @push css stacks over the styles section
......
......@@ -2,8 +2,8 @@
namespace Modules\Media\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
use Modules\Core\Events\AbstractEntityHook;
final class FileIsCreating extends AbstractEntityHook implements EntityIsChanging
{
......
......@@ -2,8 +2,8 @@
namespace Modules\Media\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Media\Entities\File;
final class FileIsUpdating extends AbstractEntityHook implements EntityIsChanging
......
<?php
namespace Modules\Media\Sidebar;
namespace Modules\Media\Events\Handlers;
use Maatwebsite\Sidebar\Group;
use Maatwebsite\Sidebar\Item;
use Maatwebsite\Sidebar\Menu;
use Modules\User\Contracts\Authentication;
use Modules\Core\Sidebar\AbstractAdminSidebar;
class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
class RegisterMediaSidebar extends AbstractAdminSidebar
{
/**
* @var Authentication
*/
protected $auth;
/**
* @param Authentication $auth
*
* @internal param Guard $guard
*/
public function __construct(Authentication $auth)
{
$this->auth = $auth;
}
/**
* @param Menu $menu
*
* @return Menu
*/
public function extendWith(Menu $menu)
{
$menu->group(trans('core::sidebar.content'), function (Group $group) {
......
......@@ -5,6 +5,8 @@ namespace Modules\Media\Providers;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
use Modules\Core\Events\BuildingSidebar;
use Modules\Core\Traits\CanGetSidebarClassForModule;
use Modules\Core\Traits\CanPublishConfiguration;
use Modules\Media\Blade\MediaMultipleDirective;
use Modules\Media\Blade\MediaSingleDirective;
......@@ -14,6 +16,7 @@ use Modules\Media\Contracts\DeletingMedia;
use Modules\Media\Contracts\StoringMedia;
use Modules\Media\Entities\File;
use Modules\Media\Events\Handlers\HandleMediaStorage;
use Modules\Media\Events\Handlers\RegisterMediaSidebar;
use Modules\Media\Events\Handlers\RemovePolymorphicLink;
use Modules\Media\Image\ThumbnailManager;
use Modules\Media\Repositories\Eloquent\EloquentFileRepository;
......@@ -22,7 +25,7 @@ use Modules\Tag\Repositories\TagManager;
class MediaServiceProvider extends ServiceProvider
{
use CanPublishConfiguration;
use CanPublishConfiguration, CanGetSidebarClassForModule;
/**
* Indicates if loading of the provider is deferred.
*
......@@ -50,6 +53,11 @@ class MediaServiceProvider extends ServiceProvider
$this->app->bind('media.thumbnail.directive', function () {
return new MediaThumbnailDirective();
});
$this->app['events']->listen(
BuildingSidebar::class,
$this->getSidebarClassForModule('media', RegisterMediaSidebar::class)
);
}
public function boot(DispatcherContract $events)
......
......@@ -178,7 +178,7 @@ class EloquentFileRepositoryTest extends MediaTestCase
'description' => 'My cool file!',
'alt_attribute' => 'My cool file!',
'keywords' => 'My cool file!',
]
],
]);
Event::assertDispatched(FileIsUpdating::class, function ($e) use ($file) {
......@@ -195,7 +195,7 @@ class EloquentFileRepositoryTest extends MediaTestCase
'filename' => 'bettername.jpg',
'en' => [
'description' => 'Hello World',
]
],
]);
});
......@@ -205,7 +205,7 @@ class EloquentFileRepositoryTest extends MediaTestCase
'description' => 'My cool file!',
'alt_attribute' => 'My cool file!',
'keywords' => 'My cool file!',
]
],
]);
$this->assertEquals('bettername.jpg', $file->filename);
......
url: https://github.com/AsgardCms/Platform
versions:
"2.5.0@unreleased":
"2.5.0":
added:
- <code>FileWasCreated</code> event
- <code>FileWasUpdated</code> event
- <code>FileIsCreating</code> hookable event
- <code>FileIsUpdating</code> hookable event
- New Sidebar event handler class replacing the old <code>SidebarExtender</code> class
changed:
- Using the @push js stacks over the scripts section
- Using the @push css stacks over the styles section
......
<?php
namespace Modules\Menu\Sidebar;
namespace Modules\Menu\Events\Handlers;
use Maatwebsite\Sidebar\Group;
use Maatwebsite\Sidebar\Item;
use Maatwebsite\Sidebar\Menu;
use Modules\User\Contracts\Authentication;
use Modules\Core\Sidebar\AbstractAdminSidebar;
class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
class RegisterMenuSidebar extends AbstractAdminSidebar
{
/**
* @var Authentication
*/
protected $auth;
/**
* @param Authentication $auth
*
* @internal param Guard $guard
*/
public function __construct(Authentication $auth)
{
$this->auth = $auth;
}
/**
* Method used to define your sidebar menu groups and items
* @param Menu $menu
*
* @return Menu
*/
public function extendWith(Menu $menu)
......
......@@ -2,8 +2,8 @@
namespace Modules\Menu\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
use Modules\Core\Events\AbstractEntityHook;
class MenuIsCreating extends AbstractEntityHook implements EntityIsChanging
{
......
......@@ -2,8 +2,8 @@
namespace Modules\Menu\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Menu\Entities\Menu;
class MenuIsUpdating extends AbstractEntityHook implements EntityIsChanging
......
......@@ -2,8 +2,8 @@
namespace Modules\Menu\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
use Modules\Core\Events\AbstractEntityHook;
class MenuItemIsCreating extends AbstractEntityHook implements EntityIsChanging
{
......
......@@ -2,8 +2,8 @@
namespace Modules\Menu\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Menu\Entities\Menuitem;
class MenuItemIsUpdating extends AbstractEntityHook implements EntityIsChanging
......
......@@ -3,10 +3,13 @@
namespace Modules\Menu\Providers;
use Illuminate\Support\ServiceProvider;
use Modules\Core\Events\BuildingSidebar;
use Modules\Core\Traits\CanGetSidebarClassForModule;
use Modules\Core\Traits\CanPublishConfiguration;
use Modules\Menu\Blade\MenuDirective;
use Modules\Menu\Entities\Menu;
use Modules\Menu\Entities\Menuitem;
use Modules\Menu\Events\Handlers\RegisterMenuSidebar;
use Modules\Menu\Repositories\Cache\CacheMenuDecorator;
use Modules\Menu\Repositories\Cache\CacheMenuItemDecorator;
use Modules\Menu\Repositories\Eloquent\EloquentMenuItemRepository;
......@@ -19,7 +22,7 @@ use Nwidart\Menus\MenuItem as PingpongMenuItem;
class MenuServiceProvider extends ServiceProvider
{
use CanPublishConfiguration;
use CanPublishConfiguration, CanGetSidebarClassForModule;
/**
* Indicates if loading of the provider is deferred.
*
......@@ -39,6 +42,11 @@ class MenuServiceProvider extends ServiceProvider
$this->app->bind('menu.menu.directive', function () {
return new MenuDirective();
});
$this->app['events']->listen(
BuildingSidebar::class,
$this->getSidebarClassForModule('menu', RegisterMenuSidebar::class)
);
}
/**
......@@ -168,9 +176,13 @@ class MenuServiceProvider extends ServiceProvider
*/
private function registerMenus()
{
if ($this->app['asgard.isInstalled'] === false || $this->app['asgard.onBackend'] === true) {
if ($this->app['asgard.isInstalled'] === false ||
$this->app['asgard.onBackend'] === true ||
$this->app->runningInConsole() === true
) {
return;
}
$menu = $this->app->make(MenuRepository::class);
$menuItem = $this->app->make(MenuItemRepository::class);
foreach ($menu->allOnline() as $menu) {
......
......@@ -43,7 +43,7 @@ abstract class BaseMenuTest extends TestCase
$this->menu = app(MenuRepository::class);
$this->menuItem = app(MenuItemRepository::class);
app(SettingRepository::class)->createOrUpdate([
'core::locales' => ['en', 'fr',]
'core::locales' => ['en', 'fr',],
]);
}
......
url: https://github.com/AsgardCms/Platform
versions:
"2.5.0@unreleased":
"2.5.0":
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
- New Sidebar event handler class replacing the old <code>SidebarExtender</code> class
changed:
- Using the @push js stacks over the scripts section
- Using the @push css stacks over the styles section
......
......@@ -3,7 +3,7 @@
namespace Modules\Page\Entities;
use Illuminate\Database\Eloquent\Model;
use Modules\Page\Events\ContentIsRendering;
use Modules\Page\Events\PageContentIsRendering;
class PageTranslation extends Model
{
......@@ -24,7 +24,7 @@ class PageTranslation extends Model
public function getBodyAttribute($body)
{
event($event = new ContentIsRendering($body));
event($event = new PageContentIsRendering($body));
return $event->getBody();
}
......
<?php
namespace Modules\Page\Sidebar;
namespace Modules\Page\Events\Handlers;
use Maatwebsite\Sidebar\Group;
use Maatwebsite\Sidebar\Item;
use Maatwebsite\Sidebar\Menu;
use Modules\User\Contracts\Authentication;
use Modules\Core\Sidebar\AbstractAdminSidebar;
class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
class RegisterPageSidebar extends AbstractAdminSidebar
{
/**
* @var Authentication
*/
protected $auth;
/**
* @param Authentication $auth
*
* @internal param Guard $guard
*/
public function __construct(Authentication $auth)
{
$this->auth = $auth;
}
/**
* @param Menu $menu
*
* @return Menu
*/
public function extendWith(Menu $menu)
......
......@@ -2,7 +2,7 @@
namespace Modules\Page\Events;
class ContentIsRendering
class PageContentIsRendering
{
/**
* @var string The body of the page to render
......
......@@ -2,8 +2,8 @@
namespace Modules\Page\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
use Modules\Core\Events\AbstractEntityHook;
class PageIsCreating extends AbstractEntityHook implements EntityIsChanging
{
......
......@@ -2,8 +2,8 @@
namespace Modules\Page\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Page\Entities\Page;
class PageIsUpdating extends AbstractEntityHook implements EntityIsChanging
......
......@@ -4,9 +4,12 @@ namespace Modules\Page\Providers;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;
use Modules\Core\Events\BuildingSidebar;
use Modules\Core\Events\CollectingAssets;
use Modules\Core\Traits\CanGetSidebarClassForModule;
use Modules\Core\Traits\CanPublishConfiguration;
use Modules\Page\Entities\Page;
use Modules\Page\Events\Handlers\RegisterPageSidebar;
use Modules\Page\Repositories\Cache\CachePageDecorator;
use Modules\Page\Repositories\Eloquent\EloquentPageRepository;
use Modules\Page\Repositories\PageRepository;
......@@ -15,7 +18,7 @@ use Modules\Tag\Repositories\TagManager;
class PageServiceProvider extends ServiceProvider
{
use CanPublishConfiguration;
use CanPublishConfiguration, CanGetSidebarClassForModule;
/**
* Indicates if loading of the provider is deferred.
*
......@@ -31,6 +34,11 @@ class PageServiceProvider extends ServiceProvider
public function register()
{
$this->registerBindings();
$this->app['events']->listen(
BuildingSidebar::class,
$this->getSidebarClassForModule('page', RegisterPageSidebar::class)
);
}
public function boot()
......
......@@ -145,7 +145,6 @@ class EloquentPageRepositoryTest extends BasePageTest
$this->assertEquals('better-tpl', $page->template);
}
/** @test */
public function it_triggers_event_when_page_was_updated()
{
......
......@@ -3,14 +3,14 @@
namespace Modules\Page\Tests;
use Illuminate\Support\Facades\Event;
use Modules\Page\Events\ContentIsRendering;
use Modules\Page\Events\PageContentIsRendering;
class ContentIsRenderingTest extends BasePageTest
class PageContentIsRenderingTest extends BasePageTest
{
/** @test */
public function it_can_change_final_content()
{
Event::listen(ContentIsRendering::class, function (ContentIsRendering $event) {
Event::listen(PageContentIsRendering::class, function (PageContentIsRendering $event) {
$event->setBody('<strong>' . $event->getOriginal() . '</strong>');
});
......
url: https://github.com/AsgardCms/Platform
versions:
"2.5.0@unreleased":
"2.5.1":
changed:
- Renamed hook <code>ContentIsRendering</code> to <code>PageContentIsRendering</code> making it more specific
"2.5.0":
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
......@@ -11,6 +14,7 @@ versions:
- 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
- Sidebar is now loaded via the <code>BuildingSidebar</code> hook
"2.2.0":
added:
- Testing event trigger on page deletion
......
<?php
namespace Modules\Setting\Sidebar;
namespace Modules\Setting\Events\Handlers;
use Maatwebsite\Sidebar\Group;
use Maatwebsite\Sidebar\Item;
use Maatwebsite\Sidebar\Menu;
use Modules\User\Contracts\Authentication;
use Modules\Core\Sidebar\AbstractAdminSidebar;
class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
class RegisterSettingSidebar extends AbstractAdminSidebar
{
/**
* @var Authentication
*/
protected $auth;
/**
* @param Authentication $auth
*
* @internal param Guard $guard
*/
public function __construct(Authentication $auth)
{
$this->auth = $auth;
}
/**
* Method used to define your sidebar menu groups and items
* @param Menu $menu
*
* @return Menu
*/
public function extendWith(Menu $menu)
......
......@@ -4,9 +4,12 @@ namespace Modules\Setting\Providers;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\ServiceProvider;
use Modules\Core\Events\BuildingSidebar;
use Modules\Core\Traits\CanGetSidebarClassForModule;
use Modules\Core\Traits\CanPublishConfiguration;
use Modules\Setting\Blade\SettingDirective;
use Modules\Setting\Entities\Setting;
use Modules\Setting\Events\Handlers\RegisterSettingSidebar;
use Modules\Setting\Facades\Settings as SettingsFacade;
use Modules\Setting\Repositories\Cache\CacheSettingDecorator;
use Modules\Setting\Repositories\Eloquent\EloquentSettingRepository;
......@@ -15,7 +18,7 @@ use Modules\Setting\Support\Settings;
class SettingServiceProvider extends ServiceProvider
{
use CanPublishConfiguration;
use CanPublishConfiguration, CanGetSidebarClassForModule;
/**
* Indicates if loading of the provider is deferred.
*
......@@ -44,6 +47,11 @@ class SettingServiceProvider extends ServiceProvider
$this->app->bind('setting.setting.directive', function () {
return new SettingDirective();
});
$this->app['events']->listen(
BuildingSidebar::class,
$this->getSidebarClassForModule('setting', RegisterSettingSidebar::class)
);
}
public function boot()
......
......@@ -165,7 +165,7 @@ class EloquentSettingRepositoryTest extends BaseSettingTest
}
if ($event->getSettingName() === 'core::site-name') {
$event->setSettingValues([
'en' => 'English AsgardCMS'
'en' => 'English AsgardCMS',
]);
}
});
......@@ -234,7 +234,7 @@ class EloquentSettingRepositoryTest extends BaseSettingTest
}
if ($event->getSettingName() === 'core::site-name') {
$event->setSettingValues([
'en' => 'English AsgardCMS'
'en' => 'English AsgardCMS',
]);
}
});
......
url: https://github.com/AsgardCms/Platform
versions:
"2.5.0@unreleased":
"2.5.0":
changed:
- Normalise the setting was created event
- Normalise the setting was updated event
- Trigger <code>SettingIsCreating</code> hook
- Trigger <code>SettingIsUpdating</code> hook
- New Sidebar event handler class replacing the old <code>SidebarExtender</code> class
changed:
- Using the @push js stacks over the scripts section
- Using the @push css stacks over the styles section
......
<?php
namespace Modules\Tag\Sidebar;
namespace Modules\Tag\Events\Handlers;
use Maatwebsite\Sidebar\Group;
use Maatwebsite\Sidebar\Item;
use Maatwebsite\Sidebar\Menu;
use Modules\User\Contracts\Authentication;
use Modules\Core\Sidebar\AbstractAdminSidebar;
class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
class RegisterTagSidebar extends AbstractAdminSidebar
{
/**
* @var Authentication
*/
protected $auth;
/**
* @param Authentication $auth
*
* @internal param Guard $guard
*/
public function __construct(Authentication $auth)
{
$this->auth = $auth;
}
/**
* Method used to define your sidebar menu groups and items
* @param Menu $menu
*
* @return Menu
*/
public function extendWith(Menu $menu)
......
......@@ -2,8 +2,8 @@
namespace Modules\Tag\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
use Modules\Core\Events\AbstractEntityHook;
class TagIsCreating extends AbstractEntityHook implements EntityIsChanging
{
......
......@@ -2,8 +2,8 @@
namespace Modules\Tag\Events;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Core\Contracts\EntityIsChanging;
use Modules\Core\Events\AbstractEntityHook;
use Modules\Tag\Entities\Tag;
class TagIsUpdating extends AbstractEntityHook implements EntityIsChanging
......
......@@ -3,9 +3,12 @@
namespace Modules\Tag\Providers;
use Illuminate\Support\ServiceProvider;
use Modules\Core\Events\BuildingSidebar;
use Modules\Core\Traits\CanGetSidebarClassForModule;
use Modules\Core\Traits\CanPublishConfiguration;
use Modules\Tag\Blade\TagWidget;
use Modules\Tag\Entities\Tag;
use Modules\Tag\Events\Handlers\RegisterTagSidebar;
use Modules\Tag\Repositories\Cache\CacheTagDecorator;
use Modules\Tag\Repositories\Eloquent\EloquentTagRepository;
use Modules\Tag\Repositories\TagManager;
......@@ -14,7 +17,7 @@ use Modules\Tag\Repositories\TagRepository;
class TagServiceProvider extends ServiceProvider
{
use CanPublishConfiguration;
use CanPublishConfiguration, CanGetSidebarClassForModule;
/**
* Indicates if loading of the provider is deferred.
*
......@@ -34,6 +37,10 @@ class TagServiceProvider extends ServiceProvider
$this->app->singleton('tag.widget.directive', function ($app) {
return new TagWidget($app[TagRepository::class]);
});
$this->app['events']->listen(
BuildingSidebar::class,
$this->getSidebarClassForModule('tag', RegisterTagSidebar::class)
);
}
public function boot()
......
......@@ -40,5 +40,4 @@ class EloquentTagRepository extends EloquentBaseRepository implements TagReposit
return $tag;
}
}
url: https://github.com/AsgardCms/Platform
versions:
"2.5.0@unreleased":
"2.5.0":
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
......@@ -8,6 +8,7 @@ versions:
changed:
- Using the @push js stacks over the scripts section
- Using the @push css stacks over the styles section
- Sidebar is now loaded via the <code>BuildingSidebar</code> hook
"2.1.0":
changed:
- Fixed tags not being removed probably on update & delete
......
<?php
namespace Modules\Translation\Sidebar;
namespace Modules\Translation\Events\Handlers;
use Maatwebsite\Sidebar\Group;
use Maatwebsite\Sidebar\Item;
use Maatwebsite\Sidebar\Menu;
use Modules\User\Contracts\Authentication;
use Modules\Core\Sidebar\AbstractAdminSidebar;
class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
class RegisterTranslationSidebar extends AbstractAdminSidebar
{
/**
* @var Authentication
*/
protected $auth;
/**
* @param Authentication $auth
*
* @internal param Guard $guard
*/
public function __construct(Authentication $auth)
{
$this->auth = $auth;
}
/**
* Method used to define your sidebar menu groups and items
* @param Menu $menu
*
* @return Menu
*/
public function extendWith(Menu $menu)
......
......@@ -53,11 +53,7 @@ class TranslationController extends AdminBaseController
public function export(TranslationsExporter $exporter)
{
return response()->make($exporter->export(), 200, [
'Content-Type' => 'application/csv',
'Content-Disposition' => "attachment; filename={$exporter->getFileName()}",
'Pragma' => 'no-cache',
]);
return response()->csv($exporter->export(), $exporter->getFileName());
}
public function import(ImportTranslationsRequest $request, TranslationsImporter $importer)
......
......@@ -2,12 +2,13 @@
namespace Modules\Translation\Http\Controllers\Api;
use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\Translation\Repositories\TranslationRepository;
use Illuminate\Database\Eloquent\Collection;
use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
use Modules\User\Traits\CanFindUserWithBearerToken;
use Modules\Translation\Services\TranslationRevisions;
use Modules\Translation\Repositories\TranslationRepository;
class TranslationController extends Controller
{
......@@ -38,67 +39,11 @@ class TranslationController extends Controller
$this->translation->clearCache();
}
public function revisions(Request $request)
public function revisions(TranslationRevisions $revisions, Request $request)
{
$translation = $this->translation->findTranslationByKey($request->get('key'));
$translation = $translation->translate($request->get('locale'));
if (null === $translation) {
return response()->json(['<tr><td>' . trans('translation::translations.No Revisions yet') . '</td></tr>']);
}
return response()->json($this->formatRevisionHistory($translation->revisionHistory));
}
private function formatRevisionHistory(Collection $revisionHistory)
{
$formattedHistory = [];
foreach ($revisionHistory as $history) {
if ($history->key == 'created_at' && !$history->old_value) {
$formattedHistory[] = $this->getCreatedRevisionTemplate($history);
} else {
$formattedHistory[] = $this->getRevisionTemplate($history);
}
}
return array_reverse($formattedHistory);
}
private function getRevisionTemplate($history)
{
$timeAgo = $history->created_at->diffForHumans();
$revertRoute = route('admin.translation.translation.update', [$history->revisionable_id, 'oldValue' => $history->oldValue()]);
$edited = trans('translation::translations.edited');
$firstName = $history->userResponsible() ? $history->userResponsible()->first_name : '';
$lastName = $history->userResponsible() ? $history->userResponsible()->last_name : '';
return <<<HTML
<tr>
<td>{$history->oldValue()}</td>
<td>{$firstName} {$lastName}</td>
<td>$edited</td>
<td><a data-toggle="tooltip" title="{$history->created_at}">{$timeAgo}</a></td>
<td><a href="{$revertRoute}"><i class="fa fa-history"></i></a></td>
</tr>
HTML;
}
private function getCreatedRevisionTemplate($history)
{
$timeAgo = $history->created_at->diffForHumans();
$created = trans('translation::translations.created');
$firstName = $history->userResponsible() ? $history->userResponsible()->first_name : '';
$lastName = $history->userResponsible() ? $history->userResponsible()->last_name : '';
return <<<HTML
<tr>
<td></td>
<td>{$firstName} {$lastName}</td>
<td>$created</td>
<td><a data-toggle="tooltip" title="{$history->created_at}">{$timeAgo}</a></td>
<td></td>
</tr>
HTML;
return $revisions->get(
$request->get('key'),
$request->get('locale')
);
}
}
......@@ -2,24 +2,26 @@
namespace Modules\Translation\Providers;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
use Modules\Core\Composers\CurrentUserViewComposer;
use Modules\Core\Events\BuildingSidebar;
use Modules\Core\Traits\CanGetSidebarClassForModule;
use Modules\Core\Traits\CanPublishConfiguration;
use Modules\Translation\Console\BuildTranslationsCacheCommand;
use Modules\Translation\Entities\Translation;
use Modules\Translation\Events\Handlers\RegisterTranslationSidebar;
use Modules\Translation\Repositories\Cache\CacheTranslationDecorator;
use Modules\Translation\Repositories\Eloquent\EloquentTranslationRepository;
use Modules\Translation\Repositories\File\FileTranslationRepository as FileDiskTranslationRepository;
use Modules\Translation\Repositories\FileTranslationRepository;
use Modules\Translation\Repositories\TranslationRepository;
use Modules\Translation\Services\TranslationLoader;
use Modules\Translation\Services\Translator;
use Schema;
class TranslationServiceProvider extends ServiceProvider
{
use CanPublishConfiguration;
use CanPublishConfiguration, CanGetSidebarClassForModule;
/**
* Indicates if loading of the provider is deferred.
*
......@@ -38,6 +40,11 @@ class TranslationServiceProvider extends ServiceProvider
$this->registerConsoleCommands();
view()->composer('translation::admin.translations.index', CurrentUserViewComposer::class);
$this->app['events']->listen(
BuildingSidebar::class,
$this->getSidebarClassForModule('translation', RegisterTranslationSidebar::class)
);
}
public function boot()
......@@ -46,12 +53,15 @@ class TranslationServiceProvider extends ServiceProvider
$this->publishConfig('translation', 'permissions');
$this->registerValidators();
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
if ($this->app->runningInConsole() === true) {
return;
}
if ($this->shouldRegisterCustomTranslator()) {
$this->registerCustomTranslator();
}
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
}
/**
......@@ -90,10 +100,6 @@ class TranslationServiceProvider extends ServiceProvider
$this->app->bind(TranslationRepository::class, function () {
$repository = new EloquentTranslationRepository(new Translation());
if (! config('app.cache')) {
return $repository;
}
return new CacheTranslationDecorator($repository);
});
......@@ -111,9 +117,6 @@ class TranslationServiceProvider extends ServiceProvider
protected function registerCustomTranslator()
{
$this->app->offsetUnset('translation.loader');
$this->app->offsetUnset('translator');
$this->app->singleton('translation.loader', function ($app) {
return new TranslationLoader($app['files'], $app['path.lang']);
});
......@@ -122,7 +125,7 @@ class TranslationServiceProvider extends ServiceProvider
$locale = $app['config']['app.locale'];
$trans = new Translator($loader, $locale);
$trans = new \Illuminate\Translation\Translator($loader, $locale);
$trans->setFallback($app['config']['app.fallback_locale']);
......
......@@ -26,8 +26,7 @@ class CacheTranslationDecorator extends BaseCacheDecorator implements Translatio
$locale = $locale ?: app()->getLocale();
return $this->cache
->tags([$this->entityName, 'global'])
return app('cache')->driver('translations')
->rememberForever("{$this->entityName}.findByKeyAndLocale.{$cleanKey}.{$locale}",
function () use ($key, $locale) {
return $this->repository->findByKeyAndLocale($key, $locale);
......@@ -37,8 +36,7 @@ class CacheTranslationDecorator extends BaseCacheDecorator implements Translatio
public function allFormatted()
{
return $this->cache
->tags([$this->entityName, 'global'])
return app('cache')->driver('translations')
->rememberForever("{$this->locale}.{$this->entityName}.allFormatted",
function () {
return $this->repository->allFormatted();
......@@ -48,7 +46,7 @@ class CacheTranslationDecorator extends BaseCacheDecorator implements Translatio
public function saveTranslationForLocaleAndKey($locale, $key, $value)
{
$this->cache->tags($this->entityName)->flush();
app('cache')->driver('translations')->flush();
return $this->repository->saveTranslationForLocaleAndKey($locale, $key, $value);
}
......@@ -57,8 +55,7 @@ class CacheTranslationDecorator extends BaseCacheDecorator implements Translatio
{
$cleanKey = $this->cleanKey($key);
return $this->cache
->tags([$this->entityName, 'global'])
return app('cache')->driver('translations')
->rememberForever("{$this->locale}.{$this->entityName}.findTranslationByKey.{$cleanKey}",
function () use ($key) {
return $this->repository->findTranslationByKey($key);
......@@ -74,7 +71,7 @@ class CacheTranslationDecorator extends BaseCacheDecorator implements Translatio
*/
public function updateFromImport($key, array $data)
{
$this->cache->tags($this->entityName)->flush();
app('cache')->driver('translations')->flush();
return $this->repository->updateFromImport($key, $data);
}
......@@ -87,7 +84,7 @@ class CacheTranslationDecorator extends BaseCacheDecorator implements Translatio
*/
public function updateTranslationToValue(TranslationTranslation $translationTranslation, $value)
{
$this->cache->tags($this->entityName)->flush();
app('cache')->driver('translations')->flush();
return $this->repository->updateTranslationToValue($translationTranslation, $value);
}
......@@ -101,4 +98,14 @@ class CacheTranslationDecorator extends BaseCacheDecorator implements Translatio
{
return str_replace(" ", "--", $key);
}
public function getTranslationsForGroupAndNamespace($locale, $group, $namespace)
{
return app('cache')->driver('translations')
->rememberForever("{$this->entityName}.findByKeyAndLocale.{$locale}.{$group}.[$namespace]",
function () use ($locale, $group, $namespace) {
return $this->repository->getTranslationsForGroupAndNamespace($locale, $group, $namespace);
}
);
}
}
......@@ -2,6 +2,7 @@
namespace Modules\Translation\Repositories\Eloquent;
use Illuminate\Database\Eloquent\Builder;
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
use Modules\Translation\Entities\TranslationTranslation;
use Modules\Translation\Repositories\TranslationRepository;
......@@ -24,6 +25,23 @@ class EloquentTranslationRepository extends EloquentBaseRepository implements Tr
return '';
}
public function getTranslationsForGroupAndNamespace($locale, $group, $namespace)
{
$start = $namespace . '::' . $group;
$test = $this->model->where('key', 'LIKE', "{$start}%")->whereHas('translations', function (Builder $query) use ($locale) {
$query->where('locale', $locale);
})->get();
$translations = [];
foreach ($test as $item) {
$key = str_replace($start . '.', '', $item->key);
$translations[$key] = $item->translate($locale)->value;
}
return $translations;
}
public function allFormatted()
{
$allRows = $this->all();
......
......@@ -48,4 +48,6 @@ interface TranslationRepository extends BaseRepository
* @return void
*/
public function updateTranslationToValue(TranslationTranslation $translationTranslation, $value);
public function getTranslationsForGroupAndNamespace($locale, $group, $namespace);
}
<?php
return [
'title' => [
'blocks' => 'Blöcke',
'create block' => 'Block erstellen',
'edit block' => 'Block bearbeiten',
],
'button' => [
'create block' => 'Block erstellen',
],
'table' => [
],
'form' => [
],
'messages' => [
'block created' => 'Block erfolgreich erstellt.',
'block not found' => 'Block nicht gefunden.',
'block updated' => 'Block erfolgreich aktualisiert.',
'block deleted' => 'Block erfolgreich gelöscht.',
],
'validation' => [
'body is required' => 'Der Inhalt ist erforderlich',
],
'online' => 'Online',
'name' => 'Namen',
'body' => 'Körper',
];
<?php
return [
'title' => [
'blocks' => 'Blocks',
'create block' => 'Create a block',
'edit block' => 'Edit a block',
],
'button' => [
'create block' => 'Create a block',
],
'table' => [
],
'form' => [
],
'messages' => [
'block created' => 'Block successfully created.',
'block not found' => 'Block not found.',
'block updated' => 'Block successfully updated.',
'block deleted' => 'Block successfully deleted.',
],
'validation' => [
'body is required' => 'The body is required',
],
'online' => 'Online',
'name' => 'Name',
'body' => 'Body',
'list resource' => 'List blocks',
'create resource' => 'Create blocks',
'edit resource' => 'Edit blocks',
'destroy resource' => 'Delete blocks',
];
<?php
return [
'title' => [
'blocks' => 'Bloques',
'create block' => 'Crear un bloque',
'edit block' => 'Editar un bloque',
],
'button' => [
'create block' => 'Crear un bloque',
],
'table' => [
],
'form' => [
],
'messages' => [
'block created' => 'Bloque creado éxitosamente.',
'block not found' => 'Bloque not found.',
'block updated' => 'Bloque actualizado éxitosamente.',
'block deleted' => 'Bloque eliminado éxitosamente.',
],
'validation' => [
'body is required' => 'El cuerpo es obligatorio.',
],
'online' => 'En línea',
'name' => 'Nombre',
'body' => 'Cuerpo',
];
<?php
return [
'title' => [
'blocks' => 'Blocks',
'create block' => 'Créer un block',
'edit block' => 'Édition d\'un block',
],
'button' => [
'create block' => 'Créer un block',
],
'table' => [
],
'form' => [
],
'messages' => [
'block created' => 'Block créé.',
'block not found' => 'Block non trouvé.',
'block updated' => 'Block mis à jour.',
'block deleted' => 'Block supprimé',
],
'validation' => [
'body is required' => 'Le contenu est requis',
],
'online' => 'En ligne',
'name' => 'Nom',
'body' => 'Contenu',
];
<?php
return [
'title' => [
'blocks' => 'Blokken',
'create block' => 'Creëer een blok',
'edit block' => 'Wijzig een blok',
],
'button' => [
'create block' => 'Creëer een blok',
],
'table' => [
],
'form' => [
],
'messages' => [
'block created' => 'Blok succesvol aangemaakt.',
'block not found' => 'Blok niet gevonden.',
'block updated' => 'Blok succesvol gewijzigd.',
'block deleted' => 'Blok succesvol verwijderd.',
],
'validation' => [
'body is required' => 'De inhoud is vereist',
],
'online' => 'Online',
'name' => 'Naam',
'body' => 'Inhoud',
];
<?php
return [
'title' => [
'blocks' => 'Blocos',
'create block' => 'Criar bloco',
'edit block' => 'Editar bloco',
],
'button' => [
'create block' => 'Criar bloco',
],
'table' => [
],
'form' => [
],
'messages' => [
'block created' => 'Bloco criado com sucesso.',
'block not found' => 'Bloco não encontrado.',
'block updated' => 'Bloco actualizado com successo.',
'block deleted' => 'Bloco eliminado com sucesso.',
],
'validation' => [
'body is required' => 'O corpo é obrigatório.',
],
'online' => 'Online',
'name' => 'Nome',
'body' => 'Corpo',
];
<?php
return [
'title' => [
'blocks' => 'Блоки',
'create block' => 'Создать блок',
'edit block' => 'Редактировать блок',
],
'button' => [
'create block' => 'Создать блок',
],
'table' => [
],
'form' => [
],
'messages' => [
'block created' => 'Блок успешно создан.',
'block not found' => 'Блок не найден.',
'block updated' => 'Блок успешно обновлён.',
'block deleted' => 'Блок успешно удалён.',
],
'validation' => [
'body is required' => 'The body is required',
],
'online' => 'Включен',
'name' => 'Название',
'body' => 'Содержание',
];
<?php
return [
'title' => [
'blocks' => 'Bloklar',
'create block' => 'Blok oluştur',
'edit block' => 'Bloğu düzenle',
],
'button' => [
'create block' => 'Blok oluştur',
],
'table' => [
],
'form' => [
],
'messages' => [
'block created' => 'Blok başarıyla oluşturuldu.',
'block not found' => 'Blok bulunamadı.',
'block updated' => 'Blok başarıyla güncellendi.',
'block deleted' => 'Blok başarıyla silindi.',
],
'validation' => [
'body is required' => 'İçerik gerekli',
],
'online' => 'Online',
'name' => 'Ad',
'body' => 'İçerik',
];
<?php
return [
'title' => [
'blocks' => '块元素',
'create block' => '创建块元素',
'edit block' => '编辑块元素',
],
'button' => [
'create block' => '创建块元素',
],
'table' => [
],
'form' => [
],
'messages' => [
'block created' => '块元素建立成功.',
'block not found' => '未找到块元素.',
'block updated' => '块元素已更新.',
'block deleted' => '块元素已删除.',
],
'validation' => [
'body is required' => '必须填写块元素的内容',
],
'online' => '在线',
'name' => '名称',
'body' => '内容',
'list resource' => '块元素列表',
'create resource' => '创建块元素',
'edit resource' => '编辑块元素',
'destroy resource' => '删除块元素',
];
<?php
return [
'title' => [
'category' => 'Kategorie',
'create category' => 'Kategorie erstellen',
'edit category' => 'Kategorie bearbeiten',
],
'button' => [
'create category' => 'Kategorie erstellen',
],
'table' => [
'created at' => 'Erstellt am',
'name' => 'Name',
'slug' => 'Slug',
],
'form' => [
'name' => 'Name',
'slug' => 'Slug',
],
'navigation' => [
'back to index' => 'Zurück zur Übersicht',
],
];
<?php
return [
/* Post management */
'post created' => 'Beitrag erfolgreich erstellt.',
'post not found' => 'Beitrag nicht gefunden.',
'post updated' => 'Beitrag erfolgreich aktualisiert.',
'post deleted' => 'Beitrag erfolgreich gelöscht.',
'title is required' => 'Titel ist erforderlich',
'slug is required' => 'Slug ist erforderlich',
'slug is unique' => 'Dieser Slug ist bereits vergeben',
/* Category management */
'category created' => 'Kategorie erfolgreich erstellt.',
'category not found' => 'Kategorie nicht gefunden.',
'category updated' => 'Kategorie erfolgreich aktualisiert.',
'category deleted' => 'Kategorie erfolgreich gelöscht.',
];
<?php
return [
'title' => [
'posts' => 'Beiträge',
'post' => 'Beitrag',
'create post' => 'Beitrag erstellen',
'edit post' => 'Beitrag bearbeiten',
],
'button' => [
'create post' => 'Beitrag erstellen',
],
'table' => [
'title' => 'Titel',
'slug' => 'Slug',
'status' => 'Status',
],
'form' => [
'title' => 'Title',
'slug' => 'Slug',
],
'navigation' => [
'back to index' => 'Zurück zur Übersicht',
],
'latest posts' => 'Letzte Beiträge',
];
<?php
return [
'posts-per-page' => 'Beiträge pro Seite',
'latest-posts-amount' => 'Anzahl neuster Beiträge',
];
<?php
return [
'draft' => 'Entwurf',
'pending review' => 'Überprüfung ausstehend',
'published' => 'Veröffentlicht',
'unpublished' => 'Unveröffentlicht',
];
<?php
return [
'title' => [
'category' => 'Categories',
'create category' => 'Create category',
'edit category' => 'Edit category',
],
'button' => [
'create category' => 'Create category',
],
'table' => [
'created at' => 'Create at',
'name' => 'Name',
'slug' => 'Slug',
],
'form' => [
'name' => 'Name',
'slug' => 'Slug',
],
'navigation' => [
'back to index' => 'Back to category index',
],
'list resource' => 'List categories',
'create resource' => 'Create categories',
'edit resource' => 'Edit categories',
'destroy resource' => 'Delete categories',
];
<?php
return [
/* Post management */
'post created' => 'Post successfully created.',
'post not found' => 'Post not found.',
'post updated' => 'Post successfully updated.',
'post deleted' => 'Post successfully deleted.',
'title is required' => 'Title is required',
'slug is required' => 'Slug is required',
'slug is unique' => 'This slug is already taken',
/* Category management */
'category created' => 'Category successfully created.',
'category not found' => 'Category not found.',
'category updated' => 'Category successfully updated.',
'category deleted' => 'Category successfully deleted.',
];
<?php
return [
'title' => [
'post' => 'Posts',
'create post' => 'Create post',
'edit post' => 'Edit post',
],
'button' => [
'create post' => 'Create post',
],
'table' => [
'title' => 'Title',
'slug' => 'Slug',
'status' => 'Status',
],
'form' => [
'title' => 'Title',
'slug' => 'Slug',
],
'navigation' => [
'back to index' => 'Back to posts index',
],
'latest posts' => 'Latest posts',
'list resource' => 'List posts',
'create resource' => 'Create posts',
'edit resource' => 'Edit posts',
'destroy resource' => 'Delete posts',
];
<?php
return [
'posts-per-page' => 'Posts per page',
'latest-posts-amount' => 'Amount of latest posts',
];
<?php
return [
'draft' => 'Draft',
'pending review' => 'Pending review',
'published' => 'Published',
'unpublished' => 'Unpublished',
];
<?php
return [
'title' => [
'tag' => 'Tags',
'create tag' => 'Create A Tag',
'edit tag' => 'Edit A Tag',
],
'button' => [
'create tag' => 'Create A Tag',
],
'table' => [
'name' => 'Name',
'slug' => 'Slug',
],
'form' => [
'name' => 'Name',
'slug' => 'Slug',
],
'messages' => [
],
'validation' => [
],
'list resource' => 'List tags',
'create resource' => 'Create tags',
'edit resource' => 'Edit tags',
'destroy resource' => 'Delete tags',
];
<?php
return [
'title' => [
'category' => 'Categorías',
'create category' => 'Crear categoría',
'edit category' => 'Editar categoría',
],
'button' => [
'create category' => 'Crear categoría',
],
'table' => [
'created at' => 'Creado el',
'name' => 'Nombre',
'slug' => 'URL amigable',
],
'form' => [
'name' => 'Nombre',
'slug' => 'URL amigable',
],
'navigation' => [
'back to index' => 'Regresar al índice de categorías',
],
];
<?php
return [
/* Post management */
'post created' => 'Entrada creada éxitosamente.',
'post not found' => 'Entrada no encontrada.',
'post updated' => 'Entrada actualizada éxitosamente.',
'post deleted' => 'Entrada eliminada éxitosamente.',
'title is required' => 'Título es requerido',
'slug is required' => 'URL amigable es requerido',
'slug is unique' => 'Este URL amigable ya existe',
/* Category management */
'category created' => 'Categoría creada éxitosamente.',
'category not found' => 'Categoría no encontrada.',
'category updated' => 'Categoría actualizada éxitosamente.',
'category deleted' => 'Categoría eliminada éxitosamente.',
];
<?php
return [
'title' => [
'post' => 'Entradas',
'create post' => 'Crear entrada',
'edit post' => 'Editar entrada',
],
'button' => [
'create post' => 'Crear entrada',
],
'table' => [
'title' => 'Título',
'slug' => 'URL amigable',
'status' => 'Estado',
],
'form' => [
'title' => 'Título',
'slug' => 'URL amigable',
],
'navigation' => [
'back to index' => 'Regresar al índice de entradas',
],
'latest posts' => 'Últimas entradas',
];
<?php
return [
'posts-per-page' => 'Entradas por página',
'latest-posts-amount' => 'Cantidad de últimas entradas',
];
<?php
return [
'draft' => 'Borrador',
'pending review' => 'Pendiente de revisión',
'published' => 'Publicado',
'unpublished' => 'No Publicado',
];
<?php
return [
'title' => [
'tag' => 'Etiquetas',
'create tag' => 'Crear una etiqueta',
'edit tag' => 'Editar una etiqueta',
],
'button' => [
'create tag' => 'Crear una etiqueta',
],
'table' => [
'name' => 'Nombre',
'slug' => 'URL amigable',
],
'form' => [
'name' => 'Nombre',
'slug' => 'URL amigable',
],
'messages' => [
],
'validation' => [
],
];
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.
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.
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.
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