diff --git a/src/Entity/Page.php b/src/Entity/Page.php
index 2bde616..f604f83 100644
--- a/src/Entity/Page.php
+++ b/src/Entity/Page.php
@@ -63,6 +63,10 @@ class Page implements PageInterface
*/
protected $updatedAt;
+ protected ?DateTimeInterface $publishAt = null;
+
+ protected ?DateTimeInterface $unpublishAt = null;
+
/**
* Page constructor.
*/
@@ -115,6 +119,32 @@ public function hasChannel(ChannelInterface $channel): bool
return $this->channels->contains($channel);
}
+ public function getPublishAt(): ?DateTimeInterface
+ {
+ return $this->publishAt;
+ }
+
+ public function setPublishAt(?DateTimeInterface $publishAt): void
+ {
+ $this->publishAt = $publishAt;
+ }
+
+ public function getUnpublishAt(): ?DateTimeInterface
+ {
+ return $this->unpublishAt;
+ }
+
+ public function setUnpublishAt(?DateTimeInterface $unpublishAt): void
+ {
+ $this->unpublishAt = $unpublishAt;
+ }
+
+ public function isPublished(DateTimeInterface $dateTime): bool
+ {
+ return (null == $this->publishAt || $this->publishAt <= $dateTime)
+ && (null === $this->unpublishAt || $this->unpublishAt > $dateTime);
+ }
+
public function getTitle(): ?string
{
return $this->getTranslation()->getTitle();
diff --git a/src/Entity/PageInterface.php b/src/Entity/PageInterface.php
index 13b9045..3488866 100644
--- a/src/Entity/PageInterface.php
+++ b/src/Entity/PageInterface.php
@@ -13,6 +13,7 @@
namespace MonsieurBiz\SyliusCmsPagePlugin\Entity;
+use DateTimeInterface;
use Gedmo\Timestampable\Timestampable;
use Sylius\Component\Channel\Model\ChannelsAwareInterface;
use Sylius\Component\Resource\Model\CodeAwareInterface;
@@ -33,6 +34,16 @@ public function getCode(): ?string;
public function setCode(?string $title): void;
+ public function getPublishAt(): ?DateTimeInterface;
+
+ public function setPublishAt(?DateTimeInterface $publishAt): void;
+
+ public function getUnpublishAt(): ?DateTimeInterface;
+
+ public function setUnpublishAt(?DateTimeInterface $unpublishAt): void;
+
+ public function isPublished(DateTimeInterface $dateTime): bool;
+
public function getTitle(): ?string;
public function setTitle(?string $title): void;
diff --git a/src/Fixture/Factory/PageFixtureFactory.php b/src/Fixture/Factory/PageFixtureFactory.php
index 1613270..416029e 100644
--- a/src/Fixture/Factory/PageFixtureFactory.php
+++ b/src/Fixture/Factory/PageFixtureFactory.php
@@ -13,6 +13,7 @@
namespace MonsieurBiz\SyliusCmsPagePlugin\Fixture\Factory;
+use DateTime;
use MonsieurBiz\SyliusCmsPagePlugin\Entity\PageInterface;
use MonsieurBiz\SyliusCmsPagePlugin\Entity\PageTranslationInterface;
use Sylius\Bundle\CoreBundle\Fixture\Factory\AbstractExampleFactory;
@@ -85,6 +86,16 @@ public function create(array $options = []): PageInterface
$page->setEnabled($options['enabled']);
$page->setCode($options['code']);
+ $publishAt = $options['publish_at'] ?? null;
+ if ($publishAt) {
+ $page->setPublishAt(new DateTime($publishAt));
+ }
+
+ $unpublishAt = $options['unpublish_at'] ?? null;
+ if ($unpublishAt) {
+ $page->setUnpublishAt(new DateTime($unpublishAt));
+ }
+
foreach ($options['channels'] as $channel) {
$page->addChannel($channel);
}
@@ -116,6 +127,8 @@ private function createTranslations(PageInterface $page, array $options): void
*/
protected function configureOptions(OptionsResolver $resolver): void
{
+ $publishAt = $this->faker->dateTimeBetween('-1 year', '+1 year');
+ $hasPublishAt = $this->faker->boolean(20);
$resolver
->setDefault('enabled', function (Options $options): bool {
return $this->faker->boolean(80);
@@ -126,6 +139,12 @@ protected function configureOptions(OptionsResolver $resolver): void
->setDefault('translations', function (OptionsResolver $translationResolver): void {
$translationResolver->setDefaults($this->configureDefaultTranslations());
})
+ ->setDefault('publish_at', function (Options $options) use ($publishAt, $hasPublishAt): ?string {
+ return $hasPublishAt ? $publishAt->format('Y-m-d H:i:s') : null;
+ })
+ ->setDefault('unpublish_at', function (Options $options) use ($publishAt): ?string {
+ return $this->faker->boolean(20) ? (clone $publishAt)->modify('+' . $this->faker->numberBetween(1, 20) . ' days')->format('Y-m-d H:i:s') : null;
+ })
->setDefault('channels', LazyOption::all($this->channelRepository))
->setAllowedTypes('channels', 'array')
->setNormalizer('channels', LazyOption::findBy($this->channelRepository, 'code'))
diff --git a/src/Fixture/PageFixture.php b/src/Fixture/PageFixture.php
index f56a901..7f6cacc 100644
--- a/src/Fixture/PageFixture.php
+++ b/src/Fixture/PageFixture.php
@@ -43,6 +43,8 @@ protected function configureResourceNode(ArrayNodeDefinition $resourceNode): voi
->children()
->booleanNode('enabled')->end()
->scalarNode('code')->cannotBeEmpty()->end()
+ ->scalarNode('publish_at')->end()
+ ->scalarNode('unpublish_at')->end()
->arrayNode('channels')
->scalarPrototype()->end()
->end()
diff --git a/src/Form/Type/PageType.php b/src/Form/Type/PageType.php
index 90be33e..2b19188 100644
--- a/src/Form/Type/PageType.php
+++ b/src/Form/Type/PageType.php
@@ -18,6 +18,7 @@
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
+use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\FormBuilderInterface;
class PageType extends AbstractResourceType
@@ -33,6 +34,16 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'required' => false,
'label' => 'monsieurbiz_cms_page.ui.form.enabled',
])
+ ->add('publishAt', DateTimeType::class, [
+ 'label' => 'monsieurbiz_cms_page.ui.form.publish_at',
+ 'required' => false,
+ 'widget' => 'single_text',
+ ])
+ ->add('unpublishAt', DateTimeType::class, [
+ 'label' => 'monsieurbiz_cms_page.ui.form.unpublish_at',
+ 'required' => false,
+ 'widget' => 'single_text',
+ ])
->add('channels', ChannelChoiceType::class, [
'label' => 'monsieurbiz_cms_page.ui.form.channels',
'required' => false,
diff --git a/src/Migrations/Version20240924135829.php b/src/Migrations/Version20240924135829.php
new file mode 100644
index 0000000..1c9add0
--- /dev/null
+++ b/src/Migrations/Version20240924135829.php
@@ -0,0 +1,40 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE.txt
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace MonsieurBiz\SyliusCmsPagePlugin\Migrations;
+
+use Doctrine\DBAL\Schema\Schema;
+use Doctrine\Migrations\AbstractMigration;
+
+/**
+ * Auto-generated Migration: Please modify to your needs!
+ */
+final class Version20240924135829 extends AbstractMigration
+{
+ public function getDescription(): string
+ {
+ return '';
+ }
+
+ public function up(Schema $schema): void
+ {
+ // this up() migration is auto-generated, please modify it to your needs
+ $this->addSql('ALTER TABLE monsieurbiz_cms_page ADD publish_at DATETIME DEFAULT NULL, ADD unpublish_at DATETIME DEFAULT NULL');
+ }
+
+ public function down(Schema $schema): void
+ {
+ // this down() migration is auto-generated, please modify it to your needs
+ $this->addSql('ALTER TABLE monsieurbiz_cms_page DROP publish_at, DROP unpublish_at');
+ }
+}
diff --git a/src/Repository/PageRepository.php b/src/Repository/PageRepository.php
index a54c223..e76bd56 100644
--- a/src/Repository/PageRepository.php
+++ b/src/Repository/PageRepository.php
@@ -13,6 +13,7 @@
namespace MonsieurBiz\SyliusCmsPagePlugin\Repository;
+use DateTimeInterface;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\QueryBuilder;
use MonsieurBiz\SyliusCmsPagePlugin\Entity\PageInterface;
@@ -48,11 +49,14 @@ public function existsOneByChannelAndSlug(ChannelInterface $channel, ?string $lo
return $count > 0;
}
- public function existsOneEnabledByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug): bool
+ public function existsOneEnabledByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug, DateTimeInterface $dateTime): bool
{
$queryBuilder = $this->createQueryBuilderExistOne($channel, $locale, $slug);
$queryBuilder
->andWhere('p.enabled = true')
+ ->andWhere('p.publishAt IS NULL OR p.publishAt <= :now')
+ ->andWhere('p.unpublishAt IS NULL OR p.unpublishAt >= :now')
+ ->setParameter('now', $dateTime)
;
$count = (int) $queryBuilder
@@ -66,7 +70,7 @@ public function existsOneEnabledByChannelAndSlug(ChannelInterface $channel, ?str
/**
* @throws NonUniqueResultException
*/
- public function findOneEnabledBySlugAndChannelCode(string $slug, string $localeCode, string $channelCode): ?PageInterface
+ public function findOneEnabledBySlugAndChannelCode(string $slug, string $localeCode, string $channelCode, DateTimeInterface $dateTime): ?PageInterface
{
return $this->createQueryBuilder('p')
->leftJoin('p.translations', 'translation')
@@ -75,6 +79,9 @@ public function findOneEnabledBySlugAndChannelCode(string $slug, string $localeC
->andWhere('translation.slug = :slug')
->andWhere('channels.code = :channelCode')
->andWhere('p.enabled = true')
+ ->andWhere('p.publishAt IS NULL OR p.publishAt <= :now')
+ ->andWhere('p.unpublishAt IS NULL OR p.unpublishAt >= :now')
+ ->setParameter('now', $dateTime)
->setParameter('localeCode', $localeCode)
->setParameter('slug', $slug)
->setParameter('channelCode', $channelCode)
diff --git a/src/Repository/PageRepositoryInterface.php b/src/Repository/PageRepositoryInterface.php
index e188ef8..d79404a 100644
--- a/src/Repository/PageRepositoryInterface.php
+++ b/src/Repository/PageRepositoryInterface.php
@@ -13,6 +13,7 @@
namespace MonsieurBiz\SyliusCmsPagePlugin\Repository;
+use DateTimeInterface;
use Doctrine\ORM\QueryBuilder;
use MonsieurBiz\SyliusCmsPagePlugin\Entity\PageInterface;
use Sylius\Component\Channel\Model\ChannelInterface;
@@ -24,7 +25,7 @@ public function createListQueryBuilder(string $localeCode): QueryBuilder;
public function existsOneByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug, array $excludedPages = []): bool;
- public function existsOneEnabledByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug): bool;
+ public function existsOneEnabledByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug, DateTimeInterface $dateTime): bool;
- public function findOneEnabledBySlugAndChannelCode(string $slug, string $localeCode, string $channelCode): ?PageInterface;
+ public function findOneEnabledBySlugAndChannelCode(string $slug, string $localeCode, string $channelCode, DateTimeInterface $dateTime): ?PageInterface;
}
diff --git a/src/Resources/config/doctrine/Page.orm.xml b/src/Resources/config/doctrine/Page.orm.xml
index 86211bb..136d0a2 100644
--- a/src/Resources/config/doctrine/Page.orm.xml
+++ b/src/Resources/config/doctrine/Page.orm.xml
@@ -16,6 +16,8 @@
+
Lorem\r\n ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod \r\ntempor incididunt ut labore et dolore magna aliqua. Amet commodo nulla \r\nfacilisi nullam vehicula ipsum. Eu mi bibendum neque egestas congue \r\nquisque egestas. Dictumst vestibulum rhoncus est pellentesque elit \r\nullamcorper dignissim cras tincidunt. Ultrices sagittis orci a \r\nscelerisque purus. Proin gravida hendrerit lectus a. Cras ornare arcu \r\ndui vivamus arcu felis. Lacus viverra vitae congue eu consequat ac \r\nfelis. Pharetra diam sit amet nisl suscipit. Nisl suscipit adipiscing \r\nbibendum est ultricies. Nunc non blandit massa enim nec dui. Phasellus \r\negestas tellus rutrum tellus. Purus ut faucibus pulvinar elementum. \r\nScelerisque eu ultrices vitae auctor eu augue ut lectus arcu. Bibendum \r\nat varius vel pharetra vel. Morbi tristique senectus et netus et \r\nmalesuada. Vulputate mi sit amet mauris commodo. Cras semper auctor \r\nneque vitae tempus quam pellentesque nec nam.
Risus quis varius quam quisque id diam. Et ultrices neque ornare \r\naenean euismod elementum nisi quis. Sagittis purus sit amet volutpat \r\nconsequat mauris nunc congue nisi. Eget felis eget nunc lobortis mattis \r\naliquam faucibus purus in. Proin libero nunc consequat interdum varius. \r\nIn hac habitasse platea dictumst. Luctus accumsan tortor posuere ac ut \r\nconsequat semper viverra nam. Neque vitae tempus quam pellentesque nec \r\nnam aliquam. Quis ipsum suspendisse ultrices gravida. Blandit volutpat \r\nmaecenas volutpat blandit aliquam etiam erat velit. Et malesuada fames \r\nac turpis egestas sed tempus urna et. Consequat ac felis donec et odio \r\npellentesque diam volutpat. Parturient montes nascetur ridiculus mus \r\nmauris vitae ultricies leo integer. Eget sit amet tellus cras adipiscing\r\n enim eu. Eget lorem dolor sed viverra ipsum nunc. Nibh mauris cursus \r\nmattis molestie a iaculis at. Faucibus pulvinar elementum integer enim. \r\nUt porttitor leo a diam sollicitudin tempor id eu.
\r\nNec sagittis aliquam malesuada bibendum arcu vitae elementum \r\ncurabitur. Dolor magna eget est lorem ipsum. Neque ornare aenean euismod\r\n elementum nisi quis eleifend. Volutpat sed cras ornare arcu. Cursus \r\neget nunc scelerisque viverra. Pretium quam vulputate dignissim \r\nsuspendisse in est ante in nibh. Leo vel orci porta non pulvinar. \r\nRhoncus urna neque viverra justo. Est ullamcorper eget nulla facilisi \r\netiam dignissim diam quis enim. Augue interdum velit euismod in \r\npellentesque. Elementum tempus egestas sed sed. Vel fringilla est \r\nullamcorper eget nulla facilisi. Libero justo laoreet sit amet cursus \r\nsit amet.
\r\nIpsum suspendisse ultrices gravida dictum fusce ut placerat orci. \r\nAdipiscing bibendum est ultricies integer. Fermentum leo vel orci porta \r\nnon. Pharetra magna ac placerat vestibulum lectus mauris ultrices eros \r\nin. Quis auctor elit sed vulputate. Quisque egestas diam in arcu cursus.\r\n Pulvinar mattis nunc sed blandit libero volutpat sed cras. Ultrices \r\nvitae auctor eu augue ut lectus arcu bibendum. Ipsum dolor sit amet \r\nconsectetur adipiscing elit pellentesque. Lectus mauris ultrices eros in\r\n cursus turpis massa. Diam maecenas ultricies mi eget mauris pharetra et\r\n ultrices. Amet porttitor eget dolor morbi non. Consectetur adipiscing \r\nelit ut aliquam purus sit amet. Enim neque volutpat ac tincidunt vitae \r\nsemper. Porta nibh venenatis cras sed felis eget. Gravida arcu ac tortor\r\n dignissim convallis aenean et tortor. Tortor consequat id porta nibh \r\nvenenatis cras sed felis eget. A diam sollicitudin tempor id. Sed \r\nelementum tempus egestas sed sed risus pretium quam vulputate. Turpis \r\negestas integer eget aliquet nibh.
\r\nPurus gravida quis blandit turpis cursus in. Pellentesque dignissim \r\nenim sit amet venenatis urna cursus eget. In pellentesque massa placerat\r\n duis ultricies lacus. Ipsum consequat nisl vel pretium lectus quam id. \r\nRisus pretium quam vulputate dignissim suspendisse in est. Sed turpis \r\ntincidunt id aliquet risus feugiat in. Vitae ultricies leo integer \r\nmalesuada nunc vel risus. Aliquet bibendum enim facilisis gravida neque.\r\n Adipiscing enim eu turpis egestas pretium. Lacus vestibulum sed arcu \r\nnon odio euismod lacinia at. Libero justo laoreet sit amet cursus sit \r\namet dictum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
"}},{"code":"monsieurbiz.separator","data":{"hidden":true}},{"code":"monsieurbiz.button","data":{"label":"An amazing web agency","link":"https://monsieurbiz.com"}}] + metaTitle: '' + metaDescription: '' + metaKeywords: '' + fr_FR: + title: 'Page Test' + slug: 'page-test' + content: | + [{"code":"monsieurbiz.text","data":{"content":"Lorem\r\n ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod \r\ntempor incididunt ut labore et dolore magna aliqua. Amet commodo nulla \r\nfacilisi nullam vehicula ipsum. Eu mi bibendum neque egestas congue \r\nquisque egestas. Dictumst vestibulum rhoncus est pellentesque elit \r\nullamcorper dignissim cras tincidunt. Ultrices sagittis orci a \r\nscelerisque purus. Proin gravida hendrerit lectus a. Cras ornare arcu \r\ndui vivamus arcu felis. Lacus viverra vitae congue eu consequat ac \r\nfelis. Pharetra diam sit amet nisl suscipit. Nisl suscipit adipiscing \r\nbibendum est ultricies. Nunc non blandit massa enim nec dui. Phasellus \r\negestas tellus rutrum tellus. Purus ut faucibus pulvinar elementum. \r\nScelerisque eu ultrices vitae auctor eu augue ut lectus arcu. Bibendum \r\nat varius vel pharetra vel. Morbi tristique senectus et netus et \r\nmalesuada. Vulputate mi sit amet mauris commodo. Cras semper auctor \r\nneque vitae tempus quam pellentesque nec nam.
Risus quis varius quam quisque id diam. Et ultrices neque ornare \r\naenean euismod elementum nisi quis. Sagittis purus sit amet volutpat \r\nconsequat mauris nunc congue nisi. Eget felis eget nunc lobortis mattis \r\naliquam faucibus purus in. Proin libero nunc consequat interdum varius. \r\nIn hac habitasse platea dictumst. Luctus accumsan tortor posuere ac ut \r\nconsequat semper viverra nam. Neque vitae tempus quam pellentesque nec \r\nnam aliquam. Quis ipsum suspendisse ultrices gravida. Blandit volutpat \r\nmaecenas volutpat blandit aliquam etiam erat velit. Et malesuada fames \r\nac turpis egestas sed tempus urna et. Consequat ac felis donec et odio \r\npellentesque diam volutpat. Parturient montes nascetur ridiculus mus \r\nmauris vitae ultricies leo integer. Eget sit amet tellus cras adipiscing\r\n enim eu. Eget lorem dolor sed viverra ipsum nunc. Nibh mauris cursus \r\nmattis molestie a iaculis at. Faucibus pulvinar elementum integer enim. \r\nUt porttitor leo a diam sollicitudin tempor id eu.
\r\nNec sagittis aliquam malesuada bibendum arcu vitae elementum \r\ncurabitur. Dolor magna eget est lorem ipsum. Neque ornare aenean euismod\r\n elementum nisi quis eleifend. Volutpat sed cras ornare arcu. Cursus \r\neget nunc scelerisque viverra. Pretium quam vulputate dignissim \r\nsuspendisse in est ante in nibh. Leo vel orci porta non pulvinar. \r\nRhoncus urna neque viverra justo. Est ullamcorper eget nulla facilisi \r\netiam dignissim diam quis enim. Augue interdum velit euismod in \r\npellentesque. Elementum tempus egestas sed sed. Vel fringilla est \r\nullamcorper eget nulla facilisi. Libero justo laoreet sit amet cursus \r\nsit amet.
\r\nIpsum suspendisse ultrices gravida dictum fusce ut placerat orci. \r\nAdipiscing bibendum est ultricies integer. Fermentum leo vel orci porta \r\nnon. Pharetra magna ac placerat vestibulum lectus mauris ultrices eros \r\nin. Quis auctor elit sed vulputate. Quisque egestas diam in arcu cursus.\r\n Pulvinar mattis nunc sed blandit libero volutpat sed cras. Ultrices \r\nvitae auctor eu augue ut lectus arcu bibendum. Ipsum dolor sit amet \r\nconsectetur adipiscing elit pellentesque. Lectus mauris ultrices eros in\r\n cursus turpis massa. Diam maecenas ultricies mi eget mauris pharetra et\r\n ultrices. Amet porttitor eget dolor morbi non. Consectetur adipiscing \r\nelit ut aliquam purus sit amet. Enim neque volutpat ac tincidunt vitae \r\nsemper. Porta nibh venenatis cras sed felis eget. Gravida arcu ac tortor\r\n dignissim convallis aenean et tortor. Tortor consequat id porta nibh \r\nvenenatis cras sed felis eget. A diam sollicitudin tempor id. Sed \r\nelementum tempus egestas sed sed risus pretium quam vulputate. Turpis \r\negestas integer eget aliquet nibh.
\r\nPurus gravida quis blandit turpis cursus in. Pellentesque dignissim \r\nenim sit amet venenatis urna cursus eget. In pellentesque massa placerat\r\n duis ultricies lacus. Ipsum consequat nisl vel pretium lectus quam id. \r\nRisus pretium quam vulputate dignissim suspendisse in est. Sed turpis \r\ntincidunt id aliquet risus feugiat in. Vitae ultricies leo integer \r\nmalesuada nunc vel risus. Aliquet bibendum enim facilisis gravida neque.\r\n Adipiscing enim eu turpis egestas pretium. Lacus vestibulum sed arcu \r\nnon odio euismod lacinia at. Libero justo laoreet sit amet cursus sit \r\namet dictum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
"}},{"code":"monsieurbiz.separator","data":{"hidden":true}},{"code":"monsieurbiz.button","data":{"label":"Une superbe agence web","link":"https://monsieurbiz.com"}}] + metaTitle: '' + metaDescription: '' + metaKeywords: '' diff --git a/src/Resources/config/sylius/grid.yaml b/src/Resources/config/sylius/grid.yaml index 3c40fa7..dba79a1 100644 --- a/src/Resources/config/sylius/grid.yaml +++ b/src/Resources/config/sylius/grid.yaml @@ -38,6 +38,12 @@ sylius_grid: sortable: ~ options: template: "@SyliusUi/Grid/Field/enabled.html.twig" + published: + type: twig + label: monsieurbiz_cms_page.ui.is_published + path: . + options: + template: "@MonsieurBizSyliusCmsPagePlugin/Admin/Grid/Field/published.html.twig" actions: main: create: diff --git a/src/Resources/translations/messages.en.yaml b/src/Resources/translations/messages.en.yaml index 95a3a5a..de510c5 100644 --- a/src/Resources/translations/messages.en.yaml +++ b/src/Resources/translations/messages.en.yaml @@ -6,6 +6,7 @@ monsieurbiz_cms_page: cms_content: "CMS content" pages_subheader: "CMS Page management" back_to_admin: "Back to admin" + is_published: "Published" form: id: 'ID' page_info: 'Page information' @@ -19,6 +20,8 @@ monsieurbiz_cms_page: meta_title: "Meta Title" meta_description: "Meta Description" meta_keywords: "Meta Keyword" + publish_at: "Publish at" + unpublish_at: "Unpublish at" show_in: "Show in" show_page_in_shop_page: "Show page in shop page" actions: diff --git a/src/Resources/translations/messages.fr.yaml b/src/Resources/translations/messages.fr.yaml index 31f7e2b..c56bf3f 100644 --- a/src/Resources/translations/messages.fr.yaml +++ b/src/Resources/translations/messages.fr.yaml @@ -6,6 +6,7 @@ monsieurbiz_cms_page: cms_content: "Contenus CMS" pages_subheader: "Gestion des contenus CMS" back_to_admin: "Retour à l'admin" + is_published: "Publiée" form: id: 'ID' page_info: 'Informations de la page' @@ -19,6 +20,8 @@ monsieurbiz_cms_page: meta_title: "Meta Title" meta_description: "Meta Description" meta_keywords: "Meta Keyword" + publish_at: "Publier le" + unpublish_at: "Dépublier le" show_in: "Afficher dans" show_page_in_shop_page: "Afficher la page dans la boutique" actions: diff --git a/src/Resources/translations/messages.pl.yaml b/src/Resources/translations/messages.pl.yaml index 64049ae..8605fdc 100644 --- a/src/Resources/translations/messages.pl.yaml +++ b/src/Resources/translations/messages.pl.yaml @@ -6,6 +6,7 @@ monsieurbiz_cms_page: cms_content: "Treść CMS" pages_subheader: "Zarządzanie stronami CMS" back_to_admin: "Powrót do administracji" + is_published: "Opublikowana" form: id: 'ID' page_info: 'Informacje o stronie' @@ -19,6 +20,8 @@ monsieurbiz_cms_page: meta_title: "Tytuł meta" meta_description: "Opis meta" meta_keywords: "Słowa kluczowe meta" + publish_at: "Opublikuj w" + unpublish_at: "Niepublikuj w" show_in: "Pokaż w" show_page_in_shop_page: "Pokaż stronę na stronie sklepu" actions: diff --git a/src/Resources/views/Admin/Grid/Field/published.html.twig b/src/Resources/views/Admin/Grid/Field/published.html.twig new file mode 100644 index 0000000..61d1f7e --- /dev/null +++ b/src/Resources/views/Admin/Grid/Field/published.html.twig @@ -0,0 +1,22 @@ +{% set publishInformationText = '' %} +{% if data.publishAt %} + {% set publishInformationText = publishInformationText ~ ('monsieurbiz_cms_page.ui.form.publish_at'|trans) ~ ' ' ~ data.publishAt|date('Y-m-d H:i:s') %} +{% endif %} +{% if data.unpublishAt %} + {% if publishInformationText is not empty %} + {% set publishInformationText = publishInformationText ~ ' - ' %} + {% endif %} + {% set publishInformationText = publishInformationText ~ ('monsieurbiz_cms_page.ui.form.unpublish_at'|trans) ~ ' ' ~ data.unpublishAt|date('Y-m-d H:i:s') %} +{% endif %} + +{% if data.isPublished(date()) %} + + + {{ 'sylius.ui.yes_label'|trans }} + +{% else %} + + + {{ 'sylius.ui.no_label'|trans }} + +{% endif %} diff --git a/src/Resources/views/Admin/Page/_showInShopButton.html.twig b/src/Resources/views/Admin/Page/_showInShopButton.html.twig index 6d1066c..0a5eceb 100644 --- a/src/Resources/views/Admin/Page/_showInShopButton.html.twig +++ b/src/Resources/views/Admin/Page/_showInShopButton.html.twig @@ -1,7 +1,7 @@ {% set enabledChannels = resource.channels|filter(channel => channel.enabled == true) %} {% if sylius_bundle_loaded_checker('SyliusShopBundle') %} - {% if not resource.enabled or enabledChannels|length < 1 %} + {% if not resource.enabled or not resource.isPublished(date()) or enabledChannels|length < 1 %} {{ 'monsieurbiz_cms_page.ui.show_page_in_shop_page'|trans }} diff --git a/src/Routing/PageSlugConditionChecker.php b/src/Routing/PageSlugConditionChecker.php index 3b5d229..bb42786 100644 --- a/src/Routing/PageSlugConditionChecker.php +++ b/src/Routing/PageSlugConditionChecker.php @@ -14,6 +14,7 @@ namespace MonsieurBiz\SyliusCmsPagePlugin\Routing; use MonsieurBiz\SyliusCmsPagePlugin\Repository\PageRepositoryInterface; +use Sylius\Calendar\Provider\DateTimeProviderInterface; use Sylius\Component\Channel\Context\ChannelContextInterface; use Sylius\Component\Channel\Context\ChannelNotFoundException; use Sylius\Component\Locale\Context\LocaleContextInterface; @@ -35,17 +36,24 @@ final class PageSlugConditionChecker */ private $localeContext; + /** + * @var DateTimeProviderInterface + */ + private $dateTimeProvider; + /** * PageSlugConditionChecker constructor. */ public function __construct( PageRepositoryInterface $pageRepository, ChannelContextInterface $channelContext, - LocaleContextInterface $localeContext + LocaleContextInterface $localeContext, + DateTimeProviderInterface $dateTimeProvider ) { $this->pageRepository = $pageRepository; $this->channelContext = $channelContext; $this->localeContext = $localeContext; + $this->dateTimeProvider = $dateTimeProvider; } public function isPageSlug(string $slug): bool @@ -54,7 +62,8 @@ public function isPageSlug(string $slug): bool return $this->pageRepository->existsOneEnabledByChannelAndSlug( $this->channelContext->getChannel(), $this->localeContext->getLocaleCode(), - $slug + $slug, + $this->dateTimeProvider->now() ); } catch (ChannelNotFoundException $channelNotFoundException) { return false;