File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
lib/Drupal/Core/Plugin/Context Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -17,12 +17,19 @@ class ContextHandler implements ContextHandlerInterface {
1717 * {@inheritdoc}
1818 */
1919 public function filterPluginDefinitionsByContexts (array $ contexts , array $ definitions ) {
20- return array_filter ($ definitions , function ($ plugin_definition ) use ($ contexts ) {
20+ $ checked_requirements = [];
21+ return array_filter ($ definitions , function ($ plugin_definition ) use ($ contexts , &$ checked_requirements ) {
2122 $ context_definitions = $ this ->getContextDefinitions ($ plugin_definition );
22-
2323 if ($ context_definitions ) {
24- // Check the set of contexts against the requirements.
25- return $ this ->checkRequirements ($ contexts , $ context_definitions );
24+ // Generate a unique key for the current context definitions. This will
25+ // allow calling checkRequirements() once for all plugins that have the
26+ // same context definitions.
27+ $ context_definitions_key = hash ('sha256 ' , serialize ($ context_definitions ));
28+ if (!isset ($ checked_requirements [$ context_definitions_key ])) {
29+ // Check the set of contexts against the requirements.
30+ $ checked_requirements [$ context_definitions_key ] = $ this ->checkRequirements ($ contexts , $ context_definitions );
31+ }
32+ return $ checked_requirements [$ context_definitions_key ];
2633 }
2734 // If this plugin doesn't need any context, it is available to use.
2835 return TRUE ;
You can’t perform that action at this time.
0 commit comments