Bug #103456
closedAbstractRestrictionContainer::removeByType() causes problems with xclassed restrictions.
100%
Description
The current implementation of AbstractRestrictionContainer::removeByType() removes values from the restrictions and enforcedRestrictions arrays by unsetting the restriction-type as specified by the parameter:
unset($this->restrictions[$restrictionType], $this->enforcedRestrictions[$restrictionType]);
This causes problems when a restriction is xclassed. The common approach to disable default restrictions is something like this:
$queryBuilder->getRestrictions()
->removeByType(HiddenRestriction::class)
->removeByType(StartTimeRestriction::class)
->removeByType(EndTimeRestriction::class);
and this would fail to remove an xclassed restriction with the current implementation.
An alternative approach might be to iterate over the array values and check if they are instances of the specified type:
public function removeByType(string $restrictionType): QueryRestrictionContainerInterface
{
foreach ($this->restrictions as $type => $instance) {
if ($instance instanceof $restrictionType) {
unset($this->restrictions[$type]);
}
}
foreach ($this->enforcedRestrictions as $type => $instance) {
if ($instance instanceof $restrictionType) {
unset($this->enforcedRestrictions[$type]);
}
}
return $this;
}
This approach would work both for the original and possible xclassed restrictions.
Thank you :)
Ole.
Updated by Gerrit Code Review 8 months ago
- Status changed from New to Under Review
Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/83562
Updated by Gerrit Code Review 8 months ago
Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/83568
Updated by Gerrit Code Review 8 months ago
Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/83562
Updated by Gerrit Code Review 8 months ago
Patch set 1 for branch 12.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/83539
Updated by Gerrit Code Review 8 months ago
Patch set 2 for branch 12.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/83539
Updated by Oliver Bartsch 8 months ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 1350e2b8b35159f44e3930c3ae0a59a1f35839a2.