Commit e55fa389 authored by Nia Kathoni's avatar Nia Kathoni Committed by Daniel Cothran
Browse files

Issue #3276699 by nikathone: Remove other unneeded services

parent 187605f5
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
<?php

use Drupal\Core\Serialization\Yaml;

/**
 * Initialize advanced requirements cdn config value.
 */
@@ -12,3 +14,26 @@ function charts_post_update_initialize_advanced_requirements_cdn(&$sandbox) {
    $config->save();
  }
}

/**
 * Update the existing default config display colors to increase them from 10 to 25.
 */
function charts_post_update_existing_default_colors_to_twenty_five(&$sandbox) {
  $config = \Drupal::service('config.factory')->getEditable('charts.settings');
  $existing_colors = $config->get('charts_default_settings.display.colors');

  if (count($existing_colors) === 10) {
    $path = \Drupal::service('extension.list.module')->getPath('charts');
    $default_install_settings_file = $path . '/config/install/charts.settings.yml';
    if (!file_exists($default_install_settings_file)) {
      return;
    }

    $default_install_settings = Yaml::decode(file_get_contents($default_install_settings_file));
    $install_colors = $default_install_settings['charts_default_settings']['display']['colors'];
    // We only want to add the last 15 colors to make it 25.
    $colors = array_merge($existing_colors, array_slice($install_colors, -15));
    $config->set('charts_default_settings.display.colors', $colors);
    $config->save();
  }
}
+0 −6
Original line number Diff line number Diff line
services:
  charts.charts_service:
    class: Drupal\charts\Services\ChartService
  charts.charts_attachment:
    class: Drupal\charts\Services\ChartAttachmentService
  charts.views_variable:
    class: Drupal\charts\Services\ViewsDataService
  plugin.manager.charts:
    class: Drupal\charts\ChartManager
    parent: default_plugin_manager
+4 −6
Original line number Diff line number Diff line
@@ -868,8 +868,7 @@ class BaseSettings extends FormElement {
    $max_weight = count($field_options);

    $field_options_count = 0;
    $default_colors = \Drupal::config('charts.settings')->get('charts_default_settings.display.colors');

    $default_colors = $options['display']['colors'];
    foreach ($field_options as $field_name => $field_label) {
      $field_option_element = &$element['fields']['data_providers'][$field_name];
      $default_value = $options['fields']['data_providers'][$field_name] ?? [];
@@ -1061,16 +1060,15 @@ class BaseSettings extends FormElement {
    ];

    // Using the default colors in the settings to populate the colors.
    $default_colors = \Drupal::config('charts.settings')->get('charts_default_settings.display.colors');
    for ($color_count = 0; $color_count < count($default_colors); $color_count++) {
      $element['display']['colors'][$color_count] = [
    foreach ($options['display']['colors'] as $color_index => $color) {
      $element['display']['colors'][$color_index] = [
        '#type' => 'textfield',
        '#attributes' => ['TYPE' => 'color'],
        '#size' => 10,
        '#maxlength' => 7,
        '#theme_wrappers' => [],
        '#suffix' => ' ',
        '#default_value' => $options['display']['colors'][$color_count] ?? $default_colors[$color_count],
        '#default_value' => $color,
      ];
    }

+1 −14
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
namespace Drupal\charts\Plugin\views\style;

use Drupal\charts\Plugin\chart\Library\ChartInterface;
use Drupal\charts\Services\ChartAttachmentServiceInterface;
use Drupal\charts\ChartManager;
use Drupal\charts\TypeManager;
use Drupal\Component\Serialization\Json;
@@ -55,13 +54,6 @@ class ChartsPluginStyleChart extends StylePluginBase implements ContainerFactory
   */
  protected $usesRowPlugin = TRUE;

  /**
   * The attachment service.
   *
   * @var \Drupal\charts\Services\ChartAttachmentService
   */
  protected $attachmentService;

  /**
   * The chart manager service.
   *
@@ -108,8 +100,6 @@ class ChartsPluginStyleChart extends StylePluginBase implements ContainerFactory
   *   The plugin implementation definition.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory service.
   * @param \Drupal\charts\Services\ChartAttachmentServiceInterface $attachment_service
   *   The attachment service.
   * @param \Drupal\charts\ChartManager $chart_manager
   *   The chart manager service.
   * @param \Drupal\charts\TypeManager $chart_type_manager
@@ -119,10 +109,9 @@ class ChartsPluginStyleChart extends StylePluginBase implements ContainerFactory
   * @param \Drupal\Core\Template\TwigEnvironment $twig
   *   The Twig environment.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, ChartAttachmentServiceInterface $attachment_service, ChartManager $chart_manager, TypeManager $chart_type_manager, RouteMatchInterface $route_match, TwigEnvironment $twig) {
  public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, ChartManager $chart_manager, TypeManager $chart_type_manager, RouteMatchInterface $route_match, TwigEnvironment $twig) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->configFactory = $config_factory;
    $this->attachmentService = $attachment_service;
    $this->chartManager = $chart_manager;
    $this->chartTypeManager = $chart_type_manager;
    $this->routeMatch = $route_match;
@@ -138,7 +127,6 @@ class ChartsPluginStyleChart extends StylePluginBase implements ContainerFactory
      $plugin_id,
      $plugin_definition,
      $container->get('config.factory'),
      $container->get('charts.charts_attachment'),
      $container->get('plugin.manager.charts'),
      $container->get('plugin.manager.charts_type'),
      $container->get('current_route_match'),
@@ -471,7 +459,6 @@ class ChartsPluginStyleChart extends StylePluginBase implements ContainerFactory
        }
      }
    }
    $this->attachmentService->setAttachmentViews($attachments);

    // Print the chart.
    return $chart;
+0 −33
Original line number Diff line number Diff line
<?php

namespace Drupal\charts\Services;

/**
 * Class ChartAttachmentService.
 *
 * @package Drupal\charts\Services.
 */
class ChartAttachmentService implements ChartAttachmentServiceInterface {

  /**
   * The view attachment.
   *
   * @var array
   */
  private $attachmentViews;

  /**
   * {@inheritdoc}
   */
  public function getAttachmentViews() {
    return $this->attachmentViews;
  }

  /**
   * {@inheritdoc}
   */
  public function setAttachmentViews(array $attachmentViews = []) {
    $this->attachmentViews = $attachmentViews;
  }

}
Loading