Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
state_machine
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
state_machine
Merge requests
!18
Issue
#3045520
by khiminrm, jsacksick: Views filter getBundles is fragile
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3045520
by khiminrm, jsacksick: Views filter getBundles is fragile
issue/state_machine-3045520:3045520-views-filter-getbundles
into
8.x-1.x
Overview
0
Commits
1
Pipelines
3
Changes
1
Merged
Tom Ashe
requested to merge
issue/state_machine-3045520:3045520-views-filter-getbundles
into
8.x-1.x
1 year ago
Overview
0
Commits
1
Pipelines
3
Changes
1
Expand
Closes
#3045520
0
0
Merge request reports
Compare
8.x-1.x
version 1
61b11328
1 year ago
8.x-1.x (base)
and
latest version
latest version
7bb0ef9f
1 commit,
1 year ago
version 1
61b11328
1 commit,
1 year ago
1 file
+
27
−
5
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/Plugin/views/filter/State.php
+
27
−
5
Options
@@ -167,11 +167,33 @@ class State extends InOperator {
protected
function
getBundles
(
EntityTypeInterface
$entity_type
,
$field_name
)
{
$bundles
=
[];
$bundle_key
=
$entity_type
->
getKey
(
'bundle'
);
if
(
$bundle_key
&&
isset
(
$this
->
view
->
filter
[
$bundle_key
]))
{
$filter
=
$this
->
view
->
filter
[
$bundle_key
];
if
(
!
$filter
->
isExposed
()
&&
!
empty
(
$filter
->
value
)
&&
$filter
->
getEntityType
()
===
$entity_type
->
id
())
{
// 'all' is added by Views and isn't a bundle.
$bundles
=
array_diff
(
$filter
->
value
,
[
'all'
]);
if
(
$bundle_key
)
{
// Get any bundle filters for this entity type and bundle.
// It is unlikely, but there could be multiple.
/** @var \Drupal\views\Plugin\views\filter\FilterPluginBase[] $bundle_filters */
$bundle_filters
=
array_filter
(
$this
->
view
->
filter
??
[],
static
function
(
$filter
)
use
(
$entity_type
,
$bundle_key
)
{
return
$filter
->
getEntityType
()
===
$entity_type
->
id
()
&&
$filter
->
realField
===
$bundle_key
;
});
foreach
(
$bundle_filters
as
$bundle_filter
)
{
if
(
$bundle_filter
->
isExposed
())
{
// If any bundle filters are exposed,
// we cannot return a subset of bundles.
$bundles
=
[];
break
;
}
switch
(
$bundle_filter
->
operator
)
{
case
'in'
:
$bundles
=
array_merge
(
$bundles
,
$bundle_filter
->
value
);
break
;
case
'not in'
:
$bundles
=
array_diff
(
$bundles
,
$bundle_filter
->
value
);
break
;
}
}
// Remove the "all" option, if present.
if
(
array_key_exists
(
'all'
,
$bundles
))
{
unset
(
$bundles
[
'all'
]);
}
}
// Fallback to the list of bundles the field is attached to.
Loading