add deprecated post feature
This commit is contained in:
parent
bad87d913e
commit
3d6acca60a
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<int, self>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<div class="row">
|
||||
<div class="col-md-3 p-3">
|
||||
<div class="row">
|
||||
{% for item in ['categories', 'slug'] %}
|
||||
{% for item in ['categories', 'slug', 'recommandedPost'] %}
|
||||
<div class="col-md-12">
|
||||
{{ form_row(form[item]) }}
|
||||
</div>
|
||||
|
@ -38,7 +38,7 @@
|
|||
</span>
|
||||
</div>
|
||||
|
||||
{% for item in ['image', 'image2', 'parameters', 'status', 'contentFormat', 'publishedAt'] %}
|
||||
{% for item in ['image', 'image2', 'status', 'contentFormat', 'publishedAt'] %}
|
||||
<div class="col-md-12">
|
||||
{{ form_row(form[item]) }}
|
||||
</div>
|
||||
|
|
|
@ -38,7 +38,19 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="body-content {% if post.parameter('podcast') %}is-podcast{% endif %}">
|
||||
<div class="body-content">
|
||||
{%- if post.recommandedPost -%}
|
||||
<div class="deprecated">
|
||||
<svg stroke-width="2" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="#ffffff"><path d="M20.043 21H3.957c-1.538 0-2.5-1.664-1.734-2.997l8.043-13.988c.77-1.337 2.699-1.337 3.468 0l8.043 13.988C22.543 19.336 21.58 21 20.043 21zM12 9v4" stroke="#ffffff" stroke-width="2" stroke-linecap="round"></path><path d="M12 17.01l.01-.011" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>
|
||||
<strong>Cet article est déprécié</strong><br>
|
||||
Article recommandé : <a href="{{ safe_path('blog_menu_post', {
|
||||
post: post.recommandedPost.id,
|
||||
slug: post.recommandedPost.slug,
|
||||
_domain: _domain})
|
||||
}}"><strong>{{ post.recommandedPost.title }}</strong></a>
|
||||
</div>
|
||||
{%- endif -%}
|
||||
|
||||
{% if post.contentFormat == 'html' %}
|
||||
{{- post.content|murph_url|file_attributes|post -}}
|
||||
{% elseif post.contentFormat == 'markdown' %}
|
||||
|
|
Loading…
Reference in a new issue