Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
F
facets
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
8
Merge Requests
8
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
facets
Commits
e1108f03
Commit
e1108f03
authored
Dec 05, 2017
by
borisson_
Committed by
borisson_
Dec 05, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2909262
by borisson_: Limit taxonomy weight processor to entity reference fields, add a test
parent
3323ecff
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
2 deletions
+65
-2
src/Plugin/facets/processor/TermWeightWidgetOrderProcessor.php
...lugin/facets/processor/TermWeightWidgetOrderProcessor.php
+28
-0
tests/src/Functional/HierarchicalFacetIntegrationTest.php
tests/src/Functional/HierarchicalFacetIntegrationTest.php
+29
-0
tests/src/Functional/ProcessorIntegrationTest.php
tests/src/Functional/ProcessorIntegrationTest.php
+8
-2
No files found.
src/Plugin/facets/processor/TermWeightWidgetOrderProcessor.php
View file @
e1108f03
...
...
@@ -4,6 +4,9 @@ namespace Drupal\facets\Plugin\facets\processor;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\Core\TypedData\ComplexDataDefinitionInterface
;
use
Drupal\Core\TypedData\DataReferenceDefinitionInterface
;
use
Drupal\facets\FacetInterface
;
use
Drupal\facets\Processor\SortProcessorPluginBase
;
use
Drupal\facets\Result\Result
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
...
...
@@ -86,4 +89,29 @@ class TermWeightWidgetOrderProcessor extends SortProcessorPluginBase implements
return
(
$term_a
->
getWeight
()
<
$term_b
->
getWeight
())
?
-
1
:
1
;
}
/**
* {@inheritdoc}
*/
public
function
supportsFacet
(
FacetInterface
$facet
)
{
$data_definition
=
$facet
->
getDataDefinition
();
if
(
$data_definition
->
getDataType
()
===
'entity_reference'
)
{
return
TRUE
;
}
if
(
!
(
$data_definition
instanceof
ComplexDataDefinitionInterface
))
{
return
FALSE
;
}
$data_definition
=
$facet
->
getDataDefinition
();
$property_definitions
=
$data_definition
->
getPropertyDefinitions
();
foreach
(
$property_definitions
as
$definition
)
{
if
(
$definition
instanceof
DataReferenceDefinitionInterface
&&
$definition
->
getDataType
()
===
'entity_reference'
&&
$definition
->
getConstraint
(
'EntityType'
)
===
'taxonomy_term'
)
{
return
TRUE
;
}
}
return
FALSE
;
}
}
tests/src/Functional/HierarchicalFacetIntegrationTest.php
View file @
e1108f03
...
...
@@ -203,6 +203,35 @@ class HierarchicalFacetIntegrationTest extends FacetsTestBase {
$this
->
assertStringPosition
(
'Child 2'
,
'Child 1'
);
}
/**
* Tests sorting by weight of a taxonomy term.
*/
public
function
testWeightSort
()
{
$edit
=
[
'facet_settings[translate_entity][status]'
=>
'1'
,
'facet_sorting[term_weight_widget_order][status]'
=>
'1'
,
];
$this
->
drupalPostForm
(
$this
->
facetEditPage
,
$edit
,
'Save'
);
$this
->
parents
[
'Parent 1'
]
->
setWeight
(
15
);
$this
->
parents
[
'Parent 1'
]
->
save
();
$this
->
parents
[
'Parent 2'
]
->
setWeight
(
25
);
$this
->
parents
[
'Parent 2'
]
->
save
();
$this
->
drupalGet
(
'search-api-test-fulltext'
);
$this
->
assertFacetLabel
(
'Parent 1'
);
$this
->
assertFacetLabel
(
'Parent 2'
);
$this
->
assertStringPosition
(
'Parent 1'
,
'Parent 2'
);
$this
->
parents
[
'Parent 2'
]
->
setWeight
(
5
);
$this
->
parents
[
'Parent 2'
]
->
save
();
$this
->
drupalGet
(
'search-api-test-fulltext'
);
$this
->
assertFacetLabel
(
'Parent 1'
);
$this
->
assertFacetLabel
(
'Parent 2'
);
$this
->
assertStringPosition
(
'Parent 2'
,
'Parent 1'
);
}
/**
* Verify the "Enable parent when child gets disabled" option is working.
*/
...
...
tests/src/Functional/ProcessorIntegrationTest.php
View file @
e1108f03
...
...
@@ -146,7 +146,7 @@ class ProcessorIntegrationTest extends FacetsTestBase {
$index
=
$this
->
getIndex
();
// Index
the taxonomy and entity reference fields
.
// Index
a boolean field
.
$boolean_field
=
new
Field
(
$index
,
$field_name
);
$boolean_field
->
setType
(
'integer'
);
$boolean_field
->
setPropertyPath
(
$field_name
);
...
...
@@ -806,6 +806,7 @@ class ProcessorIntegrationTest extends FacetsTestBase {
$this
->
assertSession
()
->
pageTextNotContains
(
'Boolean item label'
);
$this
->
assertSession
()
->
pageTextNotContains
(
'Transform UID to user name'
);
$this
->
assertSession
()
->
pageTextNotContains
(
'Transform entity ID to label'
);
$this
->
assertSession
()
->
pageTextNotContains
(
'Sort by taxonomy term weight'
);
}
/**
...
...
@@ -829,7 +830,12 @@ class ProcessorIntegrationTest extends FacetsTestBase {
}
// These processors are hidden by default, see also
// ::testHiddenProcessors.
if
(
in_array
(
$processor
->
getPluginId
(),
[
'boolean_item'
,
'translate_entity'
,
'uid_to_username_callback'
]))
{
$hiddenProcessors
=
[
'boolean_item'
,
'translate_entity'
,
'uid_to_username_callback'
,
];
if
(
in_array
(
$processor
->
getPluginId
(),
$hiddenProcessors
))
{
continue
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment