Repository navigation
[6.x] Fix “is not one of” in ID-based condition rules and the asset kind param - #20786
Conversation
The Section, Entry Type, Volume, and Affiliated Site rules passed their param value, such as ['not', 1, 2], to query methods that run a plain whereIn(), so “is not one of” matched only the excluded items. The Site Group rule looked 'not' up as a group UID, dropped it, and matched the selected groups instead of excluding them. BaseMultiSelectConditionRule::paramIds() now resolves the param value against the rule's table, the way the queries' own sectionId, typeId, and volumeId params do, so these rules pass a list of IDs. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1e9a6-291b-7063-a7f7-210df917e3f1
kind('not image') still matched images, because files with the kind's
extensions were OR'd back in. Those extensions are now excluded too.
The extension check also parses the value, so kind('image, audio')
matches files by extension like kind(['image', 'audio']) does.
Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1e9a6-291b-7063-a7f7-210df917e3f1
📚 Storybook previews@craftcms/ui — open Storybook No changed components detected in this Storybook. resources/js — open Storybook No changed components detected in this Storybook. |
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved filtering bugs allow excluded records through, reject valid sectionless or unaffiliated records, include entries in deleted sections, and apply OR semantics to AND asset-kind conditions.
6 open issues
Empty volume exclusion resolves to no filter · New Kind extensions bypass the parsed AND operator · New Section exclusion rejects sectionless entries · New Raw section lookup includes soft-deleted sections · New Empty type exclusion resolves to no filter · New Site exclusion mishandles NULL and empty ID lists · New
What changed in this PR
This PR addresses incorrect “is not one of” filtering in Craft’s element conditions and updates asset-kind queries to handle exclusions and comma-separated values.
Changes:
- Adds shared ID resolution for section, entry-type, volume, affiliated-site, and site-group conditions.
- Updates asset-kind extension checks to respect negation.
- Adds regression coverage for negative conditions and asset-kind parameters.
| File | Description |
|---|---|
tests/Feature/User/Conditions/UserConditionRulesTest.php |
Adds affiliated-site exclusion coverage. |
tests/Feature/Entry/Conditions/EntryConditionRulesTest.php |
Expands section and entry-type filtering coverage. |
tests/Feature/Element/Queries/Concerns/Asset/QueriesAssetPropertiesTest.php |
Covers comma-separated and negated asset kinds. |
tests/Feature/Element/Conditions/ElementConditionRulesTest.php |
Adds site-group exclusion coverage. |
tests/Feature/Asset/Conditions/AssetConditionRulesTest.php |
Adds volume exclusion coverage. |
src/User/Conditions/AffiliatedSiteConditionRule.php |
Resolves site conditions into IDs before filtering. |
src/Entry/Conditions/TypeConditionRule.php |
Uses resolved entry-type IDs. |
src/Entry/Conditions/SectionConditionRule.php |
Uses shared section-ID resolution. |
src/Element/Queries/Concerns/Asset/QueriesAssetProperties.php |
Parses kind parameters and negates extension checks. |
src/Element/Conditions/SiteGroupConditionRule.php |
Resolves group IDs before collecting sites. |
src/Condition/BaseMultiSelectConditionRule.php |
Adds the shared paramIds() resolver. |
src/Asset/Conditions/VolumeConditionRule.php |
Uses resolved volume IDs. |
Review effort: Balanced
…rules - paramIds() skips soft-deleted rows, so “has a value” and “is not one of” no longer match entries in trashed sections. - Excluding every entry type or volume now matches nothing, rather than resolving to an empty ID list that applyTypeId() and applyVolumeId() ignored. - “Is not one of” on the Affiliated Site rule now matches users without an affiliated site, as matchElement() already did. - The Section rule's matchElement() no longer matches sectionless entries, which its query leaves out. Amp-Thread-ID: https://ampcode.com/threads/T-01a1e9a6-291b-7063-a7f7-210df917e3f1 Co-authored-by: Amp <amp@ampcode.com>
A file has only one kind, so kind('and image, audio') can't match any
file. The extension check used to OR in every listed kind's extensions.
Amp-Thread-ID: https://ampcode.com/threads/T-01a1e9a6-291b-7063-a7f7-210df917e3f1
Co-authored-by: Amp <amp@ampcode.com>
There was a problem hiding this comment.
🟡 Changes recommended
Negated section filters can incorrectly alter outer-query structure settings and hierarchy data, while AND kind filters can omit assets that match by filename extension.
2 open issues
6 resolved since last review
Review effort: Balanced
The Section and Section Type rules used EntryQuery::applySectionId(), which sets the outer query's structureId or withStructure when one section is left. In an “or” condition group, entries that another rule matched then got the wrong structure ID or lost their structure data. The rules now filter entries.sectionId directly. kind() with “or” or “and” now checks each kind as its own group of “stored kind, or one of its extensions”, combined with the param's operator. kind(['and', 'image']) matches files by extension again, and kinds that share an extension, such as audio and video with .ogg, can both match one file. Amp-Thread-ID: https://ampcode.com/threads/T-01a1e9a6-291b-7063-a7f7-210df917e3f1 Co-authored-by: Amp <amp@ampcode.com>
The kind param is already parsed into values, so passing each one to
whereParam() as a string parsed it again. kind('drawing\,cad') was split
into “drawing” and “cad”, and a kind named like an operator would have
been read as one.
Amp-Thread-ID: https://ampcode.com/threads/T-01a1e9a6-291b-7063-a7f7-210df917e3f1
Co-authored-by: Amp <amp@ampcode.com>


Description
Condition rules that filter by ID passed their param value straight to query methods that run a plain
whereIn(). For “is not one of”, that value is['not', …ids], so the rule matched only the excluded items. A newBaseMultiSelectConditionRule::paramIds()resolves the value against the rule's table first, the way the queries' ownsectionId/typeId/volumeIdparams do.The asset query's
kindparam had the same problem withnot. Files with the kind's extensions were OR'd back in, sokind('not image')still matched images:applyKind('not image') kind != 'image' - OR filename LIKE '%.jpg' OR … + AND filename NOT LIKE '%.jpg' AND …The extension check also parses the value now, so
kind('image, audio')matches files by extension likekind(['image', 'audio'])does.Also, after review:
paramIds()skips soft-deleted rows, so entries in trashed sections don't match “has a value” or “is not one of”.applyTypeId()andapplyVolumeId()treat[]as no matches, asapplySectionId()already did.affiliatedSiteId NOT IN (…) OR IS NULL, so users without an affiliated site match, as they do inmatchElement().matchElement()no longer matches sectionless entries, which its query leaves out, likeSectionTypeConditionRule.entries.sectionIddirectly rather than throughEntryQuery::applySectionId(), which set the outer query'sstructureId/withStructurewhen one section was left. In an “or” condition group, that gave entries matched by other rules the wrong structure ID.kind()with “or” or “and” checks each kind as its own(stored kind OR one of its extensions)group, combined with the param's operator, sokind(['and', 'image'])and kinds that share an extension (.oggfor audio and video) match by extension.This affects every place an entry, asset, or user condition filters a query, such as custom element sources.
Evidence
6.x.After: they pass.
The review fixes, each failing before its commit: