backports murph-skeleton
This commit is contained in:
parent
ebbe787bac
commit
d5d7ef730b
|
@ -31,7 +31,7 @@ abstract class CrudController extends AdminController
|
||||||
$configuration = $this->getConfiguration();
|
$configuration = $this->getConfiguration();
|
||||||
|
|
||||||
$this->applySort('index', $query, $request);
|
$this->applySort('index', $query, $request);
|
||||||
$this->updatefilters($request, $session);
|
$this->updateFilters($request, $session);
|
||||||
|
|
||||||
$pager = $query
|
$pager = $query
|
||||||
->usefilters($this->filters)
|
->usefilters($this->filters)
|
||||||
|
|
|
@ -143,9 +143,19 @@ class NodeAdminController extends AdminController
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$page = $entity->getPage();
|
||||||
|
|
||||||
|
if ($page !== null) {
|
||||||
|
$pageConfiguration = $pageLocator->getPages()[get_class($page)] ?? null;
|
||||||
|
} else {
|
||||||
|
$pageConfiguration = null;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->render('@Core/site/node_admin/edit.html.twig', [
|
return $this->render('@Core/site/node_admin/edit.html.twig', [
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'entity' => $entity,
|
'entity' => $entity,
|
||||||
|
'page' => $page,
|
||||||
|
'pageConfiguration' => $pageConfiguration,
|
||||||
'tab' => $tab,
|
'tab' => $tab,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ use Symfony\Component\HttpFoundation\Session\Session;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
use App\Core\Event\Page\PageEditEvent;
|
use App\Core\Event\Page\PageEditEvent;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
use App\Core\Entity\EntityInterface;
|
||||||
|
|
||||||
class PageAdminController extends CrudController
|
class PageAdminController extends CrudController
|
||||||
{
|
{
|
||||||
|
@ -76,6 +77,14 @@ class PageAdminController extends CrudController
|
||||||
return $this->doDelete($entity, $entityManager, $request);
|
return $this->doDelete($entity, $entityManager, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/admin/site/page/batch/{page}", name="admin_site_page_batch", methods={"POST"}, requirements={"page":"\d+"})
|
||||||
|
*/
|
||||||
|
public function batch(int $page = 1, RepositoryQuery $query, EntityManager $entityManager, Request $request, Session $session): Response
|
||||||
|
{
|
||||||
|
return $this->doBatch($page, $query, $entityManager, $request, $session);
|
||||||
|
}
|
||||||
|
|
||||||
protected function getConfiguration(): CrudConfiguration
|
protected function getConfiguration(): CrudConfiguration
|
||||||
{
|
{
|
||||||
return CrudConfiguration::create()
|
return CrudConfiguration::create()
|
||||||
|
@ -87,6 +96,7 @@ class PageAdminController extends CrudController
|
||||||
->setPageRoute('edit', 'admin_site_page_edit')
|
->setPageRoute('edit', 'admin_site_page_edit')
|
||||||
->setPageRoute('delete', 'admin_site_page_delete')
|
->setPageRoute('delete', 'admin_site_page_delete')
|
||||||
->setPageRoute('filter', 'admin_site_page_filter')
|
->setPageRoute('filter', 'admin_site_page_filter')
|
||||||
|
->setPageRoute('batch', 'admin_site_page_batch')
|
||||||
|
|
||||||
->setForm('edit', Type::class, [])
|
->setForm('edit', Type::class, [])
|
||||||
->setForm('filter', FilterType::class)
|
->setForm('filter', FilterType::class)
|
||||||
|
@ -99,6 +109,7 @@ class PageAdminController extends CrudController
|
||||||
->setField('index', 'Name', Field\TextField::class, [
|
->setField('index', 'Name', Field\TextField::class, [
|
||||||
'property' => 'name',
|
'property' => 'name',
|
||||||
'sort' => ['name', '.name'],
|
'sort' => ['name', '.name'],
|
||||||
|
'attr' => ['class' => 'col-4'],
|
||||||
])
|
])
|
||||||
->setField('index', 'Elements', Field\TextField::class, [
|
->setField('index', 'Elements', Field\TextField::class, [
|
||||||
'view' => '@Core/site/page_admin/fields/nodes.html.twig',
|
'view' => '@Core/site/page_admin/fields/nodes.html.twig',
|
||||||
|
@ -110,7 +121,11 @@ class PageAdminController extends CrudController
|
||||||
->orderBy('navigation.label', $direction)
|
->orderBy('navigation.label', $direction)
|
||||||
;
|
;
|
||||||
}],
|
}],
|
||||||
|
'attr' => ['class' => 'col-6'],
|
||||||
])
|
])
|
||||||
|
->setBatchAction('index', 'delete', 'Delete', function(EntityInterface $entity, EntityManager $manager) {
|
||||||
|
$manager->delete($entity);
|
||||||
|
})
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
|
||||||
class PageFilterType extends AbstractType
|
class PageFilterType extends AbstractType
|
||||||
{
|
{
|
||||||
|
@ -47,6 +48,19 @@ class PageFilterType extends AbstractType
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$builder->add(
|
||||||
|
'isAssociated',
|
||||||
|
ChoiceType::class,
|
||||||
|
[
|
||||||
|
'label' => 'Associated',
|
||||||
|
'choices' => [
|
||||||
|
'Anyway' => -1,
|
||||||
|
'No' => 0,
|
||||||
|
'Yes' => 1,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver)
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
|
|
|
@ -17,6 +17,7 @@ abstract class RepositoryQuery
|
||||||
protected QueryBuilder $query;
|
protected QueryBuilder $query;
|
||||||
protected PaginatorInterface $paginator;
|
protected PaginatorInterface $paginator;
|
||||||
protected string $id;
|
protected string $id;
|
||||||
|
protected array $forcedFilterHandlers;
|
||||||
|
|
||||||
public function __construct(ServiceEntityRepository $repository, string $id, PaginatorInterface $paginator = null)
|
public function __construct(ServiceEntityRepository $repository, string $id, PaginatorInterface $paginator = null)
|
||||||
{
|
{
|
||||||
|
@ -24,6 +25,7 @@ abstract class RepositoryQuery
|
||||||
$this->query = $repository->createQueryBuilder($id);
|
$this->query = $repository->createQueryBuilder($id);
|
||||||
$this->paginator = $paginator;
|
$this->paginator = $paginator;
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
|
$this->forcedFilterHandlers = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __call(string $name, $params): self
|
public function __call(string $name, $params): self
|
||||||
|
@ -81,7 +83,9 @@ abstract class RepositoryQuery
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_int($value) || is_bool($value)) {
|
if (in_array($name, $this->forcedFilterHandlers)) {
|
||||||
|
$this->filterHandler($name, $value);
|
||||||
|
} elseif (is_int($value) || is_bool($value)) {
|
||||||
$this->andWhere('.'.$name.' = :'.$name);
|
$this->andWhere('.'.$name.' = :'.$name);
|
||||||
$this->setParameter(':'.$name, $value);
|
$this->setParameter(':'.$name, $value);
|
||||||
} elseif (is_string($value)) {
|
} elseif (is_string($value)) {
|
||||||
|
|
|
@ -13,11 +13,13 @@ class NodeRepository extends NestedTreeRepository
|
||||||
parent::__construct($manager, $manager->getClassMetadata(Node::class));
|
parent::__construct($manager, $manager->getClassMetadata(Node::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function urlExists($url, Node $node)
|
public function urlExists($url, Node $node): bool
|
||||||
{
|
{
|
||||||
$query = $this->createQueryBuilder('n')
|
$query = $this->createQueryBuilder('n')
|
||||||
->join('n.menu', 'm')
|
->join('n.menu', 'm')
|
||||||
->where('n.url = :url')
|
->where('n.url = :url')
|
||||||
|
->andWhere('n.disableUrl = 0')
|
||||||
|
->andWhere('n.aliasNode is null')
|
||||||
->andWhere('m.navigation = :navigation')
|
->andWhere('m.navigation = :navigation')
|
||||||
->setParameter(':url', $url)
|
->setParameter(':url', $url)
|
||||||
->setParameter(':navigation', $node->getMenu()->getNavigation())
|
->setParameter(':navigation', $node->getMenu()->getNavigation())
|
||||||
|
@ -32,7 +34,7 @@ class NodeRepository extends NestedTreeRepository
|
||||||
|
|
||||||
return $query->getQuery()
|
return $query->getQuery()
|
||||||
->setMaxResults(1)
|
->setMaxResults(1)
|
||||||
->getOneOrNullResult()
|
->getOneOrNullResult() !== null
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,11 @@ class PageRepositoryQuery extends RepositoryQuery
|
||||||
public function __construct(PageRepository $repository, PaginatorInterface $paginator)
|
public function __construct(PageRepository $repository, PaginatorInterface $paginator)
|
||||||
{
|
{
|
||||||
parent::__construct($repository, 'p', $paginator);
|
parent::__construct($repository, 'p', $paginator);
|
||||||
|
|
||||||
|
$this->forcedFilterHandlers[] = 'isAssociated';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function filterByNavigation(Navigation $navigation)
|
public function filterByNavigation(Navigation $navigation): self
|
||||||
{
|
{
|
||||||
return $this
|
return $this
|
||||||
->leftJoin('.nodes', 'node')
|
->leftJoin('.nodes', 'node')
|
||||||
|
@ -29,7 +31,7 @@ class PageRepositoryQuery extends RepositoryQuery
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function filterById($id)
|
public function filterById($id): self
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->where('.id = :id')
|
->where('.id = :id')
|
||||||
|
@ -39,12 +41,37 @@ class PageRepositoryQuery extends RepositoryQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function withAssociation(bool $isAssociated): self
|
||||||
|
{
|
||||||
|
$entities = $this->create()->find();
|
||||||
|
$ids = [];
|
||||||
|
|
||||||
|
foreach ($entities as $entity) {
|
||||||
|
if ($isAssociated && !$entity->getNodes()->isEmpty()) {
|
||||||
|
$ids[] = $entity->getId();
|
||||||
|
} elseif (!$isAssociated && $entity->getNodes()->isEmpty()) {
|
||||||
|
$ids[] = $entity->getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this
|
||||||
|
->andWhere('.id IN (:ids)')
|
||||||
|
->setParameter(':ids', $ids)
|
||||||
|
;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
protected function filterHandler(string $name, $value)
|
protected function filterHandler(string $name, $value)
|
||||||
{
|
{
|
||||||
if ('navigation' === $name) {
|
if ('navigation' === $name) {
|
||||||
return $this->filterByNavigation($value);
|
return $this->filterByNavigation($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('isAssociated' === $name && $value > -1) {
|
||||||
|
$this->withAssociation((bool) $value);
|
||||||
|
}
|
||||||
|
|
||||||
return parent::filterHandler($name, $value);
|
return parent::filterHandler($name, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,3 +191,4 @@
|
||||||
"Insert": "Insérer"
|
"Insert": "Insérer"
|
||||||
"Attributes": "Attributs"
|
"Attributes": "Attributs"
|
||||||
"Choose": "Choisir"
|
"Choose": "Choisir"
|
||||||
|
"Associated": "Associé(e)"
|
||||||
|
|
|
@ -147,6 +147,10 @@
|
||||||
<div id="form-node-page-action-keep" class="collapse show" data-parent="#node-page-action">
|
<div id="form-node-page-action-keep" class="collapse show" data-parent="#node-page-action">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
{{ 'No action'|trans }}
|
{{ 'No action'|trans }}
|
||||||
|
|
||||||
|
{% if page and pageConfiguration %}
|
||||||
|
({{ pageConfiguration.name }})
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -25,8 +25,8 @@ class StringExtension extends AbstractExtension
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildString(string $format, $object): string
|
public function buildString(?string $format, $object): string
|
||||||
{
|
{
|
||||||
return $this->stringBuilder->build($format, $object);
|
return $this->stringBuilder->build((string) $format, $object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue