From 758cce4ab78c5275a3336d8bb0ee39e53dc84eea Mon Sep 17 00:00:00 2001
From: andileco <daniel@andile.co>
Date: Thu, 20 Apr 2017 15:06:32 -0400
Subject: [PATCH] Created a ChartsInterface as a place to define constants.
 Also moved the API example module into the modules folder. And fixed code
 formatting in some places.

---
 charts.api.php                                |  4 ++-
 includes/charts.pages.inc                     | 34 +++++--------------
 .../charts_api_example}/README.txt            |  0
 .../charts_api_example.info.yml               |  2 +-
 .../charts_api_example.libraries.yml          |  0
 .../charts_api_example.module                 |  0
 .../charts_api_example.routing.yml            |  0
 .../charts_api_example}/composer.json         |  0
 .../js/charts_api_example.js                  |  0
 .../src/Controller/ChartsApiExample.php       | 13 +++----
 .../src/Tests/LoadTest.php                    |  2 +-
 .../templates/charts_api_example.html.twig    |  0
 src/Form/ChartsConfigForm.php                 | 15 ++++----
 src/Services/ChartsSettingsService.php        |  6 ++--
 src/Theme/ChartsInterface.php                 | 27 +++++++++++++++
 15 files changed, 59 insertions(+), 44 deletions(-)
 rename {charts_api_example => modules/charts_api_example}/README.txt (100%)
 rename {charts_api_example => modules/charts_api_example}/charts_api_example.info.yml (85%)
 rename {charts_api_example => modules/charts_api_example}/charts_api_example.libraries.yml (100%)
 rename {charts_api_example => modules/charts_api_example}/charts_api_example.module (100%)
 rename {charts_api_example => modules/charts_api_example}/charts_api_example.routing.yml (100%)
 rename {charts_api_example => modules/charts_api_example}/composer.json (100%)
 rename {charts_api_example => modules/charts_api_example}/js/charts_api_example.js (100%)
 rename {charts_api_example => modules/charts_api_example}/src/Controller/ChartsApiExample.php (86%)
 rename {charts_api_example => modules/charts_api_example}/src/Tests/LoadTest.php (95%)
 rename {charts_api_example => modules/charts_api_example}/templates/charts_api_example.html.twig (100%)
 create mode 100644 src/Theme/ChartsInterface.php

diff --git a/charts.api.php b/charts.api.php
index c2a33b5..fd26b74 100644
--- a/charts.api.php
+++ b/charts.api.php
@@ -1,5 +1,7 @@
 <?php
 
+use Drupal\charts\Theme\ChartsInterface;
+
 /**
  * @file
  * Documentation on hooks provided by the Charts module.
@@ -161,7 +163,7 @@ function hook_charts_type_info() {
     // If this chart supports both an X and Y axis, set this to
     // CHARTS_DUAL_AXIS. If only a single axis is supported (e.g. pie), then
     // set this to CHARTS_SINGLE_AXIS.
-    'axis' => CHARTS_DUAL_AXIS,
+    'axis' => ChartsInterface::CHARTS_DUAL_AXIS,
     // Many charting libraries always refer to the main axis as the "y-axis",
     // even if the chart's main axis is horizontal. An example of this is a
     // bar chart, where the values are along the horizontal axis.
diff --git a/includes/charts.pages.inc b/includes/charts.pages.inc
index 4e0085e..8de34d1 100644
--- a/includes/charts.pages.inc
+++ b/includes/charts.pages.inc
@@ -4,6 +4,7 @@
  * @file
  * Menu callbacks for Charts module.
  */
+use Drupal\charts\Theme\ChartsInterface;
 
 /**
  * Module settings page. Users can set the default layout of their charts.
@@ -23,23 +24,6 @@
  * The form with the chart settings added.
  */
 
-/**
- * Used to define a single axis.
- *
- * Constant used in hook_charts_type_info() to declare chart types with a single
- * axis. For example a pie chart only has a single dimension.
- */
-define('CHARTS_SINGLE_AXIS', 'y_only');
-
-/**
- * Used to define a dual axis.
- *
- * Constant used in hook_charts_type_info() to declare chart types with a dual
- * axes. Most charts use this type of data, meaning multiple categories each
- * have multiple values. This type of data is usually represented as a table.
- */
-define('CHARTS_DUAL_AXIS', 'xy');
-
 /**
  * Retrieve a list of all charting libraries available.
  *
@@ -74,7 +58,7 @@ function charts_type_info() {
   foreach ($charts_type_info as $chart_type => $chart_type_info) {
     $charts_type_info[$chart_type] += array(
       'label' => '',
-      'axis' => CHARTS_DUAL_AXIS,
+      'axis' => ChartsInterface::CHARTS_DUAL_AXIS,
       'axis_inverted' => FALSE,
       'stacking' => FALSE,
     );
@@ -104,31 +88,31 @@ function charts_get_type($chart_type) {
 function charts_charts_type_info() {
   $chart_types['pie'] = array(
     'label' => t('Pie'),
-    'axis' => CHARTS_SINGLE_AXIS,
+    'axis' => ChartsInterface::CHARTS_SINGLE_AXIS,
   );
   $chart_types['bar'] = array(
     'label' => t('Bar'),
-    'axis' => CHARTS_DUAL_AXIS,
+    'axis' => ChartsInterface::CHARTS_DUAL_AXIS,
     'axis_inverted' => TRUE,
     'stacking' => TRUE,
   );
   $chart_types['column'] = array(
     'label' => t('Column'),
-    'axis' => CHARTS_DUAL_AXIS,
+    'axis' => ChartsInterface::CHARTS_DUAL_AXIS,
     'stacking' => TRUE,
   );
   $chart_types['line'] = array(
     'label' => t('Line'),
-    'axis' => CHARTS_DUAL_AXIS,
+    'axis' => ChartsInterface::CHARTS_DUAL_AXIS,
   );
   $chart_types['area'] = array(
     'label' => t('Area'),
-    'axis' => CHARTS_DUAL_AXIS,
+    'axis' => ChartsInterface::CHARTS_DUAL_AXIS,
     'stacking' => TRUE,
   );
   $chart_types['scatter'] = array(
     'label' => t('Scatter'),
-    'axis' => CHARTS_DUAL_AXIS,
+    'axis' => ChartsInterface::CHARTS_DUAL_AXIS,
   );
   return $chart_types;
 }
@@ -265,7 +249,7 @@ function charts_settings_form($form, $defaults = array(), $field_options = array
     if ($chart_type_info['axis_inverted']) {
       $form['type'][$chart_type]['#attributes']['data-axis-inverted'] = TRUE;
     }
-    if ($chart_type_info['axis'] === CHARTS_SINGLE_AXIS) {
+    if ($chart_type_info['axis'] === ChartsInterface::CHARTS_SINGLE_AXIS) {
       $form['type'][$chart_type]['#attributes']['data-axis-single'] = TRUE;
     }
   }
diff --git a/charts_api_example/README.txt b/modules/charts_api_example/README.txt
similarity index 100%
rename from charts_api_example/README.txt
rename to modules/charts_api_example/README.txt
diff --git a/charts_api_example/charts_api_example.info.yml b/modules/charts_api_example/charts_api_example.info.yml
similarity index 85%
rename from charts_api_example/charts_api_example.info.yml
rename to modules/charts_api_example/charts_api_example.info.yml
index 25eba7f..45bcce2 100644
--- a/charts_api_example/charts_api_example.info.yml
+++ b/modules/charts_api_example/charts_api_example.info.yml
@@ -1,4 +1,4 @@
-name: charts_api_example
+name: Charts API Example
 type: module
 description: Demonstrates how to use the Charts module without Views.
 core: 8.x
diff --git a/charts_api_example/charts_api_example.libraries.yml b/modules/charts_api_example/charts_api_example.libraries.yml
similarity index 100%
rename from charts_api_example/charts_api_example.libraries.yml
rename to modules/charts_api_example/charts_api_example.libraries.yml
diff --git a/charts_api_example/charts_api_example.module b/modules/charts_api_example/charts_api_example.module
similarity index 100%
rename from charts_api_example/charts_api_example.module
rename to modules/charts_api_example/charts_api_example.module
diff --git a/charts_api_example/charts_api_example.routing.yml b/modules/charts_api_example/charts_api_example.routing.yml
similarity index 100%
rename from charts_api_example/charts_api_example.routing.yml
rename to modules/charts_api_example/charts_api_example.routing.yml
diff --git a/charts_api_example/composer.json b/modules/charts_api_example/composer.json
similarity index 100%
rename from charts_api_example/composer.json
rename to modules/charts_api_example/composer.json
diff --git a/charts_api_example/js/charts_api_example.js b/modules/charts_api_example/js/charts_api_example.js
similarity index 100%
rename from charts_api_example/js/charts_api_example.js
rename to modules/charts_api_example/js/charts_api_example.js
diff --git a/charts_api_example/src/Controller/ChartsApiExample.php b/modules/charts_api_example/src/Controller/ChartsApiExample.php
similarity index 86%
rename from charts_api_example/src/Controller/ChartsApiExample.php
rename to modules/charts_api_example/src/Controller/ChartsApiExample.php
index f778d90..bae392a 100644
--- a/charts_api_example/src/Controller/ChartsApiExample.php
+++ b/modules/charts_api_example/src/Controller/ChartsApiExample.php
@@ -15,7 +15,7 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter
     $this->chartSettings = $chartSettings->getChartsSettings();
   }
 
-  public function display(){
+  public function display() {
 
     $library = $this->chartSettings['library'];
     $options = [];
@@ -26,23 +26,24 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter
     $options['yaxis_max'] = '';
     $options['xaxis_title'] = t('X-Axis');
     //sample data format
-    $categories = ["Category 1","Category 2","Category 3","Category 4"];
+    $categories = ["Category 1", "Category 2", "Category 3", "Category 4"];
     $seriesData = [
       ["name" => "Series 1", "color" => "#0d233a", "type" => null, "data" => [250, 350, 400, 200]],
       ["name" => "Series 2", "color" => "#8bbc21", "type" => "column", "data" => [150, 450, 500, 300]],
-      ["name" => "Series 3", "color" => "#910000", "type" => "area",  "data" => [0, 0, 60, 90]]
+      ["name" => "Series 3", "color" => "#910000", "type" => "area", "data" => [0, 0, 60, 90]]
     ];
 
-    $element = array(
+    $element = [
       '#theme' => 'charts_api_example',
       '#library' => $this->t($library),
       '#categories' => $categories,
       '#seriesData' => $seriesData,
       '#options' => $options,
-    );
+    ];
     return $element;
   }
-  public static function create(ContainerInterface $container){
+
+  public static function create(ContainerInterface $container) {
     return new static(
       $container->get('charts.settings')
     );
diff --git a/charts_api_example/src/Tests/LoadTest.php b/modules/charts_api_example/src/Tests/LoadTest.php
similarity index 95%
rename from charts_api_example/src/Tests/LoadTest.php
rename to modules/charts_api_example/src/Tests/LoadTest.php
index e388f15..fac49ec 100644
--- a/charts_api_example/src/Tests/LoadTest.php
+++ b/modules/charts_api_example/src/Tests/LoadTest.php
@@ -10,7 +10,7 @@ use Drupal\simpletest\WebTestBase;
  *
  * @group charts_api_example
  */
