Skip to content

Commit

Permalink
Merge branch '2.0'
Browse files Browse the repository at this point in the history
* 2.0:
  Importing class
  Preparing 2.2.0 release
  Register the blog sidebar via event handler
  Preparing 2.1.0 release
  Adding an event hook PostContentIsRendering
  CS: PSR1/2 & removing grumphp
  Creating new hook when a post is updating
  Creating new hook when post is creating
  Make the tag test more robust
  Using new @editor directive for blog post content field
  Adding new languages to blog
  Updating block module translations
  • Loading branch information
nWidart committed Sep 20, 2017
2 parents 51a3bb4 + a5cd6fe commit 54158bf
Show file tree
Hide file tree
Showing 51 changed files with 652 additions and 85 deletions.
8 changes: 8 additions & 0 deletions Entities/PostTranslation.php
Expand Up @@ -3,10 +3,18 @@
namespace Modules\Blog\Entities;

use Illuminate\Database\Eloquent\Model;
use Modules\Blog\Events\PostContentIsRendering;

class PostTranslation extends Model
{
public $timestamps = false;
protected $fillable = ['title', 'slug', 'content'];
protected $table = 'blog__post_translations';

public function getContentAttribute($content)
{
event($event = new PostContentIsRendering($content));

return $event->getContent();
}
}
@@ -1,35 +1,19 @@
<?php

