murph-core/src/core/Resources/maker/controller/CrudController.tpl.php

155 lines
6.6 KiB
PHP
Raw Normal View History

2023-10-12 16:15:07 +02:00
<?php echo "<?php\n"; ?>
2022-03-13 19:32:32 +01:00
2023-10-12 16:15:07 +02:00
namespace <?php echo $namespace; ?>;
2022-03-13 19:32:32 +01:00
use App\Core\Controller\Admin\Crud\CrudController;
use App\Core\Crud\CrudConfiguration;
use App\Core\Crud\Field;
use App\Core\Entity\EntityInterface;
use App\Core\Manager\EntityManager;
2023-10-12 16:15:07 +02:00
use <?php echo $entity; ?> as Entity;
use <?php echo $factory; ?> as Factory;
use <?php echo $form; ?> as Type;
use <?php echo $repository_query; ?> as RepositoryQuery;
2024-03-25 15:27:06 +01:00
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
2022-03-13 19:32:32 +01:00
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Routing\Annotation\Route;
2023-10-12 16:15:07 +02:00
class <?php echo $class_name; ?> extends CrudController
2022-03-13 19:32:32 +01:00
{
protected ?CrudConfiguration $configuration = null;
2023-10-12 16:15:07 +02:00
#[Route(path: '/admin/<?php echo $route; ?>/{page}', name: 'admin_<?php echo $route; ?>_index', methods: ['GET'], requirements: ['page' => '\d+'])]
2022-03-13 19:32:32 +01:00
public function index(RepositoryQuery $query, Request $request, Session $session, int $page = 1): Response
{
return $this->doIndex($page, $query, $request, $session);
}
2023-10-12 16:15:07 +02:00
#[Route(path: '/admin/<?php echo $route; ?>/new', name: 'admin_<?php echo $route; ?>_new', methods: ['GET', 'POST'])]
2022-03-13 19:32:32 +01:00
public function new(Factory $factory, EntityManager $entityManager, Request $request): Response
{
return $this->doNew($factory->create(), $entityManager, $request);
}
2023-10-12 16:15:07 +02:00
#[Route(path: '/admin/<?php echo $route; ?>/show/{entity}', name: 'admin_<?php echo $route; ?>_show', methods: ['GET'])]
#[IsGranted('show', 'entity')]
2022-03-13 19:32:32 +01:00
public function show(Entity $entity): Response
{
return $this->doShow($entity);
}
2023-10-12 16:15:07 +02:00
#[Route(path: '/admin/<?php echo $route; ?>/filter', name: 'admin_<?php echo $route; ?>_filter', methods: ['GET'])]
2022-03-13 19:32:32 +01:00
public function filter(Session $session): Response
{
return $this->doFilter($session);
}
2023-10-12 16:15:07 +02:00
#[Route(path: '/admin/<?php echo $route; ?>/edit/{entity}', name: 'admin_<?php echo $route; ?>_edit', methods: ['GET', 'POST'])]
#[IsGranted('edit', 'entity')]
2022-03-13 19:32:32 +01:00
public function edit(Entity $entity, EntityManager $entityManager, Request $request): Response
{
return $this->doEdit($entity, $entityManager, $request);
}
2023-10-12 16:15:07 +02:00
#[Route(path: '/admin/<?php echo $route; ?>/inline_edit/{entity}/{context}/{label}', name: 'admin_<?php echo $route; ?>_inline_edit', methods: ['GET', 'POST'])]
#[IsGranted('edit', 'entity')]
public function inlineEdit(string $context, string $label, Entity $entity, EntityManager $entityManager, Request $request): Response
{
return $this->doInlineEdit($context, $label, $entity, $entityManager, $request);
}
2023-10-12 16:15:07 +02:00
#[Route(path: '/admin/<?php echo $route; ?>/sort/{page}', name: 'admin_<?php echo $route; ?>_sort', methods: ['POST'], requirements: ['page' => '\d+'])]
2022-03-13 19:32:32 +01:00
public function sort(RepositoryQuery $query, EntityManager $entityManager, Request $request, Session $session, int $page = 1): Response
{
return $this->doSort($page, $query, $entityManager, $request, $session);
}
2023-10-12 16:15:07 +02:00
#[Route(path: '/admin/<?php echo $route; ?>/batch/{page}', name: 'admin_<?php echo $route; ?>_batch', methods: ['POST'], requirements: ['page' => '\d+'])]
2022-03-13 19:32:32 +01:00
public function batch(RepositoryQuery $query, EntityManager $entityManager, Request $request, Session $session, int $page = 1): Response
{
return $this->doBatch($page, $query, $entityManager, $request, $session);
}
2023-10-12 16:15:07 +02:00
#[Route(path: '/admin/<?php echo $route; ?>/delete/{entity}', name: 'admin_<?php echo $route; ?>_delete', methods: ['DELETE', 'POST'])]
#[IsGranted('delete', 'entity')]
2022-03-13 19:32:32 +01:00
public function delete(Entity $entity, EntityManager $entityManager, Request $request): Response
{
return $this->doDelete($entity, $entityManager, $request);
}
protected function getConfiguration(): CrudConfiguration
{
if ($this->configuration) {
return $this->configuration;
}
return $this->configuration = CrudConfiguration::create()
2023-10-12 16:15:07 +02:00
->setPageTitle('index', 'List of <?php echo $entity; ?>')
2022-03-13 19:32:32 +01:00
->setPageTitle('edit', 'Edition of {id}')
2023-10-12 16:15:07 +02:00
->setPageTitle('new', 'New <?php echo $entity; ?>')
2022-03-13 19:32:32 +01:00
->setPageTitle('show', 'View of {id}')
2023-10-12 16:15:07 +02:00
->setPageRoute('index', 'admin_<?php echo $route; ?>_index')
->setPageRoute('new', 'admin_<?php echo $route; ?>_new')
->setPageRoute('edit', 'admin_<?php echo $route; ?>_edit')
->setPageRoute('inline_edit', 'admin_<?php echo $route; ?>_inline_edit')
->setPageRoute('show', 'admin_<?php echo $route; ?>_show')
->setPageRoute('sort', 'admin_<?php echo $route; ?>_sort')
->setPageRoute('batch', 'admin_<?php echo $route; ?>_batch')
->setPageRoute('delete', 'admin_<?php echo $route; ?>_delete')
->setPageRoute('filter', 'admin_<?php echo $route; ?>_filter')
2022-03-13 19:32:32 +01:00
->setForm('edit', Type::class)
2022-03-13 19:32:32 +01:00
->setForm('new', Type::class)
2023-10-12 16:15:07 +02:00
->setView('form', 'admin/<?php echo $route; ?>_admin/_form.html.twig')
->setView('show_entity', 'admin/<?php echo $route; ?>_admin/_show.html.twig')
2022-03-13 19:32:32 +01:00
// ->setForm('filter', Type::class)
// ->setMaxPerPage('index', 20)
// ->setIsSortableCollection('index', false)
// ->setSortableCollectionProperty('sortOrder')
// ->setAction('index', 'new', true)
// ->setAction('index', 'show', true)
// ->setAction('index', 'edit', true)
// ->setAction('index', 'delete', true)
// ->setDoubleClick('index', false)
2022-03-13 19:32:32 +01:00
// ->setAction('edit', 'back', true)
// ->setAction('edit', 'show', true)
// ->setAction('edit', 'delete', true)
// ->setAction('show', 'back', true)
// ->setAction('show', 'edit', true)
->setField('index', 'Entity', Field\TextField::class, [
'property_builder' => function (EntityInterface $entity) {
try {
return (string) $entity;
} catch (\Error $e) {
return $entity->getId();
}
},
])
// ->setField('index', 'Foo', Field\TextField::class, [
// 'property' => 'foo',
2022-03-13 19:32:32 +01:00
// ])
// ->setBatchAction('index', 'delete', 'Delete', function(EntityInterface $entity, EntityManager $manager) {
// $manager->delete($entity);
// })
;
}
protected function getSection(): string
{
2023-10-12 16:15:07 +02:00
return '<?php echo $route; ?>';
2022-03-13 19:32:32 +01:00
}
}