-class LoadTest extends WebTestBase{
+class LoadTest extends WebTestBase {
 
   /**
    * Modules to enable.
diff --git a/charts_api_example/templates/charts_api_example.html.twig b/modules/charts_api_example/templates/charts_api_example.html.twig
similarity index 100%
rename from charts_api_example/templates/charts_api_example.html.twig
rename to modules/charts_api_example/templates/charts_api_example.html.twig
diff --git a/src/Form/ChartsConfigForm.php b/src/Form/ChartsConfigForm.php
index 4361988..e9392f4 100644
--- a/src/Form/ChartsConfigForm.php
+++ b/src/Form/ChartsConfigForm.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\charts\Form;
 
+use Drupal\charts\Theme\ChartsInterface;
 use Drupal\Core\Extension\ModuleHandler;
 use Drupal\Core\Url;
 use Drupal\Core\Link;
@@ -188,7 +189,7 @@ class ChartsConfigForm extends ConfigFormBase {
       if ($chart_type_info['axis_inverted']) {
         $form['type'][$chart_type]['#attributes']['data-axis-inverted'] = TRUE;
       }
-      if ($chart_type_info['axis'] === CHARTS_SINGLE_AXIS) {
+      if ($chart_type_info['axis'] === ChartsInterface::CHARTS_SINGLE_AXIS) {
         $form['type'][$chart_type]['#attributes']['data-axis-single'] = TRUE;
       }
     }
@@ -477,31 +478,31 @@ class ChartsConfigForm extends ConfigFormBase {
   public function charts_charts_type_info() {
     $chart_types['pie'] = [
       'label' => $this->t('Pie'),
-      'axis' => CHARTS_SINGLE_AXIS,
+      'axis' => ChartsInterface::CHARTS_SINGLE_AXIS,
     ];
     $chart_types['bar'] = [
       'label' => $this->t('Bar'),
-      'axis' => CHARTS_DUAL_AXIS,
+      'axis' => ChartsInterface::CHARTS_DUAL_AXIS,
       'axis_inverted' => TRUE,
       'stacking' => TRUE,
     ];
     $chart_types['column'] = [
       'label' => $this->t('Column'),
-      'axis' => CHARTS_DUAL_AXIS,
+      'axis' => ChartsInterface::CHARTS_DUAL_AXIS,
       'stacking' => TRUE,
     ];
     $chart_types['line'] = [
       'label' => $this->t('Line'),
-      'axis' => CHARTS_DUAL_AXIS,
+      'axis' => ChartsInterface::CHARTS_DUAL_AXIS,
     ];
     $chart_types['area'] = [
       'label' => $this->t('Area'),
-      'axis' => CHARTS_DUAL_AXIS,
+      'axis' => ChartsInterface::CHARTS_DUAL_AXIS,
       'stacking' => TRUE,
     ];
     $chart_types['scatter'] = [
       'label' => $this->t('Scatter'),
-      'axis' => CHARTS_DUAL_AXIS,
+      'axis' => ChartsInterface::CHARTS_DUAL_AXIS,
     ];
 
     return $chart_types;
diff --git a/src/Services/ChartsSettingsService.php b/src/Services/ChartsSettingsService.php
index 2864c19..ecaa4c8 100644
--- a/src/Services/ChartsSettingsService.php
+++ b/src/Services/ChartsSettingsService.php
@@ -4,16 +4,16 @@ namespace Drupal\charts\Services;
 
 use Drupal\Core\Config\ConfigFactory;
 
-class ChartsSettingsService implements ChartsSettingsServiceInterface{
+class ChartsSettingsService implements ChartsSettingsServiceInterface {
 
   //private $editableConfigName = 'charts.settings';
   private $configFactory;
 
-  public function __construct(ConfigFactory $config_factory){
+  public function __construct(ConfigFactory $config_factory) {
     $this->configFactory = $config_factory;
   }
 
-  public function getChartsSettings(){
+  public function getChartsSettings() {
     $config = $this->configFactory->getEditable('charts.settings');
 
     return $config->get('charts_default_settings');
diff --git a/src/Theme/ChartsInterface.php b/src/Theme/ChartsInterface.php
new file mode 100644
index 0000000..d3fb36b
--- /dev/null
+++ b/src/Theme/ChartsInterface.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Drupal\charts\Theme;
+
+/**
+ * Provides an interface defining Charts constants.
+ */
+interface ChartsInterface {
+
+  /**
+   * Used to define a single axis.
+   *
+   * Constant used in hook_charts_type_info() to declare chart types with a single
+   * axis. For example a pie chart only has a single dimension.
+   */
+  const CHARTS_SINGLE_AXIS = 'y_only';
+
+  /**
+   * Used to define a dual axis.
+   *
+   * Constant used in hook_charts_type_info() to declare chart types with a dual
+   * axes. Most charts use this type of data, meaning multiple categories each
+   * have multiple values. This type of data is usually represented as a table.
+   */
+  const CHARTS_DUAL_AXIS = 'xy';
+
+}
-- 
GitLab