-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add publication dates on pages #74
base: master
Are you sure you want to change the base?
Conversation
@@ -35,3 +35,7 @@ services: | |||
MonsieurBiz\SyliusCmsPagePlugin\Routing\RequestContext: | |||
decorates: router.request_context | |||
arguments: ['@MonsieurBiz\SyliusCmsPagePlugin\Routing\RequestContext.inner'] | |||
|
|||
Sylius\Calendar\Provider\DateTimeProviderInterface: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❔ question: WDYTOT ? Else we can have a DateTimeProviderInterface
in our namespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could create a custom alias or provider that takes the native one as an argument
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 thought: it's a BC with this new parameter. Shouldn't we set it to null
by default and throw a depreciation is the value is null?
@@ -35,3 +35,7 @@ services: | |||
MonsieurBiz\SyliusCmsPagePlugin\Routing\RequestContext: | |||
decorates: router.request_context | |||
arguments: ['@MonsieurBiz\SyliusCmsPagePlugin\Routing\RequestContext.inner'] | |||
|
|||
Sylius\Calendar\Provider\DateTimeProviderInterface: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could create a custom alias or provider that takes the native one as an argument
->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; | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤓 nitpick: use a setNormalizer
to transform to DateTime
if is a string
$publishAt = $options['publish_at'] ?? null; | ||
if ($publishAt) { | ||
$page->setPublishAt(new DateTime($publishAt)); | ||
} | ||
|
||
$unpublishAt = $options['unpublish_at'] ?? null; | ||
if ($unpublishAt) { | ||
$page->setUnpublishAt(new DateTime($unpublishAt)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤓 nitpick: if you add the normalizer, unnecessary conditions
$publishAt = $options['publish_at'] ?? null; | |
if ($publishAt) { | |
$page->setPublishAt(new DateTime($publishAt)); | |
} | |
$unpublishAt = $options['unpublish_at'] ?? null; | |
if ($unpublishAt) { | |
$page->setUnpublishAt(new DateTime($unpublishAt)); | |
} | |
$page->setPublishAt($options['publish_at']); | |
$page->setUnpublishAt($options['unpublish_at']); | |
``` |
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 thought: I think this method should be rename to represent more what it is doing
public function existsOneEnabledByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug, DateTimeInterface $dateTime): bool | |
public function existsOnePublishedByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug, DateTimeInterface $dateTime): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it would be a BC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can mark existsOneEnabledByChannelAndSlug
as deprecated, create a new method named existsOnePublishedByChannelAndSlug
that call existsOneEnabledByChannelAndSlug
, then in the 2.0 version, let's remove existsOneEnabledByChannelAndSlug
in favor of existsOnePublishedByChannelAndSlug
.
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 thought: same as my other comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To handle the BC here, we can make the argument nullable. If it's actually null
, trigger a deprecation message to inform users this argument will become mandatory in 2.0. WDYT?
@@ -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 %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 thought: Maybe we should keep the button even if the page is not published. This way you can check fast if your page is available on front or not.
PageRepositoryInterface $pageRepository, | ||
ChannelContextInterface $channelContext, | ||
LocaleContextInterface $localeContext | ||
LocaleContextInterface $localeContext, | ||
DateTimeProviderInterface $dateTimeProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💣 chore: Let's put this php 8 style. This version does not support php 7.4 anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be a global refactoring could be better
Publication dates
Form
Grid
No filter on published now
We have title with information
Enabled and not published
404
Enabled and published
200
Show in shop is disable if page is not published
Preview still works