Problem/Motivation

1. A date ecosystem module that is being increasingly adopted in Drupal is https://drupal.org/project/smart_date . This module provides its own field type, smartdate. Although the 3.x version of this module provides support for the Drupal core daterange field for non-recurring date instances, its implementation for recurring date instances only supports its smartdate field type.

2. Although the module provides some robust date formatting configuration, Smart Date does not currently support AP date style formatting directly. Rather than adding AP date style as an additional formatter to that module, it would be most efficient to add a minimal amount of logic in the Date AP Style module to be able to render fields of type smartdate in the range formatter.

Proposed resolution

1. Add field formatter annotation to specify that the daterange_ap_style formatter supports the smartdate field type.
2. Add logic that parses the entity schema of the smartdate field type to derive the start & end timestamps.

Alternative considered: add a new field formatter to Smart Date that would extend the field formatter provided by Date AP Style to support smartdate field type. The disadvantage with this approach is that it would have an explicit dependency on the Date AP Style module (this could be made opt-in by bundling the AP-style formatter in its own sub-module in Smart Date that has a dependency on Date AP Style, but that doesn't seem ideal). In contrast, the proposed resolution makes the dependency implicit, supporting the field type smartdate in the Date AP Style range formatter.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mark_fullmer created an issue. See original summary.

mark_fullmer’s picture

StatusFileSize
new1.51 KB

Status: Needs review » Needs work

The last submitted patch, 2: 3167284-support-smartdate-2.patch, failed testing. View results

mark_fullmer’s picture

Status: Needs work » Needs review

Setting back to "Needs review" -- testbot marked this as failed, though there are no tests, and the code standards problems identified are not introduced by the patch.

  • shelane committed 1f7d6d3 on 8.x-1.x authored by mark_fullmer
    Issue #3167284 by mark_fullmer: Support Smart Date field type in...
shelane’s picture

Status: Needs review » Fixed
shelane’s picture

Status: Fixed » Needs work

I am reverting this patch because it caused an error for the core date range:

The website encountered an unexpected error. Please try again later.

InvalidArgumentException: The timestamp must be numeric. in Drupal\Component\Datetime\DateTimePlus::createFromTimestamp() (line 201 of core/lib/Drupal/Component/Datetime/DateTimePlus.php).

Drupal\date_ap_style\ApStyleDateFormatter->formatRange(Array, Array, 'UTC', 'en') (Line: 311)
Drupal\date_ap_style\Plugin\Field\FieldFormatter\ApStyleDateRangeFieldFormatter->viewElements(Object, 'en') (Line: 89)
Drupal\Core\Field\FormatterBase->view(Object, 'en') (Line: 263)
Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple(Array) (Line: 267)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildMultiple(Array) (Line: 351)
Drupal\Core\Entity\EntityViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 24)
Drupal\node\NodeViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 293)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 250)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func_array(Array, Array) (Line: 100)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. Support for this callback implementation is deprecated in 8.8.0 and will be removed in Drupal 9.0.0. See https://www.drupal.org/node/2966725', 'silenced_deprecation', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 781)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 372)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 67)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Though I know I need tests, this will now especially need a test in order to ensure that both date type formatters work.

  • shelane committed 277b291 on 8.x-1.x
    Revert "Issue #3167284 by mark_fullmer: Support Smart Date field type in...

trackleft2 made their first commit to this issue’s fork.

trackleft2’s picture

OOps, looks like one review in gitlab makes 1000 comments here:

Made a MR for adding a field type parameter that we can check to make sure we are looking at smartdate.
https://git.drupalcode.org/project/date_ap_style/-/merge_requests/2/diff...

Additionally fixed the smart date ALL DAY functionality.

trackleft2’s picture

Status: Needs work » Needs review
trackleft2’s picture

Version: 8.x-1.x-dev » 8.x-1.0
StatusFileSize
new7.98 KB

Here's a patch against version 1.0

trackleft2’s picture

StatusFileSize
new8.45 KB
new7.77 KB

OK, it looks like I had the logic slightly wrong in #14 and #15, here is a better one that works now.

To use
Enable Smart Date
Create a field that uses smart date range
Add the field to a node type
Create a few new pieces of content using that node type

Test 1 Start date filled out, "All day" box filled, End date set.... No time entry necessary.
Test 2 Start date and time filled out duration field with 0 value
Test 3 Start and end date and time filled out,
Test 4 Start date filled and start time 12:00 PM Midnight on start date.

Sorry for all of the noise while I figure this out.

Shoshana Mayden’s picture

Tested this patch locally with an event content type using smart date and ap style together. It worked as expected for me.

trackleft2’s picture

It seems there is still a minor issue with smart date displaying noon and midnight even when those boxes are not set.

shelane’s picture

@trackleft2 How would you like to handle the noon and midnight? Merge this and make that a separate issue or wait for a fix?

trackleft2’s picture

@shelane, I'll work on getting a fix in tomorrow, thanks for checking.

shelane’s picture

@trackleft2 feel free to commit it when you feel it’s ready.

joegraduate made their first commit to this issue’s fork.

joegraduate’s picture

StatusFileSize
new8.11 KB

Updated 3167284-support-smart-date branch in issue fork with commits from issue fork's 8.x-1.x branch and rebased on the latest project 8.x-1.x branch and then re-opened original MR !1 (because working with the issue fork's 8.x-1.x branch was awkward/confusing. Also added some minor whitespace cleanup commits.

Also adding a patch file (generated from MR !1 branch) that can be used in composer builds for testing.

Status: Needs review » Needs work

The last submitted patch, 24: 3167284-24.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

joegraduate’s picture

Status: Needs work » Needs review
StatusFileSize
new8.11 KB

Setting back to Needs review since no tests (or tests failures) exist.

Updated patch with fixed syntax error.

joegraduate’s picture

StatusFileSize
new9.03 KB
new4.12 KB

Updated patch with PHPCS fixes.

Status: Needs review » Needs work

The last submitted patch, 27: 3167284-27.patch, failed testing. View results

joegraduate’s picture

Status: Needs work » Needs review

No tests exist so there were no actual failures.

  • shelane committed 2588349 on 8.x-1.x authored by trackleft2
    Issue #3167284 by joegraduate, trackleft2, mark_fullmer, shelane:...
shelane’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.