diff --git a/assets/css/app.scss b/assets/css/app.scss index 25cc3d0..917742a 100644 --- a/assets/css/app.scss +++ b/assets/css/app.scss @@ -1363,3 +1363,18 @@ $links: ( } } } + +.deprecated { + color: #fff; + background: #3abff8; + padding: 1rem; + border-radius: var(--rounded-box, 1rem); + text-align: center; + + svg { + display: inline-block; + height: 25px; + vertical-align: top; + margin-right: 8px; + } +} diff --git a/src/Entity/Blog/Post.php b/src/Entity/Blog/Post.php index 505c4e4..c745516 100644 --- a/src/Entity/Blog/Post.php +++ b/src/Entity/Blog/Post.php @@ -90,11 +90,18 @@ class Post implements EntityInterface #[ORM\Column(type: 'array')] private $parameters = []; + #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'deprecatedPosts')] + private $recommandedPost; + + #[ORM\OneToMany(mappedBy: 'recommandedPost', targetEntity: self::class)] + private $deprecatedPosts; + public function __construct() { $this->categories = new ArrayCollection(); $this->comments = new ArrayCollection(); $this->postFollows = new ArrayCollection(); + $this->deprecatedPosts = new ArrayCollection(); } public function getId(): ?int @@ -475,4 +482,46 @@ class Post implements EntityInterface } )[0]['value'] ?? null; } + + public function getRecommandedPost(): ?self + { + return $this->recommandedPost; + } + + public function setRecommandedPost(?self $recommandedPost): self + { + $this->recommandedPost = $recommandedPost; + + return $this; + } + + /** + * @return Collection + */ + public function getDeprecatedPosts(): Collection + { + return $this->deprecatedPosts; + } + + public function addDeprecatedPost(self $deprecatedPost): self + { + if (!$this->deprecatedPosts->contains($deprecatedPost)) { + $this->deprecatedPosts[] = $deprecatedPost; + $deprecatedPost->setRecommandedPost($this); + } + + return $this; + } + + public function removeDeprecatedPost(self $deprecatedPost): self + { + if ($this->deprecatedPosts->removeElement($deprecatedPost)) { + // set the owning side to null (unless already changed) + if ($deprecatedPost->getRecommandedPost() === $this) { + $deprecatedPost->setRecommandedPost(null); + } + } + + return $this; + } } diff --git a/src/Form/Blog/PostType.php b/src/Form/Blog/PostType.php index fc312a4..e7ce7fc 100644 --- a/src/Form/Blog/PostType.php +++ b/src/Form/Blog/PostType.php @@ -113,6 +113,28 @@ class PostType extends AbstractType ] ); + $builder->add( + 'recommandedPost', + EntityType::class, + [ + 'label' => 'Article recommandé', + 'class' => Post::class, + 'choice_label' => 'title', + 'required' => false, + 'multiple' => false, + 'attr' => [ + 'data-jschoice' => '', + ], + 'query_builder' => function (EntityRepository $repo) { + return $repo->createQueryBuilder('a') + ->orderBy('a.title', 'ASC') + ; + }, + 'constraints' => [ + ], + ] + ); + $builder->add( 'status', ChoiceType::class, @@ -301,19 +323,19 @@ class PostType extends AbstractType ] ); - $builder->add( - 'parameters', - MurphCollectionType::class, - [ - 'label' => 'Paramètres', - 'entry_type' => PostParameterType::class, - 'by_reference' => false, - 'allow_add' => true, - 'allow_delete' => true, - 'prototype' => true, - 'row_attr' => ['class' => 'mb-3'], - ] - ); + // $builder->add( + // 'parameters', + // MurphCollectionType::class, + // [ + // 'label' => 'Paramètres', + // 'entry_type' => PostParameterType::class, + // 'by_reference' => false, + // 'allow_add' => true, + // 'allow_delete' => true, + // 'prototype' => true, + // 'row_attr' => ['class' => 'mb-3'], + // ] + // ); } public function configureOptions(OptionsResolver $resolver) diff --git a/templates/blog/post_admin/_form.html.twig b/templates/blog/post_admin/_form.html.twig index 2983cd8..1581f4e 100644 --- a/templates/blog/post_admin/_form.html.twig +++ b/templates/blog/post_admin/_form.html.twig @@ -1,7 +1,7 @@
- {% for item in ['categories', 'slug'] %} + {% for item in ['categories', 'slug', 'recommandedPost'] %}
{{ form_row(form[item]) }}
@@ -38,7 +38,7 @@
- {% for item in ['image', 'image2', 'parameters', 'status', 'contentFormat', 'publishedAt'] %} + {% for item in ['image', 'image2', 'status', 'contentFormat', 'publishedAt'] %}
{{ form_row(form[item]) }}
diff --git a/templates/blog/post_admin/index.html.twig b/templates/blog/post_admin/index.html.twig index 38ac4fe..4ace0e1 100644 --- a/templates/blog/post_admin/index.html.twig +++ b/templates/blog/post_admin/index.html.twig @@ -3,7 +3,7 @@ {% block list_item_actions_before %} {% if configuration.action(context, 'analytic_stats', true) %} {% set analytics = path( - configuration.pageRoute('analytic_stats'), + configuration.pageRoute('analytic_stats'), {entity: item.id}|merge(configuration.pageRouteParams('analytic_stats')) ) %} diff --git a/templates/page/post/_post.html.twig b/templates/page/post/_post.html.twig index 0421885..2a7916c 100644 --- a/templates/page/post/_post.html.twig +++ b/templates/page/post/_post.html.twig @@ -38,7 +38,19 @@
{% endif %} -
+
+ {%- if post.recommandedPost -%} +
+ + Cet article est déprécié
+ Article recommandé : {{ post.recommandedPost.title }} +
+ {%- endif -%} + {% if post.contentFormat == 'html' %} {{- post.content|murph_url|file_attributes|post -}} {% elseif post.contentFormat == 'markdown' %}