public function filterPluginDefinitionsByContexts(array
$contexts, array
$definitions) { $checked_requirements =
[];
return array_filter($definitions,
function D
$plugin_definition) use ($contexts, &
$checked_requirements) { $context_definitions =
$this->
getContextDefinitions($plugin_definition);
if ($context_definitions) { // Generate a unique key for the current context definitions. This will
// allow calling checkRequirements() once for all plugins that have the
// same context definitions.
$context_definitions_key =
hash('sha256',
serialize($context_definitions));
if (!
isset($checked_requirements[$context_definitions_key])) { // Check the set of contexts against the requirements.
$checked_requirements[$context_definitions_key] =
$this->
checkRequirements($contexts,
$context_definitions);
} return $checked_requirements[$context_definitions_key];
} // If this plugin doesn't need any context, it is available to use.
return TRUE;
});
} /**
* Returns the context definitions associated with a plugin definition.
*
* @param array|\Drupal\Component\Plugin\Definition\ContextAwarePluginDefinitionInterface $plugin_definition
* The plugin definition.
*
* @return \Drupal\Component\Plugin\Context\ContextDefinitionInterface[]|null
* The context definitions, or NULL if the plugin definition does not
* support contexts.
*/