namespace Modules\Blog\Sidebar;
namespace Modules\Blog\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 RegisterBlogSidebar extends AbstractAdminSidebar
{
/**
* @var Authentication
* Method used to define your sidebar menu groups and items
* @param \Maatwebsite\Sidebar\Menu $menu
* @return \Maatwebsite\Sidebar\Menu
*/
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)
public function extendWith(\Maatwebsite\Sidebar\Menu $menu)
{
$menu->group(trans('core::sidebar.content'), function (Group $group) {
$group->item(trans('blog::blog.title'), function (Item $item) {
Expand Down
47 changes: 47 additions & 0 deletions Events/PostContentIsRendering.php
@@ -0,0 +1,47 @@
<?php

namespace Modules\Blog\Events;

class PostContentIsRendering
{
/**
* @var string The body of the page to render
*/
private $content;
private $original;

public function __construct($content)
{
$this->content = $content;
$this->original = $content;
}

/**
* @return string
*/
public function getContent()
{
return $this->content;
}

/**
* @param string $content
*/
public function setContent($content)
{
$this->content = $content;
}

/**
* @return mixed
*/
public function getOriginal()
{
return $this->original;
}

public function __toString()
{
return $this->getContent();
}
}
10 changes: 10 additions & 0 deletions Events/PostIsCreating.php
@@ -0,0 +1,10 @@
<?php

namespace Modules\Blog\Events;

use Modules\Core\Contracts\EntityIsChanging;
use Modules\Core\Events\AbstractEntityHook;

class PostIsCreating extends AbstractEntityHook implements EntityIsChanging
{
}
30 changes: 30 additions & 0 deletions Events/PostIsUpdating.php
@@ -0,0 +1,30 @@
<?php

namespace Modules\Blog\Events;

use Modules\Blog\Entities\Post;
use Modules\Core\Contracts\EntityIsChanging;
use Modules\Core\Events\AbstractEntityHook;

class PostIsUpdating extends AbstractEntityHook implements EntityIsChanging
{
/**
* @var Post
*/
private $post;

public function __construct(Post $post, array $data)
{
parent::__construct($data);

$this->post = $post;
}

/**
* @return Post
*/
public function getPost()
{
return $this->post;
}
}
10 changes: 9 additions & 1 deletion Providers/BlogServiceProvider.php
Expand Up @@ -6,6 +6,7 @@
use Modules\Blog\Entities\Category;
use Modules\Blog\Entities\Post;
use Modules\Blog\Entities\Tag;
use Modules\Blog\Events\Handlers\RegisterBlogSidebar;
use Modules\Blog\Repositories\Cache\CacheCategoryDecorator;
use Modules\Blog\Repositories\Cache\CachePostDecorator;
use Modules\Blog\Repositories\Cache\CacheTagDecorator;
Expand All @@ -15,12 +16,14 @@
use Modules\Blog\Repositories\Eloquent\EloquentTagRepository;
use Modules\Blog\Repositories\PostRepository;
use Modules\Blog\Repositories\TagRepository;
use Modules\Core\Events\BuildingSidebar;
use Modules\Core\Traits\CanGetSidebarClassForModule;
use Modules\Core\Traits\CanPublishConfiguration;
use Modules\Media\Image\ThumbnailManager;

class BlogServiceProvider extends ServiceProvider
{
use CanPublishConfiguration;
use CanPublishConfiguration, CanGetSidebarClassForModule;
/**
* Indicates if loading of the provider is deferred.
*
Expand All @@ -36,6 +39,11 @@ class BlogServiceProvider extends ServiceProvider
public function register()
{
$this->registerBindings();

$this->app['events']->listen(
BuildingSidebar::class,
$this->getSidebarClassForModule('blog', RegisterBlogSidebar::class)
);
}

public function boot()
Expand Down
12 changes: 9 additions & 3 deletions Repositories/Cache/CachePostDecorator.php
Expand Up @@ -24,7 +24,9 @@ public function latest($amount = 5)
{
return $this->cache
->tags([$this->entityName, 'global'])
->remember("{$this->locale}.{$this->entityName}.latest.{$amount}", $this->cacheTime,
->remember(
"{$this->locale}.{$this->entityName}.latest.{$amount}",
$this->cacheTime,
function () use ($amount) {
return $this->repository->latest($amount);
}
Expand All @@ -42,7 +44,9 @@ public function getPreviousOf($post)

return $this->cache
->tags([$this->entityName, 'global'])
->remember("{$this->locale}.{$this->entityName}.getPreviousOf.{$postId}", $this->cacheTime,
->remember(
"{$this->locale}.{$this->entityName}.getPreviousOf.{$postId}",
$this->cacheTime,
function () use ($post) {
return $this->repository->getPreviousOf($post);
}
Expand All @@ -60,7 +64,9 @@ public function getNextOf($post)

return $this->cache
->tags([$this->entityName, 'global'])
->remember("{$this->locale}.{$this->entityName}.getNextOf.{$postId}", $this->cacheTime,
->remember(
"{$this->locale}.{$this->entityName}.getNextOf.{$postId}",
$this->cacheTime,
function () use ($post) {
return $this->repository->getNextOf($post);
}
Expand Down
4 changes: 3 additions & 1 deletion Repositories/Cache/CacheTagDecorator.php
Expand Up @@ -27,7 +27,9 @@ public function findByName($name)
{
return $this->cache
->tags([$this->entityName, 'global'])
->remember("{$this->locale}.{$this->entityName}.findByName.{$name}", $this->cacheTime,
->remember(
"{$this->locale}.{$this->entityName}.findByName.{$name}",
$this->cacheTime,
function () use ($name) {
return $this->repository->findByName($name);
}
Expand Down
8 changes: 6 additions & 2 deletions Repositories/Eloquent/EloquentPostRepository.php
Expand Up @@ -5,6 +5,8 @@
use Illuminate\Database\Eloquent\Builder;
use Modules\Blog\Entities\Post;
use Modules\Blog\Entities\Status;
use Modules\Blog\Events\PostIsCreating;
use Modules\Blog\Events\PostIsUpdating;
use Modules\Blog\Events\PostWasCreated;
use Modules\Blog\Events\PostWasDeleted;
use Modules\Blog\Events\PostWasUpdated;
Expand Down Expand Up @@ -39,7 +41,8 @@ public function all()
*/
public function update($post, $data)
{
$post->update($data);
event($event = new PostIsUpdating($post, $data));
$post->update($event->getAttributes());

$post->tags()->sync(array_get($data, 'tags', []));

Expand All @@ -55,7 +58,8 @@ public function update($post, $data)
*/
public function create($data)
{
$post = $this->model->create($data);
event($event = new PostIsCreating($data));
$post = $this->model->create($event->getAttributes());

$post->tags()->sync(array_get($data, 'tags', []));

Expand Down
4 changes: 2 additions & 2 deletions Resources/lang/de/category.php
Expand Up @@ -11,11 +11,11 @@
],
'table' => [
'created at' => 'Erstellt am',
'name' => 'Namen',
'name' => 'Name',
'slug' => 'Slug',
],
'form' => [
'name' => 'Namen',
'name' => 'Name',
'slug' => 'Slug',
],
'navigation' => [
Expand Down
11 changes: 6 additions & 5 deletions Resources/lang/de/post.php
Expand Up @@ -2,15 +2,16 @@

return [
'title' => [
'post' => 'Beiträge',
'create post' => 'Beiträge erstellen',
'edit post' => 'Beiträge bearbeiten',
'posts' => 'Beiträge',
'post' => 'Beitrag',
'create post' => 'Beitrag erstellen',
'edit post' => 'Beitrag bearbeiten',
],
'button' => [
'create post' => 'Beiträge erstellen',
'create post' => 'Beitrag erstellen',
],
'table' => [
'title' => 'Title',
'title' => 'Titel',
'slug' => 'Slug',
'status' => 'Status',
],
Expand Down
4 changes: 4 additions & 0 deletions Resources/lang/en/category.php
Expand Up @@ -21,4 +21,8 @@
'navigation' => [
'back to index' => 'Back to category index',
],
'list resource' => 'List categories',
'create resource' => 'Create categories',
'edit resource' => 'Edit categories',
'destroy resource' => 'Delete categories',
];
5 changes: 5 additions & 0 deletions Resources/lang/en/post.php
Expand Up @@ -17,9 +17,14 @@
'form' => [
'title' => 'Title',
'slug' => 'Slug',
'content' => 'Content',
],
'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',
];
1 change: 0 additions & 1 deletion Resources/lang/en/settings.php
Expand Up @@ -3,5 +3,4 @@
return [
'posts-per-page' => 'Posts per page',
'latest-posts-amount' => 'Amount of latest posts',
'widget-posts-amount' => 'Amount of latest posts to show on the dashboard widget',
];
4 changes: 4 additions & 0 deletions Resources/lang/en/tag.php
Expand Up @@ -21,4 +21,8 @@
],
'validation' => [
],
'list resource' => 'List tags',
'create resource' => 'Create tags',
'edit resource' => 'Edit tags',
'destroy resource' => 'Delete tags',
];
24 changes: 24 additions & 0 deletions Resources/lang/es/tag.php
@@ -0,0 +1,24 @@
<?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' => [
],
];
3 changes: 2 additions & 1 deletion Resources/lang/fr/category.php
Expand Up @@ -4,12 +4,13 @@
'title' => [
'category' => 'Catégories',
'create category' => 'Création d\'une catégorie',
'edit category' => 'Edition d\'une catégorie',
'edit category' => 'Édition d\'une catégorie',
],
'button' => [
'create category' => 'Création de catégorie',
],
'table' => [
'created at' => 'Créé le',
'name' => 'Nom',
'slug' => 'Slug',
],
Expand Down
8 changes: 4 additions & 4 deletions Resources/lang/fr/messages.php
Expand Up @@ -2,10 +2,10 @@

return [
/* Post management */
'post created' => 'Post créé',
'post not found' => 'Post non trouvé',
'post updated' => 'Post mis à jour',
'post deleted' => 'Post supprimé',
'post created' => 'Article créé',
'post not found' => 'Article non trouvé',
'post updated' => 'Article mis à jour',
'post deleted' => 'Article supprimé',

'title is required' => 'Le titre est requis',
'slug is required' => 'Le slug est requis',
Expand Down

0 comments on commit 54158bf

Please sign in to comment.