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
7
Merge Requests
7
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
29b27d5d
Commit
29b27d5d
authored
May 24, 2017
by
andrewbelcher
Committed by
borisson_
May 24, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2880411
by andrewbelcher: Facets added via config don't clear the block cache
parent
34d43b40
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
16 deletions
+76
-16
src/Entity/Facet.php
src/Entity/Facet.php
+37
-0
src/Form/FacetSettingsForm.php
src/Form/FacetSettingsForm.php
+1
-16
tests/src/Kernel/Entity/FacetTest.php
tests/src/Kernel/Entity/FacetTest.php
+38
-0
No files found.
src/Entity/Facet.php
View file @
29b27d5d
...
...
@@ -3,6 +3,7 @@
namespace
Drupal\facets\Entity
;
use
Drupal\Core\Config\Entity\ConfigEntityBase
;
use
Drupal\Core\Entity\EntityStorageInterface
;
use
Drupal\facets\Exception\Exception
;
use
Drupal\facets\Exception\InvalidProcessorException
;
use
Drupal\facets\FacetInterface
;
...
...
@@ -901,4 +902,40 @@ class Facet extends ConfigEntityBase implements FacetInterface {
return
$this
;
}
/**
* {@inheritdoc}
*/
public
function
postSave
(
EntityStorageInterface
$storage
,
$update
=
TRUE
)
{
parent
::
postSave
(
$storage
,
$update
);
if
(
!
$update
)
{
self
::
clearBlockCache
();
}
}
/**
* {@inheritdoc}
*/
public
static
function
postDelete
(
EntityStorageInterface
$storage
,
array
$entities
)
{
parent
::
postDelete
(
$storage
,
$entities
);
self
::
clearBlockCache
();
}
/**
* Clear the block cache.
*
* This includes resetting the shared plugin block manager as this can result
* in the block definition cache being rebuilt in the same request with stale
* static caches in the deriver.
*/
protected
static
function
clearBlockCache
()
{
$container
=
\
Drupal
::
getContainer
();
// If the block manager has already been loaded, we may have stale static
// caches in the facet deriver, so lets clear it out.
$container
->
set
(
'plugin.manager.block'
,
NULL
);
// Now rebuild the cache to force a fresh set of data.
$container
->
get
(
'plugin.manager.block'
)
->
clearCachedDefinitions
();
}
}
src/Form/FacetSettingsForm.php
View file @
29b27d5d
...
...
@@ -2,7 +2,6 @@
namespace
Drupal\facets\Form
;
use
Drupal\Core\Block\BlockManagerInterface
;
use
Drupal\Core\Entity\EntityForm
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Extension\ModuleHandlerInterface
;
...
...
@@ -48,13 +47,6 @@ class FacetSettingsForm extends EntityForm {
*/
protected
$moduleHandler
;
/**
* The block manager.
*
* @var \Drupal\Core\Block\BlockManagerInterface
*/
protected
$blockManager
;
/**
* The url generator.
*
...
...
@@ -73,17 +65,14 @@ class FacetSettingsForm extends EntityForm {
* The plugin manager for processors.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Block\BlockManagerInterface $block_manager
* The block manager.
* @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
* The url generator.
*/
public
function
__construct
(
EntityTypeManagerInterface
$entity_type_manager
,
FacetSourcePluginManager
$facet_source_plugin_manager
,
ProcessorPluginManager
$processor_plugin_manager
,
ModuleHandlerInterface
$module_handler
,
BlockManagerInterface
$block_manager
,
UrlGeneratorInterface
$url_generator
)
{
public
function
__construct
(
EntityTypeManagerInterface
$entity_type_manager
,
FacetSourcePluginManager
$facet_source_plugin_manager
,
ProcessorPluginManager
$processor_plugin_manager
,
ModuleHandlerInterface
$module_handler
,
UrlGeneratorInterface
$url_generator
)
{
$this
->
facetStorage
=
$entity_type_manager
->
getStorage
(
'facets_facet'
);
$this
->
facetSourcePluginManager
=
$facet_source_plugin_manager
;
$this
->
processorPluginManager
=
$processor_plugin_manager
;
$this
->
moduleHandler
=
$module_handler
;
$this
->
blockManager
=
$block_manager
;
$this
->
urlGenerator
=
$url_generator
;
}
...
...
@@ -96,7 +85,6 @@ class FacetSettingsForm extends EntityForm {
$container
->
get
(
'plugin.manager.facets.facet_source'
),
$container
->
get
(
'plugin.manager.facets.processor'
),
$container
->
get
(
'module_handler'
),
$container
->
get
(
'plugin.manager.block'
),
$container
->
get
(
'url_generator'
)
);
}
...
...
@@ -323,9 +311,6 @@ class FacetSettingsForm extends EntityForm {
drupal_set_message
(
$this
->
t
(
'Facet %name has been updated.'
,
[
'%name'
=>
$facet
->
getName
()]));
}
// Clear Drupal cache for blocks to reflect recent changes.
$this
->
blockManager
->
clearCachedDefinitions
();
list
(
$type
,)
=
explode
(
':'
,
$facet_source_id
);
if
(
$type
!==
'search_api'
)
{
return
$facet
;
...
...
tests/src/Kernel/Entity/FacetTest.php
View file @
29b27d5d
...
...
@@ -2,6 +2,7 @@
namespace
Drupal\Tests\facets\Kernel\Entity
;
use
Drupal\Core\Plugin\PluginBase
;
use
Drupal\facets\Entity\Facet
;
use
Drupal\facets\Exception\InvalidProcessorException
;
use
Drupal\facets\Hierarchy\HierarchyPluginManager
;
...
...
@@ -372,4 +373,41 @@ class FacetTest extends KernelTestBase {
$this
->
assertEquals
([
'type'
=>
'taxonomy'
,
'config'
=>
[]],
$entity
->
getHierarchy
());
}
/**
* Tests that the block caches are cleared from API calls.
*
* @covers ::postSave
* @covers ::postDelete
* @covers ::clearBlockCache
*/
public
function
testBlockCache
()
{
// Block processing requires the system module.
$this
->
enableModules
([
'system'
]);
// Create our facet.
$entity
=
Facet
::
create
([
'id'
=>
'test_facet'
,
'name'
=>
'Test facet'
,
]);
$entity
->
setWidget
(
'links'
);
$entity
->
setEmptyBehavior
([
'behavior'
=>
'none'
]);
$block_id
=
'facet_block'
.
PluginBase
::
DERIVATIVE_SEPARATOR
.
$entity
->
id
();
// Check we don't have a block yet.
$this
->
assertFalse
(
$this
->
container
->
get
(
'plugin.manager.block'
)
->
hasDefinition
(
$block_id
));
// Save our facet.
$entity
->
save
();
// Check our block exists.
$this
->
assertTrue
(
$this
->
container
->
get
(
'plugin.manager.block'
)
->
hasDefinition
(
$block_id
));
// Delete our facet.
$entity
->
delete
();
// Check our block exists.
$this
->
assertFalse
(
$this
->
container
->
get
(
'plugin.manager.block'
)
->
hasDefinition
(
$block_id
));
}
}
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