+ /**
+ * 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.
+ */
+ protected function getContextDefinitions($plugin_definition) {
+ if ($plugin_definition instanceof ContextAwarePluginDefinitionInterface) {
+ return $plugin_definition->getContextDefinitions();
+ }
+ if (is_array($plugin_definition) && isset($plugin_definition['context'])) {
+ return $plugin_definition['context'];
+ }
+ return NULL;
+ }
+