add alias on node
This commit is contained in:
parent
0fddd78b11
commit
d6926cc949
|
@ -41,6 +41,7 @@ class NodeAdminController extends AdminController
|
||||||
$entity = $factory->create($node->getMenu());
|
$entity = $factory->create($node->getMenu());
|
||||||
$form = $this->createForm(EntityType::class, $entity, [
|
$form = $this->createForm(EntityType::class, $entity, [
|
||||||
'pages' => $pageLocator->getPages(),
|
'pages' => $pageLocator->getPages(),
|
||||||
|
'navigation' => $node->getMenu()->getNavigation(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($request->isMethod('POST')) {
|
if ($request->isMethod('POST')) {
|
||||||
|
@ -108,6 +109,7 @@ class NodeAdminController extends AdminController
|
||||||
): Response {
|
): Response {
|
||||||
$form = $this->createForm(EntityType::class, $entity, [
|
$form = $this->createForm(EntityType::class, $entity, [
|
||||||
'pages' => $pageLocator->getPages(),
|
'pages' => $pageLocator->getPages(),
|
||||||
|
'navigation' => $entity->getMenu()->getNavigation(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($request->isMethod('POST')) {
|
if ($request->isMethod('POST')) {
|
||||||
|
@ -269,15 +271,21 @@ class NodeAdminController extends AdminController
|
||||||
$page = $pageFactory->create($pageType, $entity->getLabel());
|
$page = $pageFactory->create($pageType, $entity->getLabel());
|
||||||
$page->setTemplate($pageConfiguration->getTemplates()[0]['file']);
|
$page->setTemplate($pageConfiguration->getTemplates()[0]['file']);
|
||||||
|
|
||||||
$entity->setPage($page);
|
$entity
|
||||||
|
->setPage($page)
|
||||||
|
->setAliasNode(null);
|
||||||
} elseif ('existing' === $pageAction) {
|
} elseif ('existing' === $pageAction) {
|
||||||
if ($pageEntity) {
|
if ($pageEntity) {
|
||||||
$entity->setPage($pageEntity);
|
$entity->setPage($pageEntity);
|
||||||
} else {
|
} else {
|
||||||
$this->addFlash('info', 'Aucun changement de page effectué.');
|
$this->addFlash('info', 'Aucun changement de page effectué.');
|
||||||
}
|
}
|
||||||
} elseif ('none' === $pageAction) {
|
} elseif ('alias' === $pageAction) {
|
||||||
$entity->setPage(null);
|
$entity->setPage(null);
|
||||||
|
} elseif ('none' === $pageAction) {
|
||||||
|
$entity
|
||||||
|
->setPage(null)
|
||||||
|
->setAliasNode(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,9 +123,20 @@ class Node implements EntityInterface
|
||||||
*/
|
*/
|
||||||
private $sitemapParameters = [];
|
private $sitemapParameters = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToOne(targetEntity=Node::class, inversedBy="aliasNodes")
|
||||||
|
*/
|
||||||
|
private $aliasNode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\OneToMany(targetEntity=Node::class, mappedBy="aliasNode")
|
||||||
|
*/
|
||||||
|
private $aliasNodes;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->children = new ArrayCollection();
|
$this->children = new ArrayCollection();
|
||||||
|
$this->aliasNodes = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
|
@ -324,6 +335,10 @@ class Node implements EntityInterface
|
||||||
|
|
||||||
public function getPage(): ?Page
|
public function getPage(): ?Page
|
||||||
{
|
{
|
||||||
|
if ($this->getAliasNode()) {
|
||||||
|
return $this->getAliasNode()->getPage();
|
||||||
|
}
|
||||||
|
|
||||||
return $this->page;
|
return $this->page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,11 +351,19 @@ class Node implements EntityInterface
|
||||||
|
|
||||||
public function getRouteName(): string
|
public function getRouteName(): string
|
||||||
{
|
{
|
||||||
|
if ($this->getAliasNode()) {
|
||||||
|
return $this->getAliasNode()->getRouteName();
|
||||||
|
}
|
||||||
|
|
||||||
return $this->getMenu()->getRouteName().'_'.($this->getCode() ? $this->getCode() : $this->getId());
|
return $this->getMenu()->getRouteName().'_'.($this->getCode() ? $this->getCode() : $this->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCode(): ?string
|
public function getCode(): ?string
|
||||||
{
|
{
|
||||||
|
if ($this->getAliasNode()) {
|
||||||
|
return $this->getAliasNode()->getCode();
|
||||||
|
}
|
||||||
|
|
||||||
return $this->code;
|
return $this->code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,6 +376,10 @@ class Node implements EntityInterface
|
||||||
|
|
||||||
public function getParameters(): ?array
|
public function getParameters(): ?array
|
||||||
{
|
{
|
||||||
|
if ($this->getAliasNode()) {
|
||||||
|
return $this->getAliasNode()->getParameters();
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_array($this->parameters)) {
|
if (!is_array($this->parameters)) {
|
||||||
$this->parameters = [];
|
$this->parameters = [];
|
||||||
}
|
}
|
||||||
|
@ -385,6 +412,10 @@ class Node implements EntityInterface
|
||||||
|
|
||||||
public function getController(): ?string
|
public function getController(): ?string
|
||||||
{
|
{
|
||||||
|
if ($this->getAliasNode()) {
|
||||||
|
return $this->getAliasNode()->getController();
|
||||||
|
}
|
||||||
|
|
||||||
return $this->controller;
|
return $this->controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,6 +428,10 @@ class Node implements EntityInterface
|
||||||
|
|
||||||
public function getSitemapParameters(): ?array
|
public function getSitemapParameters(): ?array
|
||||||
{
|
{
|
||||||
|
if ($this->getAliasNode()) {
|
||||||
|
return $this->getAliasNode()->getSitemapParameters();
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_array($this->sitemapParameters)) {
|
if (!is_array($this->sitemapParameters)) {
|
||||||
$this->sitemapParameters = [
|
$this->sitemapParameters = [
|
||||||
'isVisible' => false,
|
'isVisible' => false,
|
||||||
|
@ -414,4 +449,46 @@ class Node implements EntityInterface
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAliasNode(): ?self
|
||||||
|
{
|
||||||
|
return $this->aliasNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAliasNode(?self $aliasNode): self
|
||||||
|
{
|
||||||
|
$this->aliasNode = $aliasNode;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection|self[]
|
||||||
|
*/
|
||||||
|
public function getAliasNodes(): Collection
|
||||||
|
{
|
||||||
|
return $this->aliasNodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addAliasNode(self $aliasNode): self
|
||||||
|
{
|
||||||
|
if (!$this->aliasNodes->contains($aliasNode)) {
|
||||||
|
$this->aliasNodes[] = $aliasNode;
|
||||||
|
$aliasNode->setAliasNode($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeAliasNode(self $aliasNode): self
|
||||||
|
{
|
||||||
|
if ($this->aliasNodes->removeElement($aliasNode)) {
|
||||||
|
// set the owning side to null (unless already changed)
|
||||||
|
if ($aliasNode->getAliasNode() === $this) {
|
||||||
|
$aliasNode->setAliasNode(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,7 @@ class NodeType extends AbstractType
|
||||||
$actions = [
|
$actions = [
|
||||||
'New page' => 'new',
|
'New page' => 'new',
|
||||||
'Use an existing page' => 'existing',
|
'Use an existing page' => 'existing',
|
||||||
|
'Alias element' => 'alias',
|
||||||
'No page' => 'none',
|
'No page' => 'none',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -153,6 +154,38 @@ class NodeType extends AbstractType
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$builder->add(
|
||||||
|
'aliasNode',
|
||||||
|
EntityType::class,
|
||||||
|
[
|
||||||
|
'label' => false,
|
||||||
|
'required' => true,
|
||||||
|
'mapped' => true,
|
||||||
|
'class' => Node::class,
|
||||||
|
'choice_label' => 'label',
|
||||||
|
'choices' => call_user_func(function() use ($options, $builder) {
|
||||||
|
$nodes = [];
|
||||||
|
|
||||||
|
foreach ($options['navigation']->getMenus() as $menu) {
|
||||||
|
$nodes = array_merge(
|
||||||
|
$nodes,
|
||||||
|
$menu->getRootNode()->getAllChildren()->toArray()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($nodes as $k => $value) {
|
||||||
|
if ($value->getId() === $builder->getData()->getId()) {
|
||||||
|
unset($nodes[$k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $nodes;
|
||||||
|
}),
|
||||||
|
'constraints' => [
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
$builder->add(
|
$builder->add(
|
||||||
'parameters',
|
'parameters',
|
||||||
CollectionType::class,
|
CollectionType::class,
|
||||||
|
@ -213,6 +246,7 @@ class NodeType extends AbstractType
|
||||||
$resolver->setDefaults([
|
$resolver->setDefaults([
|
||||||
'data_class' => Node::class,
|
'data_class' => Node::class,
|
||||||
'pages' => [],
|
'pages' => [],
|
||||||
|
'navigation' => null,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,8 @@
|
||||||
"New menu": "Nouveau menu"
|
"New menu": "Nouveau menu"
|
||||||
"New": "Nouveau"
|
"New": "Nouveau"
|
||||||
"No action": "Aucune action"
|
"No action": "Aucune action"
|
||||||
|
"Alias element": "Élement alias"
|
||||||
|
"This element is an alias so the next configuration is ignored.": "Cet élement est un alias donc cette configuration sera ignorée"
|
||||||
"Route name: <code>%routeName%</code>": "Nom de la route : <code>%routeName%</code>"
|
"Route name: <code>%routeName%</code>": "Nom de la route : <code>%routeName%</code>"
|
||||||
"Content": "Contenu"
|
"Content": "Contenu"
|
||||||
"Routing": "Routage"
|
"Routing": "Routage"
|
||||||
|
|
|
@ -59,7 +59,6 @@
|
||||||
|
|
||||||
<div data-collection-add="collection-{{ collection_name }}" class="collection-add">
|
<div data-collection-add="collection-{{ collection_name }}" class="collection-add">
|
||||||
<span class="btn btn-sm btn-primary" data-collection-add="collection-{{ collection_name }}">
|
<span class="btn btn-sm btn-primary" data-collection-add="collection-{{ collection_name }}">
|
||||||
<span class="fa fa-plus"></span>
|
|
||||||
{{ label_add|trans }}
|
{{ label_add|trans }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -96,14 +96,39 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="form-node-page-action-none" class="collapse" data-parent="#node-page-action">
|
<div id="form-node-page-action-none" class="collapse" data-parent="#node-page-action">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
Aucune action
|
{{ form_row(form.aliasNode) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
{% set action = form.pageAction[3] %}
|
||||||
|
{% set options = {'attr': {'checked': 'checked'}} %}
|
||||||
|
|
||||||
|
<div class="card-header p-0">
|
||||||
|
<h2 class="mb-0">
|
||||||
|
<label class="btn btn-link btn-block text-left"
|
||||||
|
for="{{ action.vars.id }}"
|
||||||
|
data-toggle="collapse"
|
||||||
|
data-target="#form-node-page-action-alias">
|
||||||
|
{{ action.vars.label|trans }}
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div class="d-none">
|
||||||
|
{{ form_row(action, options) }}
|
||||||
|
</div>
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<div id="form-node-page-action-alias" class="collapse" data-parent="#node-page-action">
|
||||||
|
<div class="card-body">
|
||||||
|
{{ 'No action'|trans }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if entity.id %}
|
{% if entity.id %}
|
||||||
<div class="card">
|
<div class="card">
|
||||||
{% set action = form.pageAction[3] %}
|
{% set action = form.pageAction[4] %}
|
||||||
{% set options = {'attr': {'checked': 'checked'}} %}
|
{% set options = {'attr': {'checked': 'checked'}} %}
|
||||||
|
|
||||||
<div class="card-header p-0">
|
<div class="card-header p-0">
|
||||||
|
@ -138,6 +163,12 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if entity.aliasNode %}
|
||||||
|
<div class="alert alert-warning">
|
||||||
|
{{ 'This element is an alias so the next configuration is ignored.'|trans }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{{ form_row(form.url) }}
|
{{ form_row(form.url) }}
|
||||||
|
|
||||||
<div class="pb-1">
|
<div class="pb-1">
|
||||||
|
@ -215,6 +246,12 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane {% if tab == 'sitemap' %}show active{% endif %}" id="form-node-edit-sitemap">
|
<div class="tab-pane {% if tab == 'sitemap' %}show active{% endif %}" id="form-node-edit-sitemap">
|
||||||
|
{% if entity.aliasNode %}
|
||||||
|
<div class="alert alert-warning">
|
||||||
|
{{ 'This element is an alias so the next configuration is ignored.'|trans }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{{ form_row(form.sitemapParameters) }}
|
{{ form_row(form.sitemapParameters) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -79,7 +79,11 @@
|
||||||
{{ node.label }}
|
{{ node.label }}
|
||||||
|
|
||||||
<span class="ml-3 btn-group d-none d-md-inline-block">
|
<span class="ml-3 btn-group d-none d-md-inline-block">
|
||||||
{% if node.hasExternalUrl %}
|
{% if node.aliasNode %}
|
||||||
|
<span title="{{ node.aliasNode.label }}" data-toggle="tooltip" data-placement="top" class="btn btn-sm border border-secondary btn-light">
|
||||||
|
<span class="fa fa-file-import"></span>
|
||||||
|
</span>
|
||||||
|
{% elseif node.hasExternalUrl %}
|
||||||
<a href="{{ safe_node_url(node) }}" class="btn btn-sm border border-secondary btn-light">
|
<a href="{{ safe_node_url(node) }}" class="btn btn-sm border border-secondary btn-light">
|
||||||
<span class="fa fa-sign-out-alt text-muted"></span>
|
<span class="fa fa-sign-out-alt text-muted"></span>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -57,6 +57,10 @@ class SiteRouteLoader extends Loader
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (null !== $node->getAliasNode()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$requirements = [];
|
$requirements = [];
|
||||||
|
|
||||||
$defaults = [
|
$defaults = [
|
||||||
|
|
Loading…
Reference in a new issue