From a36a29c0b025d2520972dfafd3f8d8e7e0567d68 Mon Sep 17 00:00:00 2001
From: mmwebaze <mmwebaze@3201071.no-reply.drupal.org>
Date: Wed, 23 May 2018 14:43:52 -0400
Subject: [PATCH] Issue #2954043 by ritzz, mwebaze, andileco: Replace instances
 of drupal_set_message

---
 .../src/Controller/ChartsApiExample.php       | 20 +++++++++++++------
 .../src/Plugin/chart/Highcharts.php           |  4 ++--
 src/Util/Util.php                             |  2 +-
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/modules/charts_api_example/src/Controller/ChartsApiExample.php b/modules/charts_api_example/src/Controller/ChartsApiExample.php
index 47dabbe..346c11f 100644
--- a/modules/charts_api_example/src/Controller/ChartsApiExample.php
+++ b/modules/charts_api_example/src/Controller/ChartsApiExample.php
@@ -5,14 +5,18 @@ namespace Drupal\charts_api_example\Controller;
 use Drupal\charts\Services\ChartsSettingsService;
 use Drupal\Core\Controller\ControllerBase;
 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
+use Drupal\Core\Messenger\MessengerInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
+use Drupal\Component\Uuid\Php;
 
 /**
  * Charts Api Example.
  */
 class ChartsApiExample extends ControllerBase implements ContainerInjectionInterface {
 
-  private $chartSettings;
+  protected $chartSettings;
+  protected $messenger;
+  protected $uuidService;
 
   /**
    * Construct.
@@ -20,8 +24,10 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter
    * @param \Drupal\charts\Services\ChartsSettingsService $chartSettings
    *   Service ChartsSettingsService.
    */
-  public function __construct(ChartsSettingsService $chartSettings) {
+  public function __construct(ChartsSettingsService $chartSettings, MessengerInterface $messenger, Php $uuidService) {
     $this->chartSettings = $chartSettings->getChartsSettings();
+    $this->messenger = $messenger;
+    $this->uuidService = $uuidService;
   }
 
   /**
@@ -34,7 +40,7 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter
 
     $library = $this->chartSettings['library'];
     if (empty($library)) {
-      drupal_set_message($this->t('You need to first configure Charts default settings'));
+      $this->messenger->addError($this->t('You need to first configure Charts default settings'));
       return [];
     }
 
@@ -80,8 +86,8 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter
     }
 
     // Creates a UUID for the chart ID.
-    $uuid_service = \Drupal::service('uuid');
-    $chartId = 'chart-' . $uuid_service->generate();
+    //$uuid_service = \Drupal::service('uuid');
+    $chartId = 'chart-' . $this->uuidService->generate();
 
     $build = [
       '#theme' => 'charts_api_example',
@@ -100,7 +106,9 @@ class ChartsApiExample extends ControllerBase implements ContainerInjectionInter
    */
   public static function create(ContainerInterface $container) {
     return new static(
-      $container->get('charts.settings')
+      $container->get('charts.settings'),
+      $container->get('messenger'),
+      $container->get('uuid')
     );
   }
 
diff --git a/modules/charts_highcharts/src/Plugin/chart/Highcharts.php b/modules/charts_highcharts/src/Plugin/chart/Highcharts.php
index 4b32a77..979c372 100644
--- a/modules/charts_highcharts/src/Plugin/chart/Highcharts.php
+++ b/modules/charts_highcharts/src/Plugin/chart/Highcharts.php
@@ -181,8 +181,8 @@ class Highcharts extends AbstractChart {
       $chartYaxis->setMin((int) $options['min']);
       $chartYaxis->setMax((int) $options['max']);
       if (count($seriesData) > 1 || count($categories) > 1) {
-        drupal_set_message(t('The gauge chart type does not work well 
-        with more than one value.'), 'warning');
+          \Drupal::service('messenger')->addMessage(t('The gauge 
+          chart type does not work well with more than one value.'), 'warning');
       }
     }
     $chartYaxis->setLabels($yaxisLabels);
diff --git a/src/Util/Util.php b/src/Util/Util.php
index 5ddaca0..218ac19 100644
--- a/src/Util/Util.php
+++ b/src/Util/Util.php
@@ -116,7 +116,7 @@ class Util {
    */
   public static function checkMissingLibrary($libraryPath = '') {
     if (!file_exists(DRUPAL_ROOT . DIRECTORY_SEPARATOR . $libraryPath)) {
-      drupal_set_message(t('Charting libraries might not be installed at the location @libraryPath.', [
+        \Drupal::service('messenger')->addMessage(t('Charting libraries might not be installed at the location @libraryPath.', [
         '@libraryPath' => $libraryPath,
       ]), 'error');
     }
-- 
GitLab