52 lines
1.8 KiB
PHP
52 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace IriksIT\Manager\Modules\Posts;
|
|
|
|
use IriksIT\Manager\Models\Post;
|
|
use IriksIT\Manager\Modules\BaseModule;
|
|
use IriksIT\Manager\Support\MediaUsage;
|
|
use IriksIT\Manager\Support\Permission;
|
|
|
|
class PostsModule extends BaseModule
|
|
{
|
|
public function key(): string
|
|
{
|
|
return 'posts';
|
|
}
|
|
|
|
public function label(): string
|
|
{
|
|
return 'Posts';
|
|
}
|
|
|
|
public function enabledByDefault(): bool
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public function permissions(): array
|
|
{
|
|
return [
|
|
new Permission('posts.view', 'See the posts, drafts included', 'Posts'),
|
|
new Permission('posts.write', 'Write posts: create drafts and change them', 'Posts', needs: ['posts.view']),
|
|
new Permission('posts.publish', 'Publish, schedule and unpublish posts, and change posts that are live', 'Posts', needs: ['posts.view', 'posts.write']),
|
|
new Permission('posts.delete', 'Delete posts (one that is live only together with publishing)', 'Posts', needs: ['posts.view']),
|
|
new Permission('posts.labels', 'Manage the categories and tags: make them, and rename, merge and remove them on all posts', 'Posts', needs: ['posts.view']),
|
|
];
|
|
}
|
|
|
|
public function navigation(): array
|
|
{
|
|
return [
|
|
['label' => 'Posts', 'route' => 'manager.posts.index', 'permission' => 'posts.view'],
|
|
['label' => 'Categories and tags', 'route' => 'manager.labels.index', 'permission' => 'posts.labels'],
|
|
];
|
|
}
|
|
|
|
/** Where the media library looks for the use of a file: the texts of the posts. */
|
|
public function boot(): void
|
|
{
|
|
app(MediaUsage::class)->register(fn () => Post::query()->get(['body', 'excerpt', 'cover_image'])->flatMap(fn (Post $row) => array_values($row->only(['body', 'excerpt', 'cover_image']))));
|
|
}
|
|
}
|