Skip to content
Snippets Groups Projects
Commit a36a29c0 authored by mmwebaze's avatar mmwebaze Committed by Daniel Cothran
Browse files

Issue #2954043 by ritzz, mwebaze, andileco: Replace instances of drupal_set_message

parent d212c18d
No related branches found
No related tags found
No related merge requests found
......@@ -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')
);
}
......
......@@ -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);
......
......@@ -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');
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment