Skip to content
Snippets Groups Projects
Commit 2fa1c0db authored by Daniel Cothran's avatar Daniel Cothran
Browse files

Issue #3450588 by nikathone, kksandr, andileco: The "site_default" plugin does not exist

parent bc350175
No related branches found
No related tags found
No related merge requests found
Pipeline #365831 passed with warnings
......@@ -12,6 +12,7 @@ use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\charts\ChartManager;
use Drupal\charts\Plugin\chart\Library\ChartBase;
use Drupal\charts\Plugin\chart\Library\ChartInterface;
use Drupal\charts\Plugin\chart\Library\LibraryRetrieverTrait;
use Drupal\charts\TypeManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -23,6 +24,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class Chart extends RenderElementBase implements ContainerFactoryPluginInterface {
use StringTranslationTrait;
use LibraryRetrieverTrait;
/**
* The config factory service.
......@@ -282,29 +284,6 @@ class Chart extends RenderElementBase implements ContainerFactoryPluginInterface
}
}
/**
* Get the library.
*
* @param string $library
* The library.
*
* @return string
* The library.
*/
private function getLibrary($library) {
$definitions = $this->chartsManager->getDefinitions();
if (!$library || $library === 'site_default') {
$charts_settings = $this->configFactory->get('charts.settings');
$default_settings_library = $charts_settings->get('charts_default_settings.library');
$library = !empty($default_settings_library) ? $default_settings_library : key($definitions);
}
elseif (!isset($definitions[$library])) {
$library = key($definitions);
}
return $library;
}
/**
* Build the element.
*
......
<?php
namespace Drupal\charts\Plugin\chart\Library;
/**
* Implement a method to retrieve the "site_default" library.
*/
trait LibraryRetrieverTrait {
/**
* Get the library.
*
* @param string $library
* The library.
*
* @return string
* The library.
*/
private function getLibrary(string $library): string {
$definitions = $this->chartsManager->getDefinitions();
if (!$library || $library === 'site_default') {
$charts_settings = $this->configFactory->get('charts.settings');
$default_settings_library = $charts_settings->get('charts_default_settings.library');
$library = !empty($default_settings_library) ? $default_settings_library : key($definitions);
}
elseif (!isset($definitions[$library])) {
$library = key($definitions);
}
return $library;
}
}
......@@ -14,6 +14,7 @@ use Drupal\charts\ChartManager;
use Drupal\charts\ChartViewsFieldInterface;
use Drupal\charts\Element\BaseSettings;
use Drupal\charts\Plugin\chart\Library\ChartInterface;
use Drupal\charts\Plugin\chart\Library\LibraryRetrieverTrait;
use Drupal\charts\TypeManager;
use Drupal\views\Plugin\views\field\EntityField;
use Drupal\views\Plugin\views\style\StylePluginBase;
......@@ -35,6 +36,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class ChartsPluginStyleChart extends StylePluginBase implements ContainerFactoryPluginInterface {
use LibraryRetrieverTrait;
/**
* {@inheritdoc}
*/
......@@ -91,17 +94,17 @@ class ChartsPluginStyleChart extends StylePluginBase implements ContainerFactory
* The plugin implementation definition.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
* @param \Drupal\charts\ChartManager $chart_manager
* @param \Drupal\charts\ChartManager $chartsManager
* The chart manager service.
* @param \Drupal\charts\TypeManager $chart_type_manager
* The chart type manager.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, ChartManager $chart_manager, TypeManager $chart_type_manager, RouteMatchInterface $route_match) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, protected ChartManager $chartsManager, TypeManager $chart_type_manager, RouteMatchInterface $route_match) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configFactory = $config_factory;
$this->chartManager = $chart_manager;
$this->chartManager = $this->chartsManager;
$this->chartTypeManager = $chart_type_manager;
$this->routeMatch = $route_match;
}
......@@ -636,11 +639,14 @@ class ChartsPluginStyleChart extends StylePluginBase implements ContainerFactory
public function calculateDependencies() {
$dependencies = [];
if (!empty($this->options['chart_settings']['library'])) {
$plugin_definition = $this->chartManager->getDefinition($this->options['chart_settings']['library']);
$dependencies['module'] = [$plugin_definition['provider']];
if (empty($this->options['chart_settings']['library'])) {
return $dependencies;
}
$library = $this->getLibrary($this->options['chart_settings']['library']);
$plugin_definition = $this->chartsManager->getDefinition($library);
$dependencies['module'] = [$plugin_definition['provider']];
return $dependencies;
}
......
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