Skip to content
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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

maximehuran
Copy link
Member

@maximehuran maximehuran commented Sep 24, 2024

Publication dates

Form

image

Grid

No filter on published now

image

We have title with information

image

Enabled and not published

404

image

Enabled and published

200

image

Show in shop is disable if page is not published

image

Preview still works

image

@@ -35,3 +35,7 @@ services:
MonsieurBiz\SyliusCmsPagePlugin\Routing\RequestContext:
decorates: router.request_context
arguments: ['@MonsieurBiz\SyliusCmsPagePlugin\Routing\RequestContext.inner']

Sylius\Calendar\Provider\DateTimeProviderInterface:
Copy link
Member Author

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

Copy link
Member

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

Comment on lines +28 to +30
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;
Copy link
Member

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:
Copy link
Member

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

Comment on lines +142 to +147
->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;
})
Copy link
Member

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

Comment on lines +89 to +97
$publishAt = $options['publish_at'] ?? null;
if ($publishAt) {
$page->setPublishAt(new DateTime($publishAt));
}

$unpublishAt = $options['unpublish_at'] ?? null;
if ($unpublishAt) {
$page->setUnpublishAt(new DateTime($unpublishAt));
}
Copy link
Member

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

Suggested change
$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

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‏

Suggested change
public function existsOneEnabledByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug, DateTimeInterface $dateTime): bool
public function existsOnePublishedByChannelAndSlug(ChannelInterface $channel, ?string $locale, string $slug, DateTimeInterface $dateTime): bool

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

Copy link
Contributor

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

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‏

Copy link
Contributor

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 %}

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.‏

Comment on lines 48 to +51
PageRepositoryInterface $pageRepository,
ChannelContextInterface $channelContext,
LocaleContextInterface $localeContext
LocaleContextInterface $localeContext,
DateTimeProviderInterface $dateTimeProvider

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 ‏

Copy link
Member Author

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

@madamebiz madamebiz added Status: needs update This Issue/PR needs update and removed Status: needs review Status: needs review labels Sep 25, 2024
@lanfisis lanfisis removed their request for review September 30, 2024 07:13
@maximehuran maximehuran mentioned this pull request Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: needs update This Issue/PR needs update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants