diff --git a/modules/charts_api_example/src/Controller/ChartsApiExample.php b/modules/charts_api_example/src/Controller/ChartsApiExample.php index 513f4955323ceae18a86474c18b5e314d3badee8..b5ff641b9464ca28240be72be27dc2f52cefce32 100644 --- a/modules/charts_api_example/src/Controller/ChartsApiExample.php +++ b/modules/charts_api_example/src/Controller/ChartsApiExample.php @@ -2,33 +2,50 @@ namespace Drupal\charts_api_example\Controller; - use Drupal\charts\Services\ChartsSettingsService; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +/** + * Charts Api Example. + */ class ChartsApiExample extends ControllerBase implements ContainerInjectionInterface { + private $chartSettings; + /** + * Construct. + * + * @param \Drupal\charts\Services\ChartsSettingsService $chartSettings + * Service ChartsSettingsService. + */ public function __construct(ChartsSettingsService $chartSettings) { $this->chartSettings = $chartSettings->getChartsSettings(); } + /** + * Display. + * + * @return array + * Array to render. + */ public function display() { $library = $this->chartSettings['library']; - if (!isset($library)) { - drupal_set_message(t('You need to first configure Charts default - settings')); + if (empty($library)) { + drupal_set_message($this->t('You need to first configure Charts default settings')); + return []; } - $options = []; - $options['type'] = $this->chartSettings['type']; - $options['title'] = $this->t('Chart title'); - $options['yaxis_title'] = $this->t('Y-Axis'); - $options['yaxis_min'] = ''; - $options['yaxis_max'] = ''; - $options['xaxis_title'] = $this->t('X-Axis'); + $options = [ + 'type' => $this->chartSettings['type'], + 'title' => $this->t('Chart title'), + 'xaxis_title' => $this->t('X-Axis'), + 'yaxis_title' => $this->t('Y-Axis'), + 'yaxis_min' => '', + 'yaxis_max' => '', + ]; + // Sample data format. $categories = ["Category 1", "Category 2", "Category 3", "Category 4"]; $seriesData = [ @@ -37,16 +54,18 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter ["name" => "Series 3", "color" => "#910000", "type" => "area", "data" => [0, 0, 60, 90]] ]; - $element = [ - '#theme' => 'charts_api_example', - '#library' => $this->t($library), + return [ + '#theme' => 'charts_api_example', + '#library' => (string) $library, '#categories' => $categories, '#seriesData' => $seriesData, - '#options' => $options, + '#options' => $options, ]; - return $element; } + /** + * {@inheritdoc} + */ public static function create(ContainerInterface $container) { return new static( $container->get('charts.settings') diff --git a/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php b/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php index 928792f747032cce28c47750ab9548583f199fd5..df69fadb66e466553bbd543cfe0d24c5e7b08803 100644 --- a/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php +++ b/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php @@ -60,16 +60,38 @@ class HighchartsChartsRender implements ChartsRenderInterface { } } $chart->setType($typeOptions); - $chart->setWidth($options['width']); - $chart->setHeight($options['height']); + + // Set chart width. + if (isset($options['width'])) { + $chart->setWidth($options['width']); + } + + // Set chart height. + if (isset($options['height'])) { + $chart->setHeight($options['height']); + } + + // Set chart title. $chartTitle = new ChartTitle(); - $chartTitle->setText($options['title']); + if (isset($options['title'])) { + $chartTitle->setText($options['title']); + } + $chartXaxis = new Xaxis(); $chartLabels = new ChartLabel(); - $chartLabels->setRotation($options['xaxis_labels_rotation']); + + // Set x-axis label rotation. + if (isset($options['xaxis_labels_rotation'])) { + $chartLabels->setRotation($options['xaxis_labels_rotation']); + } + $chartXaxis->setCategories($categories); + + // Set x-axis title. $xAxisTitle = new XaxisTitle(); - $xAxisTitle->setText($options['xaxis_title']); + if (isset($options['xaxis_title'])) { + $xAxisTitle->setText($options['xaxis_title']); + } $chartXaxis->setTitle($xAxisTitle); $chartXaxis->setLabels($chartLabels); $yaxisLabels = new YaxisLabel(); @@ -87,7 +109,8 @@ class HighchartsChartsRender implements ChartsRenderInterface { $chartYaxis->setLabels($yaxisLabels); $chartYaxis->setTitle($yAxisTitle); array_push($yAxes, $chartYaxis); - // Chart libraries tend to supports only one secondary axis. + + // Chart libraries tend to support only one secondary axis. if (!$noAttachmentDisplays && $attachmentDisplayOptions[0]['inherit_yaxis'] == 0) { $chartYaxisSecondary = new Yaxis(); $yAxisTitleSecondary = new YaxisTitle(); diff --git a/src/Form/ChartsConfigForm.php b/src/Form/ChartsConfigForm.php index 0cb0f2c6442cd8906d20c16bf93fa214ea624d54..5d1a193d727a0e19367091b565720dd981b32c49 100644 --- a/src/Form/ChartsConfigForm.php +++ b/src/Form/ChartsConfigForm.php @@ -10,12 +10,25 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +/** + * Charts Config Form. + */ class ChartsConfigForm extends ConfigFormBase { protected $moduleHandler; + protected $config; + /** + * Construct. + * + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * Config factory. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * Module handler. + */ public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler) { parent::__construct($config_factory); $this->moduleHandler = $module_handler; + $this->config = $this->configFactory->getEditable('charts.settings'); } /** @@ -25,33 +38,38 @@ class ChartsConfigForm extends ConfigFormBase { return new static($container->get('config.factory'), $container->get('module_handler')); } + /** + * {@inheritdoc} + */ public function getFormId() { return 'charts_form'; } + /** + * {@inheritdoc} + */ protected function getEditableConfigNames() { return ['charts.settings']; } + /** + * {@inheritdoc} + */ public function buildForm(array $form, FormStateInterface $form_state) { - $config = $this->configFactory->getEditable('charts.settings'); $parents = ['charts_default_settings']; - $default_config = $config->get('charts_default_settings'); - if ($default_config == NULL) { - $defaults = [] + $this->charts_default_settings(); - } else { - $defaults = $default_config + $this->charts_default_settings(); - } + $default_config = (array) $this->config->get('charts_default_settings'); + $defaults = $default_config + $this->chartsDefaultSettings(); $field_options = []; $form['help'] = [ - '#type' => 'markup', - '#markup' => '<p>' . $this->t('The settings on this page are used to set + '#type' => 'markup', + '#prefix' => '<p>', + '#suffix' => '</p>', + '#markup' => $this->t('The settings on this page are used to set <strong>default</strong> settings. They do not affect existing charts. To make a new chart, <a href="@create">create a new view</a> and select - the display format of "Chart".', ['@create' => Url::fromRoute('views_ui.add')->toString()]) - . '</p>', + the display format of "Chart".', ['@create' => Url::fromRoute('views_ui.add')->toString()]), '#weight' => -100, ]; // Reuse the global settings form for defaults, but remove JS classes. @@ -66,43 +84,51 @@ class ChartsConfigForm extends ConfigFormBase { $form['yaxis']['#group'] = 'defaults'; $form['defaults'] = ['#type' => 'vertical_tabs']; // Add submit buttons and normal saving behavior. - $form['actions']['#type'] = 'actions'; - $form['actions']['submit'] = [ - '#type' => 'submit', - '#value' => $this->t('Save defaults'), + $form['actions'] = [ + '#type' => 'actions', + 'submit' => [ + '#type' => 'submit', + '#value' => $this->t('Save defaults'), + '#button_type' => 'primary', + ], ]; return $form; } - public function charts_default_settings() { - $defaults = []; - $defaults['type'] = 'pie'; - $defaults['library'] = NULL; - $defaults['label_field'] = NULL; - $defaults['data_fields'] = NULL; - $defaults['field_colors'] = NULL; - $defaults['title'] = ''; - $defaults['title_position'] = 'out'; - $defaults['legend'] = TRUE; - $defaults['legend_position'] = 'right'; - $defaults['colors'] = $this->charts_default_colors(); - $defaults['background'] = ''; - $defaults['tooltips'] = TRUE; - $defaults['tooltips_use_html'] = FALSE; - $defaults['width'] = NULL; - $defaults['height'] = NULL; - - $defaults['xaxis_title'] = ''; - $defaults['xaxis_labels_rotation'] = 0; - - $defaults['yaxis_title'] = ''; - $defaults['yaxis_min'] = ''; - $defaults['yaxis_max'] = ''; - $defaults['yaxis_prefix'] = ''; - $defaults['yaxis_suffix'] = ''; - $defaults['yaxis_decimal_count'] = ''; - $defaults['yaxis_labels_rotation'] = 0; + /** + * Get Charts default settings. + * + * @return array + * Charts defaults settings. + */ + public function chartsDefaultSettings() { + $defaults = [ + 'type' => 'pie', + 'library' => NULL, + 'label_field' => NULL, + 'data_fields' => NULL, + 'field_colors' => NULL, + 'title' => '', + 'title_position' => 'out', + 'legend' => TRUE, + 'legend_position' => 'right', + 'colors' => $this->chartsDefaultColors(), + 'background' => '', + 'tooltips' => TRUE, + 'tooltips_use_html' => FALSE, + 'width' => NULL, + 'height' => NULL, + 'xaxis_title' => '', + 'xaxis_labels_rotation' => 0, + 'yaxis_title' => '', + 'yaxis_min' => '', + 'yaxis_max' => '', + 'yaxis_prefix' => '', + 'yaxis_suffix' => '', + 'yaxis_decimal_count' => '', + 'yaxis_labels_rotation' => 0, + ]; $this->moduleHandler->alter('charts_default_settings', $defaults); @@ -111,8 +137,11 @@ class ChartsConfigForm extends ConfigFormBase { /** * Default colors used in all libraries. + * + * @return array + * Default Colors. */ - public function charts_default_colors() { + public function chartsDefaultColors() { return [ '#2f7ed8', '#0d233a', @@ -127,14 +156,27 @@ class ChartsConfigForm extends ConfigFormBase { ]; } - public function chartsSettingsForm($form, $defaults = [], $field_options = [], $parents = []) { + /** + * Get charts settings form. + * + * @param array $form + * Form. + * @param array $defaults + * Defaults. + * @param array $field_options + * Field options. + * @param array $parents + * parents. + * + * @return array + * Form. + */ + public function chartsSettingsForm(array $form = [], array $defaults = [], array $field_options = [], array $parents = []) { // Ensure all defaults are set. - $options = array_merge($this->charts_default_settings(), $defaults); - - $form['#attached']['library'][] = ['charts', 'charts.admin']; + $options = array_merge($this->chartsDefaultSettings(), $defaults); // Get a list of available chart libraries. - $charts_info = $this->charts_info(); + $charts_info = $this->chartsInfo(); $library_options = []; foreach ($charts_info as $library_name => $library_info) { if ($this->moduleHandler->moduleExists($charts_info[$library_name]['module'])) { @@ -145,15 +187,15 @@ class ChartsConfigForm extends ConfigFormBase { drupal_set_message($this->t('There are no enabled charting libraries. Please enable a Charts sub-module.')); } $form['library'] = [ - '#title' => $this->t('Charting library'), - '#type' => 'select', - '#options' => $library_options, + '#title' => $this->t('Charting library'), + '#type' => 'select', + '#options' => $library_options, '#default_value' => $options['library'], - '#required' => TRUE, - '#access' => count($library_options) > 0, - '#attributes' => ['class' => ['chart-library-select']], - '#weight' => -15, - '#parents' => array_merge($parents, ['library']), + '#required' => TRUE, + '#access' => count($library_options) > 0, + '#attributes' => ['class' => ['chart-library-select']], + '#weight' => -15, + '#parents' => array_merge($parents, ['library']), ]; // This is a work around will need to revisit this. @@ -164,13 +206,13 @@ class ChartsConfigForm extends ConfigFormBase { } $form['type'] = [ - '#title' => $this->t('Chart type'), - '#type' => 'radios', + '#title' => $this->t('Chart type'), + '#type' => 'radios', '#default_value' => $options['type'], - '#options' => $type_options, - '#required' => TRUE, - '#weight' => -20, - '#attributes' => [ + '#options' => $type_options, + '#required' => TRUE, + '#weight' => -20, + '#attributes' => [ 'class' => [ 'chart-type-radios', 'container-inline', @@ -181,7 +223,7 @@ class ChartsConfigForm extends ConfigFormBase { // Set data attributes to identify special properties of different types. foreach ($chart_types as $chart_type => $chart_type_info) { - if ($chart_type_info['axis_inverted']) { + if (isset($chart_type_info['axis_inverted']) && $chart_type_info['axis_inverted']) { $form['type'][$chart_type]['#attributes']['data-axis-inverted'] = TRUE; } if ($chart_type_info['axis'] === ChartsInterface::CHARTS_SINGLE_AXIS) { @@ -193,31 +235,31 @@ class ChartsConfigForm extends ConfigFormBase { $first_field = key($field_options); // $form['fields']['#theme'] = 'charts_settings_fields'; $form['fields']['label_field'] = [ - '#type' => 'radios', - '#title' => $this->t('Label field'), - '#options' => $field_options + ['' => $this->t('No label field')], + '#type' => 'radios', + '#title' => $this->t('Label field'), + '#options' => $field_options + ['' => $this->t('No label field')], '#default_value' => isset($options['label_field']) ? $options['label_field'] : $first_field, - '#weight' => -10, - '#parents' => array_merge($parents, ['label_field']), + '#weight' => -10, + '#parents' => array_merge($parents, ['label_field']), ]; $form['fields']['data_fields'] = [ - '#type' => 'checkboxes', - '#title' => $this->t('Data fields'), - '#options' => $field_options, + '#type' => 'checkboxes', + '#title' => $this->t('Data fields'), + '#options' => $field_options, '#default_value' => isset($options['data_fields']) ? $options['data_fields'] : array_diff(array_keys($field_options), [$first_field]), - '#weight' => -9, - '#parents' => array_merge($parents, ['data_fields']), + '#weight' => -9, + '#parents' => array_merge($parents, ['data_fields']), ]; $color_count = 0; foreach ($field_options as $field_name => $field_label) { $form['fields']['field_colors'][$field_name] = [ - '#type' => 'textfield', - '#attributes' => ['TYPE' => 'color'], - '#size' => 10, - '#maxlength' => 7, + '#type' => 'textfield', + '#attributes' => ['TYPE' => 'color'], + '#size' => 10, + '#maxlength' => 7, '#theme_wrappers' => [], - '#default_value' => !empty($options['field_colors'][$field_name]) ? $options['field_colors'][$field_name] : $options['colors'][$color_count], - '#parents' => array_merge($parents, [ + '#default_value' => !empty($options['field_colors'][$field_name]) ? $options['field_colors'][$field_name] : $options['colors'][$color_count], + '#parents' => array_merge($parents, [ 'field_colors', $field_name, ]), @@ -227,231 +269,250 @@ class ChartsConfigForm extends ConfigFormBase { } $form['display'] = [ - '#title' => $this->t('Display'), - '#type' => 'details', + '#title' => $this->t('Display'), + '#type' => 'details', '#collapsible' => TRUE, - '#collapsed' => TRUE, + '#collapsed' => TRUE, ]; + $form['display']['title'] = [ - '#title' => $this->t('Chart title'), - '#type' => 'textfield', + '#title' => $this->t('Chart title'), + '#type' => 'textfield', '#default_value' => $options['title'], - '#parents' => array_merge($parents, ['title']), + '#parents' => array_merge($parents, ['title']), ]; + $form['display']['title_position'] = [ - '#title' => $this->t('Title position'), - '#type' => 'select', - '#options' => [ - '' => $this->t('None'), + '#title' => $this->t('Title position'), + '#type' => 'select', + '#options' => [ + '' => $this->t('None'), 'out' => $this->t('Outside'), - 'in' => $this->t('Inside'), + 'in' => $this->t('Inside'), ], '#default_value' => $options['title_position'], - '#parents' => array_merge($parents, ['title_position']), + '#parents' => array_merge($parents, ['title_position']), ]; $form['display']['legend_position'] = [ - '#title' => $this->t('Legend position'), - '#type' => 'select', - '#options' => [ - '' => $this->t('None'), - 'top' => $this->t('Top'), - 'right' => $this->t('Right'), + '#title' => $this->t('Legend position'), + '#type' => 'select', + '#options' => [ + '' => $this->t('None'), + 'top' => $this->t('Top'), + 'right' => $this->t('Right'), 'bottom' => $this->t('Bottom'), - 'left' => $this->t('Left'), + 'left' => $this->t('Left'), ], '#default_value' => $options['legend_position'], - '#parents' => array_merge($parents, ['legend_position']), + '#parents' => array_merge($parents, ['legend_position']), ]; $form['display']['colors'] = [ - '#title' => $this->t('Chart colors'), + '#title' => $this->t('Chart colors'), '#theme_wrappers' => ['form_element'], - '#prefix' => '<div class="chart-colors">', - '#suffix' => '</div>', + '#prefix' => '<div class="chart-colors">', + '#suffix' => '</div>', ]; + for ($color_count = 0; $color_count < 10; $color_count++) { $form['display']['colors'][$color_count] = [ - '#type' => 'textfield', - '#attributes' => ['TYPE' => 'color'], - '#size' => 10, - '#maxlength' => 7, + '#type' => 'textfield', + '#attributes' => ['TYPE' => 'color'], + '#size' => 10, + '#maxlength' => 7, '#theme_wrappers' => [], - '#suffix' => ' ', - '#default_value' => $options['colors'][$color_count], - '#parents' => array_merge($parents, ['colors', $color_count]), + '#suffix' => ' ', + '#default_value' => $options['colors'][$color_count], + '#parents' => array_merge($parents, ['colors', $color_count]), ]; } + $form['display']['background'] = [ - '#title' => $this->t('Background color'), - '#type' => 'textfield', - '#size' => 10, - '#maxlength' => 7, - '#attributes' => ['placeholder' => $this->t('transparent')], - '#description' => $this->t('Leave blank for a transparent background.'), + '#title' => $this->t('Background color'), + '#type' => 'textfield', + '#size' => 10, + '#maxlength' => 7, + '#attributes' => ['placeholder' => $this->t('transparent')], + '#description' => $this->t('Leave blank for a transparent background.'), '#default_value' => $options['background'], - '#parents' => array_merge($parents, ['background']), + '#parents' => array_merge($parents, ['background']), ]; $form['display']['dimensions'] = [ - '#title' => $this->t('Dimensions'), + '#title' => $this->t('Dimensions'), '#theme_wrappers' => ['form_element'], - '#description' => $this->t('If dimensions are left empty, the chart will fill its containing element.'), + '#description' => $this->t('If dimensions are left empty, the chart will fill its containing element.'), ]; + $form['display']['dimensions']['width'] = [ - '#type' => 'textfield', - '#attributes' => [ - 'TYPE' => 'number', - 'step' => 1, - 'min' => 0, - 'max' => 9999, + '#type' => 'textfield', + '#attributes' => [ + 'TYPE' => 'number', + 'step' => 1, + 'min' => 0, + 'max' => 9999, 'placeholder' => $this->t('auto'), ], - '#default_value' => $options['width'], - '#size' => 8, - '#suffix' => ' x ', + '#default_value' => $options['width'], + '#size' => 8, + '#suffix' => ' x ', '#theme_wrappers' => [], - '#parents' => array_merge($parents, ['width']), + '#parents' => array_merge($parents, ['width']), ]; + $form['display']['dimensions']['height'] = [ - '#type' => 'textfield', - '#attributes' => [ - 'TYPE' => 'number', - 'step' => 1, - 'min' => 0, - 'max' => 9999, + '#type' => 'textfield', + '#attributes' => [ + 'TYPE' => 'number', + 'step' => 1, + 'min' => 0, + 'max' => 9999, 'placeholder' => $this->t('auto'), ], - '#default_value' => $options['height'], - '#size' => 8, - '#suffix' => ' px', + '#default_value' => $options['height'], + '#size' => 8, + '#suffix' => ' px', '#theme_wrappers' => [], - '#parents' => array_merge($parents, ['height']), + '#parents' => array_merge($parents, ['height']), ]; $form['xaxis'] = [ - '#title' => $this->t('Horizontal axis'), - '#type' => 'details', + '#title' => $this->t('Horizontal axis'), + '#type' => 'details', '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#attributes' => ['class' => ['chart-xaxis']], + '#collapsed' => TRUE, + '#attributes' => ['class' => ['chart-xaxis']], ]; + $form['xaxis']['title'] = [ - '#title' => $this->t('Custom title'), - '#type' => 'textfield', + '#title' => $this->t('Custom title'), + '#type' => 'textfield', '#default_value' => $options['xaxis_title'], - '#parents' => array_merge($parents, ['xaxis_title']), + '#parents' => array_merge($parents, ['xaxis_title']), ]; + $form['xaxis']['labels_rotation'] = [ - '#title' => $this->t('Labels rotation'), - '#type' => 'select', - '#options' => [ - 0 => $this->t('0°'), + '#title' => $this->t('Labels rotation'), + '#type' => 'select', + '#options' => [ + 0 => $this->t('0°'), 30 => $this->t('30°'), 45 => $this->t('45°'), 60 => $this->t('60°'), 90 => $this->t('90°'), ], // This is only shown on non-inverted charts. - '#attributes' => ['class' => ['axis-inverted-hide']], + '#attributes' => ['class' => ['axis-inverted-hide']], '#default_value' => $options['xaxis_labels_rotation'], - '#parents' => array_merge($parents, ['xaxis_labels_rotation']), + '#parents' => array_merge($parents, ['xaxis_labels_rotation']), ]; $form['yaxis'] = [ - '#title' => $this->t('Vertical axis'), - '#type' => 'details', + '#title' => $this->t('Vertical axis'), + '#type' => 'details', '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#attributes' => ['class' => ['chart-yaxis']], + '#collapsed' => TRUE, + '#attributes' => ['class' => ['chart-yaxis']], ]; + $form['yaxis']['title'] = [ - '#title' => $this->t('Custom title'), - '#type' => 'textfield', + '#title' => $this->t('Custom title'), + '#type' => 'textfield', '#default_value' => $options['yaxis_title'], - '#parents' => array_merge($parents, ['yaxis_title']), + '#parents' => array_merge($parents, ['yaxis_title']), ]; + $form['yaxis']['minmax'] = [ - '#title' => $this->t('Value range'), + '#title' => $this->t('Value range'), '#theme_wrappers' => ['form_element'], ]; + $form['yaxis']['minmax']['min'] = [ - '#type' => 'textfield', - '#attributes' => [ - 'TYPE' => 'number', - 'max' => 999999, + '#type' => 'textfield', + '#attributes' => [ + 'TYPE' => 'number', + 'max' => 999999, 'placeholder' => $this->t('Minimum'), ], - '#default_value' => $options['yaxis_min'], - '#size' => 12, - '#parents' => array_merge($parents, ['yaxis_min']), - '#suffix' => ' ', + '#default_value' => $options['yaxis_min'], + '#size' => 12, + '#parents' => array_merge($parents, ['yaxis_min']), + '#suffix' => ' ', '#theme_wrappers' => [], ]; + $form['yaxis']['minmax']['max'] = [ - '#type' => 'textfield', - '#attributes' => [ - 'TYPE' => 'number', - 'max' => 999999, + '#type' => 'textfield', + '#attributes' => [ + 'TYPE' => 'number', + 'max' => 999999, 'placeholder' => $this->t('Maximum'), ], - '#default_value' => $options['yaxis_max'], - '#size' => 12, - '#parents' => array_merge($parents, ['yaxis_max']), + '#default_value' => $options['yaxis_max'], + '#size' => 12, + '#parents' => array_merge($parents, ['yaxis_max']), '#theme_wrappers' => [], ]; + $form['yaxis']['prefix'] = [ - '#title' => $this->t('Value prefix'), - '#type' => 'textfield', + '#title' => $this->t('Value prefix'), + '#type' => 'textfield', '#default_value' => $options['yaxis_prefix'], - '#size' => 12, - '#parents' => array_merge($parents, ['yaxis_prefix']), + '#size' => 12, + '#parents' => array_merge($parents, ['yaxis_prefix']), ]; + $form['yaxis']['suffix'] = [ - '#title' => $this->t('Value suffix'), - '#type' => 'textfield', + '#title' => $this->t('Value suffix'), + '#type' => 'textfield', '#default_value' => $options['yaxis_suffix'], - '#size' => 12, - '#parents' => array_merge($parents, ['yaxis_suffix']), + '#size' => 12, + '#parents' => array_merge($parents, ['yaxis_suffix']), ]; + $form['yaxis']['decimal_count'] = [ - '#title' => $this->t('Decimal count'), - '#type' => 'textfield', - '#attributes' => [ - 'TYPE' => 'number', - 'step' => 1, - 'min' => 0, - 'max' => 20, + '#title' => $this->t('Decimal count'), + '#type' => 'textfield', + '#attributes' => [ + 'TYPE' => 'number', + 'step' => 1, + 'min' => 0, + 'max' => 20, 'placeholder' => $this->t('auto'), ], '#default_value' => $options['yaxis_decimal_count'], - '#size' => 5, - '#description' => $this->t('Enforce a certain number of decimal-place digits in displayed values.'), - '#parents' => array_merge($parents, ['yaxis_decimal_count']), + '#size' => 5, + '#description' => $this->t('Enforce a certain number of decimal-place digits in displayed values.'), + '#parents' => array_merge($parents, ['yaxis_decimal_count']), ]; + $form['yaxis']['labels_rotation'] = [ - '#title' => $this->t('Labels rotation'), - '#type' => 'select', - '#options' => [ - 0 => $this->t('0°'), + '#title' => $this->t('Labels rotation'), + '#type' => 'select', + '#options' => [ + 0 => $this->t('0°'), 30 => $this->t('30°'), 45 => $this->t('45°'), 60 => $this->t('60°'), 90 => $this->t('90°'), ], - '#attributes' => [ + '#attributes' => [ 'class' => ['axis-inverted-show'] ], '#default_value' => $options['yaxis_labels_rotation'], - '#parents' => array_merge($parents, ['yaxis_labels_rotation']), + '#parents' => array_merge($parents, ['yaxis_labels_rotation']), ]; return $form; } /** + * Get Charts info. + * * @return array + * Charts info. */ - public function charts_info() { + public function chartsInfo() { $charts_info = []; foreach ($this->moduleHandler->getImplementations('charts_info') as $module) { $module_charts_info = $this->moduleHandler->invoke($module, 'charts_info'); @@ -467,7 +528,10 @@ class ChartsConfigForm extends ConfigFormBase { } /** - * @return mixed + * Get charts types info. + * + * @return array + * Chart types. */ public function chartsChartsTypeInfo() { $chart_types['pie'] = [ @@ -503,13 +567,11 @@ class ChartsConfigForm extends ConfigFormBase { } /** - * @param array $form - * @param \Drupal\Core\Form\FormStateInterface $form_state + * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $config = $this->configFactory->getEditable('charts.settings'); - $config->set('charts_default_settings', $form_state->getValue('charts_default_settings')); - $config->save(); + $this->config->set('charts_default_settings', $form_state->getValue('charts_default_settings')); + $this->config->save(); } }