add builder as post editor
This commit is contained in:
parent
b86f3096e1
commit
7e6d230e17
|
@ -2,31 +2,30 @@
|
|||
|
||||
namespace App\Controller\Blog;
|
||||
|
||||
use App\Analytic\DateRangeAnalytic;
|
||||
use App\Core\Controller\Admin\Crud\CrudController;
|
||||
use App\Core\Crud\CrudConfiguration;
|
||||
use App\Core\Crud\Field\DatetimeField;
|
||||
use App\Core\Crud\Field\TextField;
|
||||
use App\Core\Entity\EntityInterface;
|
||||
use App\Core\Form\FileUploadHandler;
|
||||
use App\Core\Manager\EntityManager;
|
||||
use App\Core\Repository\Site\NodeRepository;
|
||||
use App\Entity\Blog\Post;
|
||||
use App\Entity\Blog\Post as Entity;
|
||||
use App\Factory\Blog\PostFactory as EntityFactory;
|
||||
use App\Form\Blog\Filter\PostFilterType;
|
||||
use App\Form\Blog\PostType;
|
||||
use App\Form\Blog\PostType as EntityType;
|
||||
use App\Repository\Blog\PostRepositoryQuery as RepositoryQuery;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
||||
use Symfony\Component\Form\Form;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Form\Form;
|
||||
use App\Core\Entity\EntityInterface;
|
||||
use App\Entity\Blog\Post;
|
||||
use App\Analytic\DateRangeAnalytic;
|
||||
use App\Core\Repository\Site\NodeRepository;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
|
||||
#[Route(path: '/admin/blog/post')]
|
||||
class PostAdminController extends CrudController
|
||||
|
@ -68,7 +67,7 @@ class PostAdminController extends CrudController
|
|||
'attr' => ['class' => 'miw-400'],
|
||||
])
|
||||
->setField('index', 'ID', TextField::class, [
|
||||
'property_builder' => function(EntityInterface $entity) {
|
||||
'property_builder' => function (EntityInterface $entity) {
|
||||
return sprintf('#%d', $entity->getId());
|
||||
},
|
||||
'sort' => ['id', '.id'],
|
||||
|
@ -85,7 +84,7 @@ class PostAdminController extends CrudController
|
|||
'format' => 'd/m/Y H:i',
|
||||
'sort' => ['publishedAt', '.publishedAt'],
|
||||
'attr' => ['class' => 'miw-200'],
|
||||
'inline_form' => function(FormBuilderInterface $builder) {
|
||||
'inline_form' => function (FormBuilderInterface $builder) {
|
||||
$builder->add(
|
||||
'publishedAt',
|
||||
DateTimeType::class,
|
||||
|
@ -107,7 +106,7 @@ class PostAdminController extends CrudController
|
|||
'view' => 'blog/post_admin/field/status.html.twig',
|
||||
'sort' => ['status', '.status'],
|
||||
'attr' => ['class' => 'miw-100'],
|
||||
'inline_form' => function(FormBuilderInterface $builder) {
|
||||
'inline_form' => function (FormBuilderInterface $builder) {
|
||||
$builder->add(
|
||||
'status',
|
||||
ChoiceType::class,
|
||||
|
@ -125,15 +124,15 @@ class PostAdminController extends CrudController
|
|||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
},
|
||||
])
|
||||
->setBatchAction('index', 'delete', 'Delete', function(EntityInterface $entity, EntityManager $manager) {
|
||||
->setBatchAction('index', 'delete', 'Delete', function (EntityInterface $entity, EntityManager $manager) {
|
||||
$manager->delete($entity);
|
||||
})
|
||||
->setBatchAction('index', 'draft', 'Statut : publier', function(EntityInterface $entity, EntityManager $manager) {
|
||||
->setBatchAction('index', 'draft', 'Statut : publier', function (EntityInterface $entity, EntityManager $manager) {
|
||||
$manager->update($entity->setStatus(Post::PUBLISHED));
|
||||
})
|
||||
->setBatchAction('index', 'publish', 'Statut : brouillon', function(EntityInterface $entity, EntityManager $manager) {
|
||||
->setBatchAction('index', 'publish', 'Statut : brouillon', function (EntityInterface $entity, EntityManager $manager) {
|
||||
$manager->update($entity->setStatus(Post::DRAFT));
|
||||
})
|
||||
;
|
||||
|
@ -152,7 +151,7 @@ class PostAdminController extends CrudController
|
|||
$factory->create($this->getUser()),
|
||||
$entityManager,
|
||||
$request,
|
||||
function(Entity $entity, Form $form, Request $request) use ($fileUpload) {
|
||||
function (Entity $entity, Form $form, Request $request) use ($fileUpload) {
|
||||
$directory = 'uploads/post/'.date('Y');
|
||||
|
||||
$fileUpload->handleForm(
|
||||
|
@ -173,7 +172,7 @@ class PostAdminController extends CrudController
|
|||
$entity,
|
||||
$entityManager,
|
||||
$request,
|
||||
function(Entity $entity, Form $form, Request $request) use ($fileUpload) {
|
||||
function (Entity $entity, Form $form, Request $request) use ($fileUpload) {
|
||||
$directory = 'uploads/post/'.date('Y');
|
||||
|
||||
$fileUpload->handleForm(
|
||||
|
@ -187,7 +186,7 @@ class PostAdminController extends CrudController
|
|||
);
|
||||
}
|
||||
|
||||
#[Route(path: "/inline_edit/{entity}/{context}/{label}", name: 'admin_blog_post_inline_edit', methods: ['GET', 'POST'])]
|
||||
#[Route(path: '/inline_edit/{entity}/{context}/{label}', name: 'admin_blog_post_inline_edit', methods: ['GET', 'POST'])]
|
||||
public function inlineEdit(string $context, string $label, Entity $entity, EntityManager $entityManager, Request $request): Response
|
||||
{
|
||||
return $this->doInlineEdit($context, $label, $entity, $entityManager, $request);
|
||||
|
@ -268,8 +267,7 @@ class PostAdminController extends CrudController
|
|||
DateRangeAnalytic $analytic,
|
||||
NodeRepository $nodeRepository,
|
||||
string $range = '7days'
|
||||
): Response
|
||||
{
|
||||
): Response {
|
||||
if (!in_array($range, ['7days', '30days', '90days', '1year'])) {
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ use App\Core\Form\Type\EditorJsTextareaType;
|
|||
use App\Core\Form\FileManager\FilePickerType;
|
||||
use App\Core\Form\Type\CollectionType as MurphCollectionType;
|
||||
use App\Form\MarkdownType;
|
||||
use App\Core\Form\Type\BuilderType;
|
||||
|
||||
class PostType extends AbstractType
|
||||
{
|
||||
|
@ -52,6 +53,7 @@ class PostType extends AbstractType
|
|||
'required' => true,
|
||||
'choices' => [
|
||||
'Markdown' => 'markdown',
|
||||
'Builder' => 'builder',
|
||||
'HTML' => 'html',
|
||||
'Editor JS' => 'editorjs',
|
||||
],
|
||||
|
@ -63,6 +65,7 @@ class PostType extends AbstractType
|
|||
|
||||
$types = [
|
||||
'markdown' => MarkdownType::class,
|
||||
'builder' => BuilderType::class,
|
||||
'html' => MarkdownType::class,
|
||||
'editorjs' => EditorJsTextareaType::class,
|
||||
];
|
||||
|
|
|
@ -55,6 +55,8 @@
|
|||
{{- post.content|murph_url|file_attributes|post -}}
|
||||
{% elseif post.contentFormat == 'markdown' %}
|
||||
{{- post.content|murph_url|file_attributes|markdown('post')|lazy_load -}}
|
||||
{% elseif post.contentFormat == 'builder' %}
|
||||
{{- post.content|block_to_html|lazy_load -}}
|
||||
{% elseif post.contentFormat == 'editorjs' %}
|
||||
{{- post.content|murph_url|file_attributes|editorjs_to_html|raw -}}
|
||||
{% endif %}
|
||||
|
|
Loading…
Reference in a new issue