function visualization_plugin in Visualization API 8
Same name and namespace in other branches
- 7 visualization.module \visualization_plugin()
Returns the name of the library that should be used to render a chart.
Optionally one can pass a chart type to get the best library available for that type.
1 call to visualization_plugin()
- template_preprocess_visualization in ./
visualization.theme.inc - Preprocess function for visualization function.
File
- ./
visualization.module, line 31
Code
function visualization_plugin($type = FALSE) {
$config = Drupal::config('visualization.settings');
$preferred_plugin = $config
->get('library');
$plugin_manager = Drupal::service('plugin.manager.visualization.handler');
$plugins = $plugin_manager
->getDefinitions();
if (!empty($plugins[$preferred_plugin])) {
$id = $plugins[$preferred_plugin]['id'];
$instance = $plugin_manager
->createInstance($id);
if ($instance
->available() && (!empty($type) && in_array($type, $instance
->supportedTypes()))) {
return $instance;
}
}
// No prefered plugin found, let's return first found plugin.
$first_plugin = reset($plugins);
return $plugin_manager
->createInstance($first_plugin['id']);
}