Skip to content

Fixed 'ImageHandler' and 'DatetimeHandler' compound parser shape.#370

Merged
AlexSkrypnyk merged 12 commits into
masterfrom
feature/compound-shape
May 18, 2026
Merged

Fixed 'ImageHandler' and 'DatetimeHandler' compound parser shape.#370
AlexSkrypnyk merged 12 commits into
masterfrom
feature/compound-shape

Conversation

@AlexSkrypnyk
Copy link
Copy Markdown
Collaborator

@AlexSkrypnyk AlexSkrypnyk commented May 18, 2026

Summary

Field handlers gain a shared normalise() helper on AbstractHandler that converts any loose input shape a caller naturally produces — a bare scalar, a list of scalars, a single keyed record, a list of records, or a mixed list of scalars and records — into a canonical list of records. Callers never need to know whether a field is single- or multi-column, never need to type column names like target_id or value for the simple case, and the handler always returns a uniform list of records that Drupal entity storage accepts. ImageHandler::expand() and DatetimeHandler::expand() now use normalise() instead of in-line shape sniffing; the three text handlers (TextHandler, TextLongHandler, TextWithSummaryHandler) were migrated from implements FieldHandlerInterface to extends AbstractHandler so they get the same helper.

The original bug — ImageHandler::expand() reading $values[0] as a string when the parser handed it [['target_id' => 'foo.jpg', ...]] and triggering TypeError — is fixed as a consequence. The branch also fixes the DrupalExtension smoke workflow that kept breaking whenever drupalextension bumped its minimum-stability floor.

Consumers (drupal-extension's EntityFieldParser, DrushDriver, etc.) can now pass whatever they have without inspecting the field's column structure first. That work happens in the consumer packages.

Changes

  • src/Drupal/Driver/Core/Field/AbstractHandler.php — added protected function normalise(mixed $values): array. Discovers the main property via $this->fieldInfo->getMainPropertyName(). Accepts five shapes (bare scalar, list of scalars, single record, list of records, mixed list); throws InvalidArgumentException for the ambiguous "positional plus named keys at the top level" shape (e.g. ['/path', 'alt' => 'A']) rather than silently picking an interpretation. Subclasses override normalise() only when they have custom shorthand (e.g. a future NameHandler "Family, Given" string).

  • src/Drupal/Driver/Core/Field/ImageHandler.phpexpand() now calls $this->normalise($values) and iterates the canonical records. Always returns a list of records (no flat-single-record return, no shape sniffing).

  • src/Drupal/Driver/Core/Field/DatetimeHandler.phpexpand() now calls $this->normalise($values) and iterates the canonical records. Returns a list of ['value' => …] records with each value formatted for storage.

  • src/Drupal/Driver/Core/Field/TextHandler.php, TextLongHandler.php, TextWithSummaryHandler.php — migrated from implements FieldHandlerInterface to extends AbstractHandler. expand() delegates to normalise(). Production wiring is unchanged (Core::getFieldHandler() already passes the stub/entity_type/field_name constructor args); test setup updated to follow the newInstanceWithoutConstructor() + reflection-injected fieldInfo pattern.

  • tests/Drupal/Tests/Driver/Unit/Core/Field/AbstractHandlerNormaliseTest.php — new. Single test method testNormalise driven by a 16-row data provider. 12 happy-path rows cover every accepted shape against multiple main-property names (target_id, value, uri); 4 throw rows cover the ambiguous-key cases (numeric-0 + named extras, gappy numeric + named, ordering variants). Each row carries (input, main_property, expected_output, expected_exception_class, expected_exception_message_fragment) — the test branches on whether an exception class was supplied. A test-local final subclass NormaliseTestHandler exists in the same file solely to provide the abstract surface so reflection can invoke the inherited normalise().

  • tests/Drupal/Tests/Driver/Unit/Core/Field/ImageHandlerTest.php — refactored. Two data-provider tests (testExpandUploadsFile, testExpandReusesManagedFile) now cover every loose shape a caller can naturally pass: bare scalar path, list of paths, single record, list of records, multi-record, plus the same shape variations for the reuse-managed-file path. createHandler() injects a fieldInfo stub returning 'target_id'.

  • tests/Drupal/Tests/Driver/Unit/Core/Field/DatetimeHandlerTest.phptestExpandPreservesEmptyValuesAsNull is now data-driven (5 shape variants); createHandler() stubs both getSetting('datetime_type') and getMainPropertyName().

  • tests/Drupal/Tests/Driver/Unit/Core/Field/TextHandlerTest.php, TextLongHandlerTest.php, TextWithSummaryHandlerTest.php — updated to construct the handler via newInstanceWithoutConstructor() + reflection-injected fieldInfo, matching the pattern used by other handler tests.

  • Kernel tests (ImageHandlerKernelTest.php, ImageHandlerReuseKernelTest.php, DatetimeHandlerKernelTest.php) — inputs use the canonical record shape, which the new normalise() returns unchanged.

  • .github/workflows/ci.ymlDrupalExtension smoke job: the path repo for drupal/drupal-driver is now declared at version 3.0.99 (stable) instead of 3.0.99-alpha. The previous alpha-suffixed declaration broke every time drupalextension bumped its minimum-stability floor (alpha → beta → RC). Declaring stable satisfies any floor up to and including stable, decoupling this workflow from the consumer's stability progression.

Before / After

Caller decoupling — ImageHandler

Before (caller must know 'target_id' even for the trivial case):
  $stub->setValue('field_image', [['target_id' => '/path/foo.jpg']]);

After (caller passes whatever's natural; normalise() handles the rest):
  $stub->setValue('field_image', '/path/foo.jpg');                     // bare path
  $stub->setValue('field_image', ['/path/a.jpg', '/path/b.jpg']);      // list of paths
  $stub->setValue('field_image', ['target_id' => '/path/foo.jpg',      // single record
                                  'alt' => 'A', 'title' => 'B']);
  $stub->setValue('field_image', [['target_id' => '/path/foo.jpg',     // list of records
                                   'alt' => 'A']]);
  // All four call sites end up at the same canonical
  //   [['target_id' => N, 'alt' => …, 'title' => …]]
  // inside ImageHandler::expand() and produce the same stored entity.
ImageHandler::expand() shape pipeline

Before (sniff $values[0], collapse single-record return to flat assoc):
  expand($mixed_input)
    if (is_array($values[0])) treat $values as records
    else                      wrap $values as one record
    foreach each record       resolve target_id
    return count($expanded) === 1 ? $expanded[0] : $expanded
                                  ^ dual return shape

After (canonical pipeline, single return shape):
  expand($mixed_input)
    $records = $this->normalise($values)              // AbstractHandler helper
    foreach each $record                              // always a list
      resolve target_id, default alt/title to NULL
    return list of records                            // always a list
DrupalExtension smoke workflow — stability coupling

Before (recurring failure pattern):
  drupalextension main composer.json:  "minimum-stability": "RC"
  ci.yml declares path repo:           "drupal/drupal-driver": "3.0.99-alpha"
                                       (alpha < RC -> Composer refuses install)

  Every time drupalextension bumps its stability floor, ci.yml has to follow:
    alpha -> beta -> RC -> stable

After:
  ci.yml declares path repo:           "drupal/drupal-driver": "3.0.99"
                                       (stable -> satisfies any floor up to stable)

Summary by CodeRabbit

Release Notes

  • Refactor

    • Standardized input normalization across field handlers (text, image, datetime) to consistently process various input shapes and formats.
    • Enhanced handling of empty values and mixed input formats in field handlers.
  • Tests

    • Expanded test coverage for field handler input normalization and edge cases.
  • Chores

    • Updated CI workflow for stable version mappings.

Review Change Stack

@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 33 minutes and 59 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: 1c70fad5-d840-43a0-a302-03da1a91e568

📥 Commits

Reviewing files that changed from the base of the PR and between 8769108 and 275fe01.

📒 Files selected for processing (8)
  • src/Drupal/Driver/Core/Field/AbstractHandler.php
  • src/Drupal/Driver/Core/Field/ImageHandler.php
  • tests/Drupal/Tests/Driver/Unit/Core/Field/AbstractHandlerNormaliseTest.php
  • tests/Drupal/Tests/Driver/Unit/Core/Field/DatetimeHandlerTest.php
  • tests/Drupal/Tests/Driver/Unit/Core/Field/ImageHandlerTest.php
  • tests/Drupal/Tests/Driver/Unit/Core/Field/TextHandlerTest.php
  • tests/Drupal/Tests/Driver/Unit/Core/Field/TextLongHandlerTest.php
  • tests/Drupal/Tests/Driver/Unit/Core/Field/TextWithSummaryHandlerTest.php
📝 Walkthrough

Walkthrough

Add AbstractHandler::normalise() and update handlers (Datetime, Image, Text variants) to consume canonical record-list shapes; expand() implementations now return newly built record arrays. Unit and kernel tests converted to data-provider-driven forms and adjusted to assert the compound-parser record-list shape.

Changes

Field handler normalization and tests

Layer / File(s) Summary
Normalise helper and tests
src/Drupal/Driver/Core/Field/AbstractHandler.php, tests/Drupal/Tests/Driver/Unit/Core/Field/AbstractHandlerNormaliseTest.php
Adds AbstractHandler::normalise(mixed): array and comprehensive unit tests covering valid and invalid input shapes via a test-only subclass and reflection utilities.
DatetimeHandler canonical records
src/Drupal/Driver/Core/Field/DatetimeHandler.php, tests/Drupal/Tests/Driver/Unit/Core/Field/DatetimeHandlerTest.php, tests/Drupal/Tests/Driver/Kernel/Core/Field/DatetimeHandlerKernelTest.php
expand() now calls normalise(), builds a new formatted array of records (['value' => ...] or NULL), and tests/kernels updated to assert compound record-list round-trips and empty-value handling.
ImageHandler canonical records & kernel updates
src/Drupal/Driver/Core/Field/ImageHandler.php, tests/Drupal/Tests/Driver/Kernel/Core/Field/ImageHandlerKernelTest.php, tests/Drupal/Tests/Driver/Kernel/Core/Field/ImageHandlerReuseKernelTest.php
expand() normalises inputs, handles per-record upload/resolve, and returns per-record target_id/alt/title; kernel tests switched to nested record-list input shapes.
ImageHandler unit tests (data-providers)
tests/Drupal/Tests/Driver/Unit/Core/Field/ImageHandlerTest.php
Replace single-case tests with two #[DataProvider]-backed tests covering upload and reuse branches across input shape variants; inject field storage main property for normalisation; helper methods made protected and stubs modernized.
FileHandler unit tests (data-providers)
tests/Drupal/Tests/Driver/Unit/Core/Field/FileHandlerTest.php
Convert FileHandler tests to parameterized data-provider tests for upload and managed-file reuse paths; modernize helper visibility and anonymous stub constructor promotion; add DataProvider import.
Text handlers inheritance and tests
src/Drupal/Driver/Core/Field/TextHandler.php, src/Drupal/Driver/Core/Field/TextLongHandler.php, src/Drupal/Driver/Core/Field/TextWithSummaryHandler.php, tests/*TextHandlerTest.php
Change Text* handlers to extend AbstractHandler and delegate expand() to normalise(); update unit tests to construct handlers via reflection and assert canonical record-list outputs.
CI workflow
.github/workflows/ci.yml
Update extension job to map local drupal-driver path repository as stable drupal/drupal-driver: 3.0.99 and adjust step documentation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • jhedstrom/DrupalDriver#341: Adds initial kernel round-trip infrastructure and DatetimeHandler/ImageHandler kernel tests that this PR extends with compound-parser shape coverage.
  • jhedstrom/DrupalDriver#363: Modifies AbstractHandler-related code; changes here build on similar core handler foundations.
  • jhedstrom/DrupalDriver#342: Related edits touching AbstractHandler and handler normalization behaviors.

🐰 A rabbit's ode to compound shapes!

I hopped through arrays both flat and wide,
Now every record finds a proper guide.
Tests sing in providers, helpers tucked away,
Normalised fields hop merrily today! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 78.26% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: fixing the compound parser shape for ImageHandler and DatetimeHandler, which are the primary subjects of this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/compound-shape

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/Drupal/Tests/Driver/Unit/Core/Field/DatetimeHandlerTest.php (1)

77-83: ⚡ Quick win

Add one assertion for the numeric-index compound fallback path.

This test validates ['value' => ...], but expand() also supports [0 => ...]. Adding that case here will lock in both accepted parser shapes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/Drupal/Tests/Driver/Unit/Core/Field/DatetimeHandlerTest.php` around
lines 77 - 83, Update the testExpandHandlesCompoundParserShapeEmpty test to also
assert the numeric-index compound fallback path: call
$this->createHandler('datetime')->expand with elements that use key 0 (e.g. [[0
=> ''], [0 => NULL]]) and assert the result is [NULL, NULL]; this ensures both
supported parser shapes ('value' and numeric index 0) are covered for the
expand() method.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Drupal/Driver/Core/Field/DatetimeHandler.php`:
- Around line 27-33: The loop in DatetimeHandler that builds $formatted
reindexes the array and drops original delta keys; change the foreach over
$values to preserve keys (e.g. foreach ($values as $delta => $value)) and assign
formatted results back using that same key (set $formatted[$delta] =
$this->formatDateValue(...)) so DatetimeHandler and formatDateValue keep
incoming delta-keyed compound shapes intact.

---

Nitpick comments:
In `@tests/Drupal/Tests/Driver/Unit/Core/Field/DatetimeHandlerTest.php`:
- Around line 77-83: Update the testExpandHandlesCompoundParserShapeEmpty test
to also assert the numeric-index compound fallback path: call
$this->createHandler('datetime')->expand with elements that use key 0 (e.g. [[0
=> ''], [0 => NULL]]) and assert the result is [NULL, NULL]; this ensures both
supported parser shapes ('value' and numeric index 0) are covered for the
expand() method.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2807be7f-da88-4c2f-8b06-ac40c5584cbb

📥 Commits

Reviewing files that changed from the base of the PR and between 7efe05f and 679ed0b.

📒 Files selected for processing (7)
  • src/Drupal/Driver/Core/Field/DatetimeHandler.php
  • src/Drupal/Driver/Core/Field/ImageHandler.php
  • tests/Drupal/Tests/Driver/Kernel/Core/Field/DatetimeHandlerKernelTest.php
  • tests/Drupal/Tests/Driver/Kernel/Core/Field/ImageHandlerKernelTest.php
  • tests/Drupal/Tests/Driver/Unit/Core/Field/DatetimeHandlerTest.php
  • tests/Drupal/Tests/Driver/Unit/Core/Field/FileHandlerTest.php
  • tests/Drupal/Tests/Driver/Unit/Core/Field/ImageHandlerTest.php

Comment on lines 27 to 33
foreach ($values as $value) {
// EntityFieldParser emits compound-mode deltas as '['value' => '...']'
// arrays. Sibling DaterangeHandler accepts the same shape; mirror it
// here so 'datetime' fields work uniformly with the parser.
$date = is_array($value) ? ($value['value'] ?? $value[0] ?? NULL) : $value;
$formatted[] = $this->formatDateValue($date, $site_timezone, $storage_timezone);
}
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot May 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Preserve incoming delta keys when formatting records.

$formatted[] reindexes results and discards original delta keys. Since this handler now accepts delta-keyed compound shapes, keep keys stable during transformation.

Suggested fix
-    foreach ($values as $value) {
+    foreach ($values as $delta => $value) {
       // EntityFieldParser emits compound-mode deltas as '['value' => '...']'
       // arrays. Sibling DaterangeHandler accepts the same shape; mirror it
       // here so 'datetime' fields work uniformly with the parser.
       $date = is_array($value) ? ($value['value'] ?? $value[0] ?? NULL) : $value;
-      $formatted[] = $this->formatDateValue($date, $site_timezone, $storage_timezone);
+      $formatted[$delta] = $this->formatDateValue($date, $site_timezone, $storage_timezone);
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Drupal/Driver/Core/Field/DatetimeHandler.php` around lines 27 - 33, The
loop in DatetimeHandler that builds $formatted reindexes the array and drops
original delta keys; change the foreach over $values to preserve keys (e.g.
foreach ($values as $delta => $value)) and assign formatted results back using
that same key (set $formatted[$delta] = $this->formatDateValue(...)) so
DatetimeHandler and formatDateValue keep incoming delta-keyed compound shapes
intact.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declining this one. Every sibling handler in src/Drupal/Driver/Core/Field/ reindexes via $arr[]:

  • FileHandler::expand()$files[] = [...]
  • ImageHandler::expand()$expanded[] = [...]
  • DaterangeHandler::expand()$result[] = [...]
  • LinkHandler::expand()$links[] = $link
  • NameHandler::expand()$names[] = ...
  • AddressHandler::expand()$result[] = ...

DatetimeHandler now matches that pattern (the whole point of this change was to mirror DaterangeHandler). Preserving incoming delta keys here would make DatetimeHandler the odd one out without buying anything observable: EntityFieldParser only emits numerically-keyed records (0, 1, 2…) and Drupal's entity field storage re-indexes on save, so the keys are never carried through to the stored entity.

If we ever decide that handlers should preserve delta keys, that's a project-wide change across all eight handlers, not a one-off here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexSkrypnyk, that's a well-reasoned argument — the consistency with all eight sibling handlers and the fact that Drupal re-indexes on save makes preserving delta keys here genuinely redundant. Acknowledged, withdrawing the suggestion.

(╯°□°)╯ 🐇 (graceful retreat)


✏️ Learnings added
Learnt from: AlexSkrypnyk
Repo: jhedstrom/DrupalDriver PR: 370
File: src/Drupal/Driver/Core/Field/DatetimeHandler.php:27-33
Timestamp: 2026-05-18T10:25:22.749Z
Learning: In `src/Drupal/Driver/Core/Field/` (DrupalDriver project, PHP), all field handler `expand()` methods consistently reindex their output arrays using `$arr[] = ...` (append syntax). This is intentional and project-wide: EntityFieldParser only emits numerically-keyed (0, 1, 2…) records, and Drupal's entity field storage re-indexes on save. Suggestions to preserve incoming delta keys in any individual handler should be declined as the pattern is uniform across all handlers (FileHandler, ImageHandler, DaterangeHandler, DatetimeHandler, LinkHandler, NameHandler, AddressHandler, etc.).

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 18, 2026

Code coverage (threshold: 95%)



Code Coverage Report Summary:
  Classes: 71.88% (23/32)
  Methods: 91.19% (207/227)
  Lines:   97.24% (1091/1122)

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Drupal/Driver/Core/Field/ImageHandler.php`:
- Around line 29-31: Check for and validate the required target_id before
calling resolveExistingFile/uploadAndSave in the loop that processes $records
(the foreach in expand()); specifically ensure $record has a non-empty
'target_id' (e.g., isset/array_key_exists and not empty) and if missing or
invalid throw a clear exception (e.g., InvalidArgumentException) or return a
meaningful error rather than passing an invalid path into resolveExistingFile()
or uploadAndSave(); update the logic around resolveExistingFile($file_path) and
uploadAndSave($file_path) to only run when $file_path is present and valid and
reference the expand(), normalise(), resolveExistingFile, and uploadAndSave
symbols when making the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8774b9be-649c-4cb2-95b2-de3bd60ed200

📥 Commits

Reviewing files that changed from the base of the PR and between 679ed0b and 8769108.

📒 Files selected for processing (17)
  • .github/workflows/ci.yml
  • src/Drupal/Driver/Core/Field/AbstractHandler.php
  • src/Drupal/Driver/Core/Field/DatetimeHandler.php
  • src/Drupal/Driver/Core/Field/ImageHandler.php
  • src/Drupal/Driver/Core/Field/TextHandler.php
  • src/Drupal/Driver/Core/Field/TextLongHandler.php
  • src/Drupal/Driver/Core/Field/TextWithSummaryHandler.php
  • tests/Drupal/Tests/Driver/Kernel/Core/Field/DatetimeHandlerKernelTest.php
  • tests/Drupal/Tests/Driver/Kernel/Core/Field/ImageHandlerKernelTest.php
  • tests/Drupal/Tests/Driver/Kernel/Core/Field/ImageHandlerReuseKernelTest.php
  • tests/Drupal/Tests/Driver/Unit/Core/Field/AbstractHandlerNormaliseTest.php
  • tests/Drupal/Tests/Driver/Unit/Core/Field/DatetimeHandlerTest.php
  • tests/Drupal/Tests/Driver/Unit/Core/Field/FileHandlerTest.php
  • tests/Drupal/Tests/Driver/Unit/Core/Field/ImageHandlerTest.php
  • tests/Drupal/Tests/Driver/Unit/Core/Field/TextHandlerTest.php
  • tests/Drupal/Tests/Driver/Unit/Core/Field/TextLongHandlerTest.php
  • tests/Drupal/Tests/Driver/Unit/Core/Field/TextWithSummaryHandlerTest.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Drupal/Driver/Core/Field/DatetimeHandler.php

Comment thread src/Drupal/Driver/Core/Field/ImageHandler.php
@AlexSkrypnyk AlexSkrypnyk merged commit abee343 into master May 18, 2026
13 checks passed
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