You are here

function template_preprocess_charts_api_example in Charts 8.3

Implements template_preprocess_hook().

File

modules/charts_api_example/charts_api_example.module, line 47
Charts Api Example - Module.

Code

function template_preprocess_charts_api_example(&$variables) {

  // Charts override settings applied at this point.
  $chartOverridePluginManager = \Drupal::service('plugin.manager.charts_override');
  $plugin_definition = [];
  $chartOverrideOptions = [];
  try {
    $plugin_definition = $chartOverridePluginManager
      ->getDefinition($variables['library'] . '_overrides');
    if (!empty($plugin_definition)) {
      $chartOverridePlugin = $chartOverridePluginManager
        ->createInstance($variables['library'] . '_overrides');
      $chartOverrideOptions = $chartOverridePlugin
        ->chartOverrides($variables['options']);
    }
  } catch (PluginNotFoundException $e) {
    \Drupal::service('messenger')
      ->addMessage(t('Exception: @error', [
      '@error',
      $e
        ->getMessage(),
    ]));
  }
  $plugin_manager = \Drupal::service('plugin.manager.charts');
  $plugin = $plugin_manager
    ->createInstance($variables['library']);
  $plugin
    ->buildVariables($variables['options'], $variables['categories'], $variables['seriesData'], [], $variables, $variables['id'], $chartOverrideOptions);
}