Skip to content

Added 'SmartdateHandler' for the 'smart_date' contrib module.#371

Merged
AlexSkrypnyk merged 2 commits into
masterfrom
feature/smartdate-handler
May 18, 2026
Merged

Added 'SmartdateHandler' for the 'smart_date' contrib module.#371
AlexSkrypnyk merged 2 commits into
masterfrom
feature/smartdate-handler

Conversation

@AlexSkrypnyk
Copy link
Copy Markdown
Collaborator

Summary

Adds SmartdateHandler, a dedicated field handler for the smartdate field type provided by the drupal/smart_date contrib module. Prior to v3.0, unknown multi-column fields were silently passed through DefaultHandler; v3.0 hardened DefaultHandler to throw a RuntimeException for any field with multiple storage columns it cannot recognise. Because smartdate stores six columns (value, end_value, duration, rrule, rrule_index, timezone), every attempt to write a smart date field via the driver triggered that exception. The new handler closes the gap by normalising positional or named input records, parsing numeric or strtotime()-compatible date strings, auto-deriving duration when not supplied, and emitting the six-column shape that Drupal's smart date storage expects.

Changes

Handler implementation - src/Drupal/Driver/Core/Field/SmartdateHandler.php

New SmartdateHandler extends AbstractHandler. Accepts a single positional pair [start, end], a single named record ['value' => ..., 'end_value' => ...], or a list of either form for multi-delta fields. Numeric values pass through as Unix timestamps; non-numeric strings are parsed via strtotime() and resolve to NULL when unparseable. Duration is auto-derived as (end - start) / 60 clamped to zero when both endpoints are present and no explicit duration is supplied.

Unit test - tests/Drupal/Tests/Driver/Unit/Core/Field/SmartdateHandlerTest.php

Fourteen data-provider cases cover: empty input, non-array input, positional pair, named record, multi-delta list, explicit duration override, single-endpoint default, NULL endpoints, reversed-endpoint clamping, strtotime() string parsing, rrule/timezone passthrough, unparseable string, numeric string casting, and non-array record skipping.

Kernel test - tests/Drupal/Tests/Driver/Kernel/Core/Field/SmartdateHandlerKernelTest.php

Round-trip test via the Core driver that attaches a smartdate field to a node, writes a named record with numeric timestamps and explicit duration through the driver, and asserts Drupal stores and returns the payload intact.

README handler table - src/Drupal/Driver/Core/Field/README.md

Added H11 row documenting the smartdate field type, SmartdateHandler class, and the six-column auto-duration behaviour.

Dev dependency - composer.json

Added drupal/smart_date: ^4.2 to require-dev so the kernel test environment can install the module.

Before / After

Before
──────
smartdate field
      │
      ▼
 DefaultHandler
      │
      ▼
  RuntimeException
  (unknown multi-column field)


After
─────
smartdate field
      │
      ▼
SmartdateHandler
      │
      ├─ accepts positional [start, end] or named record
      ├─ parses numeric timestamps or strtotime() strings
      ├─ auto-derives duration = (end - start) / 60, clamped ≥ 0
      │
      ▼
  six-column storage record
  { value, end_value, duration, rrule, rrule_index, timezone }
      │
      ▼
  Drupal smart_date storage

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

Warning

Rate limit exceeded

@AlexSkrypnyk has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 35 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 90c6c955-64bf-4823-8994-fa1e5f2f508c

📥 Commits

Reviewing files that changed from the base of the PR and between abee343 and af8375c.

📒 Files selected for processing (5)
  • composer.json
  • src/Drupal/Driver/Core/Field/README.md
  • src/Drupal/Driver/Core/Field/SmartdateHandler.php
  • tests/Drupal/Tests/Driver/Kernel/Core/Field/SmartdateHandlerKernelTest.php
  • tests/Drupal/Tests/Driver/Unit/Core/Field/SmartdateHandlerTest.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/smartdate-handler

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

Code coverage (threshold: 95%)



Code Coverage Report Summary:
  Classes: 72.73% (24/33)
  Methods: 91.27% (209/229)
  Lines:   97.30% (1118/1149)

Per-class coverage
Drupal\Driver\Alias\CreationAliasRegistryTrait               100.00%
Drupal\Driver\Alias\RolesAlias                                85.71%
Drupal\Driver\BlackboxDriver                                 100.00%
Drupal\Driver\Core\Alias\AuthorAlias                          94.12%
Drupal\Driver\Core\Alias\ParentTermAlias                      90.62%
Drupal\Driver\Core\Alias\VocabularyMachineNameAlias           88.89%
Drupal\Driver\Core\Core                                       96.06%
Drupal\Driver\Core\Field\AbstractHandler                      95.65%
Drupal\Driver\Core\Field\AddressHandler                      100.00%
Drupal\Driver\Core\Field\BooleanHandler                      100.00%
Drupal\Driver\Core\Field\DaterangeHandler                    100.00%
Drupal\Driver\Core\Field\DatetimeHandler                     100.00%
Drupal\Driver\Core\Field\DefaultHandler                      100.00%
Drupal\Driver\Core\Field\EmbridgeAssetItemHandler              0.00%
Drupal\Driver\Core\Field\EntityReferenceHandler              100.00%
Drupal\Driver\Core\Field\EntityReferenceRevisionsHandler      91.11%
Drupal\Driver\Core\Field\FieldClassifier                      94.44%
Drupal\Driver\Core\Field\FileHandler                         100.00%
Drupal\Driver\Core\Field\ImageHandler                        100.00%
Drupal\Driver\Core\Field\LinkHandler                         100.00%
Drupal\Driver\Core\Field\ListFloatHandler                      0.00%
Drupal\Driver\Core\Field\ListHandlerBase                     100.00%
Drupal\Driver\Core\Field\ListIntegerHandler                    0.00%
Drupal\Driver\Core\Field\ListStringHandler                     0.00%
Drupal\Driver\Core\Field\NameHandler                         100.00%
Drupal\Driver\Core\Field\OgStandardReferenceHandler            0.00%
Drupal\Driver\Core\Field\SmartdateHandler                    100.00%
Drupal\Driver\Core\Field\SupportedImageHandler               100.00%
Drupal\Driver\Core\Field\TextHandler                         100.00%
Drupal\Driver\Core\Field\TextLongHandler                     100.00%
Drupal\Driver\Core\Field\TextWithSummaryHandler              100.00%
Drupal\Driver\Core\Field\TimeHandler                         100.00%
Drupal\Driver\DrupalDriver                                    98.86%
Drupal\Driver\DrushDriver                                    100.00%
Drupal\Driver\Entity\EntityStub                              100.00%
Drupal\Driver\Exception\BootstrapException                   100.00%
Drupal\Driver\Exception\CreationAliasResolutionException       0.00%
Drupal\Driver\Exception\Exception                            100.00%
Drupal\Driver\Exception\UnsupportedDriverActionException     100.00%

@AlexSkrypnyk AlexSkrypnyk merged commit d07fa7d into master May 18, 2026
13 checks passed
@AlexSkrypnyk AlexSkrypnyk deleted the feature/smartdate-handler branch May 18, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant