feat(#2072237): allow disabling File (Field) Paths processing site-wide and per entity#8
feat(#2072237): allow disabling File (Field) Paths processing site-wide and per entity#8Decipher wants to merge 1 commit into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (14)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (11)
📝 WalkthroughWalkthroughAdds a site-wide ChangesSite-wide enabled toggle and per-entity override support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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/Hook/EntityWithFileField.php`:
- Around line 58-62: The variable $override assigned from the untyped property
$entity->filefield_paths_settings may not be an array, which will cause
array_diff_key() to throw a TypeError. Add a type guard check using is_array()
on $override before calling array_diff_key($override, $fields) to ensure it
contains a valid array, and fall back to an empty array if the type check fails.
🪄 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 Plus
Run ID: 3a9fa764-277c-45ea-baf4-fd95b6901b7d
📒 Files selected for processing (12)
README.mdconfig/install/filefield_paths.settings.ymlconfig/schema/filefield_paths.schema.ymlfilefield_paths.api.phpfilefield_paths.installphpstan.neonsrc/Form/SettingsForm.phpsrc/Hook/EntityWithFileField.phptests/src/Kernel/EntityWithFileFieldOverrideTest.phptests/src/Kernel/InstallFunctionsTest.phptests/src/Kernel/SettingsFormTest.phptests/src/Unit/EntityWithFileFieldTest.php
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 8.x-1.x #8 +/- ##
===========================================
+ Coverage 79.72% 80.37% +0.64%
===========================================
Files 17 17
Lines 666 688 +22
===========================================
+ Hits 531 553 +22
Misses 135 135 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
8ccee2b to
7ed493c
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
filefield_paths.module (1)
151-163:⚠️ Potential issue | 🟠 MajorDeprecation messages reference non-existent method.
The deprecation attribute and
@trigger_error()both referencerecommendedFileScheme(), which does not exist onMoveFileProcessorInterface. The implementation correctly callsrecommendedTemporaryScheme()(the actual method defined in the interface). Update the deprecation message and attribute to reference the correct method name.🤖 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 `@filefield_paths.module` around lines 151 - 163, The deprecation messages in both the #[\Deprecated()] attribute and the `@trigger_error`() call within the filefield_paths_recommended_temporary_scheme() function incorrectly reference recommendedFileScheme() as the replacement method, but this method does not exist on MoveFileProcessorInterface. Update both deprecation messages to correctly reference recommendedTemporaryScheme() instead, which is the actual method being called in the function implementation.
🤖 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.
Outside diff comments:
In `@filefield_paths.module`:
- Around line 151-163: The deprecation messages in both the #[\Deprecated()]
attribute and the `@trigger_error`() call within the
filefield_paths_recommended_temporary_scheme() function incorrectly reference
recommendedFileScheme() as the replacement method, but this method does not
exist on MoveFileProcessorInterface. Update both deprecation messages to
correctly reference recommendedTemporaryScheme() instead, which is the actual
method being called in the function implementation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 60ff2f2e-6d85-4003-8d51-924efda45fb9
📒 Files selected for processing (18)
README.mdconfig/install/filefield_paths.settings.ymlconfig/schema/filefield_paths.schema.ymlfilefield_paths.api.phpfilefield_paths.installfilefield_paths.modulephpstan.neonsrc/Form/SettingsForm.phpsrc/Hook/EntityWithFileField.phpsrc/Hook/FieldWidgetSingleElementForm.phptests/modules/filefield_paths_test/src/StreamWrapper/FileFieldPathsDummyReadOnlyStreamWrapper.phptests/src/Functional/FileFieldPathsTestBase.phptests/src/Kernel/EntityWithFileFieldOverrideTest.phptests/src/Kernel/InstallFunctionsTest.phptests/src/Kernel/RedirectTest.phptests/src/Kernel/SettingsFormTest.phptests/src/Unit/EntityWithFileFieldTest.phptests/src/Unit/FieldWidgetSingleElementFormTest.php
✅ Files skipped from review due to trivial changes (6)
- filefield_paths.api.php
- config/install/filefield_paths.settings.yml
- config/schema/filefield_paths.schema.yml
- README.md
- tests/src/Kernel/RedirectTest.php
- tests/modules/filefield_paths_test/src/StreamWrapper/FileFieldPathsDummyReadOnlyStreamWrapper.php
🚧 Files skipped from review as they are similar to previous changes (8)
- phpstan.neon
- tests/src/Kernel/SettingsFormTest.php
- src/Form/SettingsForm.php
- tests/src/Kernel/InstallFunctionsTest.php
- filefield_paths.install
- tests/src/Kernel/EntityWithFileFieldOverrideTest.php
- tests/src/Unit/EntityWithFileFieldTest.php
- src/Hook/EntityWithFileField.php
0010b35 to
1d1831c
Compare
…de and per entity Add a site-wide "enabled" setting (config + settings form) and a transient `filefield_paths_settings` entity property so migrations and other programmatic saves can suppress or override processing for a single save without touching field configuration. Includes an update hook to default existing sites to enabled and a runtime requirements warning when disabled site-wide. Issue #2072237 by jose reyero, herved, trebormc, feng-shui, rudolfbyker, geek-merlin, vistree, deciphered.
1d1831c to
9d5a84c
Compare
Summary
Adds three independent ways to suppress File (Field) Paths processing, addressing
#2072237 ("Add option to
disable filefield paths when programmatically saving a node"), open since 2013:
enabledsetting on the module's settings form, persisted infilefield_paths.settings:enabled.filefield_paths_settingsruntime property onthe entity, read once per save and merged into the settings passed to
hook_filefield_paths_process_file(). Never persisted (a plain non-field entity property), soit only affects the single save it's set on -- no config save, no cache invalidation.
Closes #2072237
Background
The issue's 13-year comment thread contains many shaped attempts at a per-save override, none
committed, plus two recent unmerged attempts by the same contributor: an uploaded patch file
(per-field-item-value override, read at delta 0 only) and
MR !62 (a global config
toggle, currently conflicting against
8.x-1.x). Mapping the real migration scenarios this issueis meant to solve (disable one field across thousands of nodes, disable everything on one node,
disable the whole module temporarily, or some mixture) showed a single mechanism wasn't enough.
The entity-level override's shape generalizes an older idea from the thread
(
$entity->fielfield_paths_override_settings, a single property merged into the field's settings)rather than the unmerged per-field-item-value patch:
A field-name key scopes the override to that field and takes precedence; any other key applies to
every field. The
enabledkey is still checked inside the existingFieldItem::hasConfigurationEnabled()gate, so the override can only suppress processing that'salready enabled at the field-config level, never enable it on an unconfigured field.
Credit to jose reyero, geek-merlin, nwom, herved, hussainweb, trebormc, and feng-shui for the
years of patches and workarounds this design draws on, and to rudolfbyker (dolf) for the two
recent attempts that prompted re-examining the whole thread. MR !62 remains open separately; it
solves a narrower problem (global switch only) and still has its own merge conflicts, so it isn't
superseded by this PR.
Changes
src/Hook/EntityWithFileField.phpsrc/Form/SettingsForm.phpenabledcheckboxconfig/schema/filefield_paths.schema.yml,config/install/filefield_paths.settings.ymlenabledconfig keyfilefield_paths.installfilefield_paths_update_9002(), requirements warning when disabled site-widetests/src/Unit/EntityWithFileFieldTest.phptests/src/Kernel/EntityWithFileFieldOverrideTest.phptests/src/Kernel/InstallFunctionsTest.phptests/src/Kernel/SettingsFormTest.phpenabledcheckbox default and persistencefilefield_paths.api.php,README.mdphpstan.neonContentEntityInterfaceis a field access)Test plan
DRUPAL_VERSION=10 make test-unit-- 35/35 passDRUPAL_VERSION=10 make test-kernel-- 79/79 pass (2 pre-existing skips, unrelated)DRUPAL_VERSION=10 make lint-- PHPCS and PHPStan clean. Rector flags missing#[\Override]attributes on 5 files includingsrc/Form/SettingsForm.php; confirmed viagit stashagainst the clean8.x-1.xcheckout that this is pre-existing tech debt, notintroduced by this PR, so left untouched as out of scope.
$entity->filefield_paths_settingsbefore save,confirm the file is not moved; disable the global toggle and confirm
/admin/reports/statuswarns and no field is processed site-wide until re-enabledSummary by CodeRabbit
enabledsetting (defaulting to true when unset).