diff --git a/includes/charts.pages.inc b/includes/charts.pages.inc index 160f35cba5eaa1ce7bd860b879ccfb0d8014ef85..081890a9407147bdded58dd9b3aa02be91b55638 100644 --- a/includes/charts.pages.inc +++ b/includes/charts.pages.inc @@ -286,8 +286,6 @@ function charts_settings_form($form, $defaults = [], $field_options = [], $paren if ($field_options) { $first_field = key($field_options); - /* $form['#theme'] = 'charts_settings_fields'; */ - $form['fields'] = [ '#title' => t('Charts fields'), '#type' => 'fieldset', diff --git a/modules/charts_api_example/charts_api_example.module b/modules/charts_api_example/charts_api_example.module index 1c5d09949e09236e93d8ba36cbd23da8cfeca5d0..1da3ee0d9819c57545d82bd6ca0edcff5bc6b87e 100644 --- a/modules/charts_api_example/charts_api_example.module +++ b/modules/charts_api_example/charts_api_example.module @@ -35,6 +35,7 @@ function charts_api_example_theme() { 'categories' => [], 'seriesData' => [], 'options' => [], + 'id' => '', ], ], ]; @@ -44,8 +45,7 @@ function charts_api_example_theme() { * Implements template_preprocess_charts_api_example(). */ function template_preprocess_charts_api_example(&$variables) { - $moduleSelector = new ModuleSelector($variables['library'], $variables['categories'], $variables['seriesData'], $variables['options'], [], 'xyz'); - if ($moduleSelector->moduleExists()) { - $moduleSelector->buildVariables($variables); - } + $plugin_manager = \Drupal::service('plugin.manager.charts'); + $plugin = $plugin_manager->createInstance($variables['library']); + $plugin->buildVariables($variables['options'], $variables['categories'], $variables['seriesData'], [], $variables, 'xyz'); } diff --git a/modules/charts_api_example/src/Controller/ChartsApiExample.php b/modules/charts_api_example/src/Controller/ChartsApiExample.php index e0d54dcfdf61fce15d460d6b6c4b9f93cb41ffb3..fe7e872d72d9a09fd75485c4c0885f08c5eb6f78 100644 --- a/modules/charts_api_example/src/Controller/ChartsApiExample.php +++ b/modules/charts_api_example/src/Controller/ChartsApiExample.php @@ -37,6 +37,8 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter drupal_set_message($this->t('You need to first configure Charts default settings')); return []; } + + // Customize options here. $options = [ 'type' => $this->chartSettings['type'], 'title' => $this->t('Chart title'), diff --git a/modules/charts_api_example/templates/charts_api_example.html.twig b/modules/charts_api_example/templates/charts_api_example.html.twig index 561c1e10949264e284722b59bcd0be867430b9a6..734319d20cbcd3ff4f8ae2edcf09f8284e8f91e6 100644 --- a/modules/charts_api_example/templates/charts_api_example.html.twig +++ b/modules/charts_api_example/templates/charts_api_example.html.twig @@ -1,6 +1,3 @@ -{% set library, height, width = 'charts_' ~ chart_type ~ '/' ~ chart_type, options.height, options.width %} +{% set library, height, width = 'charts_' ~ library ~ '/' ~ library, options.height, options.width %} {{ attach_library("#{ library }") }} -<p>Edit charts_api_example.html.twig to delete this message. To change the - library used by this file, change the <a href="{{ url('charts.settings',{}) }}">default settings</a>. -</p> -<div {{ attributes }} {{ content_attributes }} style="width:{{ width }};height:{{ height }};"></div> +<div {{ attributes }} {{ content_attributes }} style="{% if width is not empty %}width:{{ width }}px;{% endif %}{% if height is not empty %}height:{{ height }}px;{% endif %}"></div> diff --git a/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php b/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php index fdd9f33be5e20d09b67de12ae3cc66c1fd656c2d..d3876d249bc11d02ab1006c0619b3cee6d2cab84 100644 --- a/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php +++ b/modules/charts_blocks/src/Plugin/Block/ChartsBlock.php @@ -26,7 +26,6 @@ class ChartsBlock extends BlockBase { // Get the default chart values. $defaults = \Drupal::state()->get('charts_default_settings', []); - $defaults += charts_default_settings(); foreach ($defaults as $default_key => $default_value) { $options[$default_key]['default'] = $default_value; @@ -247,12 +246,9 @@ class ChartsBlock extends BlockBase { ]; } - /** - * @todo: refactor the way this id is produced to ensure uniqueness. - */ - $chartId = strtolower($this->label()); - $chartId = preg_replace('/[^a-z0-9_]+/', '_', $chartId); - $chartId = preg_replace('/_+/', '_', $chartId); + // Creates a UUID for the chart ID. + $uuid_service = \Drupal::service('uuid'); + $chartId = 'chart-' . $uuid_service->generate(); $build = [ '#theme' => 'charts_blocks',