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

Issue #3426704 by andileco, nikathone, jwilson3: Ability to disable some chart types

parent 61bf28c6
No related branches found
No related tags found
1 merge request!89Issue #3426704: Ability to disable some chart types
Pipeline #157636 passed with warnings
......@@ -133,3 +133,37 @@ function hook_chart_definition_alter(array &$definition, array $element, $chart_
*/
function hook_chart_definition_CHART_ID_alter(array &$definition, array $element, $chart_id) {
}
/**
* Alter the list of supported chart types for a chart plugin.
*
* To use this hook, first define the chart types you want to add in a file
* named <module>.charts_types.yml to your module's root directory. For example,
* if your module is named "charts_foo", the file should be named
* "charts_foo.charts_types.yml".
*
* The contents of this file will look something like:
*
* @code
* candlestick:
* label: 'Candlestick'
* axis: 'xy'
* axis_inverted: false
* stacking: false
* @endcode
*
* @see charts.charts_types.yml
*
* With that file in place, you can now implement this hook. See below for an
* example adding the 'candlestick' chart type to the 'highcharts' chart plugin.
*
* @param array $types
* An array of supported chart types.
* @param string $chart_plugin_id
* The chart plugin ID.
*/
function hook_charts_plugin_supported_chart_types_alter(array &$types, string $chart_plugin_id) {
if ($chart_plugin_id === 'highcharts') {
$types[] = 'candlestick';
}
}
......@@ -17,21 +17,25 @@ abstract class ChartBase extends PluginBase implements ChartInterface {
/**
* {@inheritdoc}
*/
public function getChartName() {
public function getChartName(): string {
return $this->pluginDefinition['name'];
}
/**
* {@inheritdoc}
*/
public function getSupportedChartTypes() {
return $this->pluginDefinition['types'];
public function getSupportedChartTypes(): array {
$types = $this->pluginDefinition['types'];
$chart_plugin_id = $this->getPluginId();
// @todo Add dependency injection for the next major version.
\Drupal::moduleHandler()->alter('charts_plugin_supported_chart_types', $types, $chart_plugin_id);
return $types;
}
/**
* {@inheritdoc}
*/
public function isSupportedChartType(string $chart_type_id) {
public function isSupportedChartType(string $chart_type_id): bool {
$supported_chart_types = $this->getSupportedChartTypes();
return !$supported_chart_types || in_array($chart_type_id, $supported_chart_types);
}
......@@ -39,14 +43,14 @@ abstract class ChartBase extends PluginBase implements ChartInterface {
/**
* {@inheritdoc}
*/
public function getConfiguration() {
public function getConfiguration(): array {
return $this->configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
public function setConfiguration(array $configuration): void {
$this->configuration = NestedArray::mergeDeep($this->defaultConfiguration(), $configuration);
}
......@@ -82,8 +86,8 @@ abstract class ChartBase extends PluginBase implements ChartInterface {
* @return array
* The defaults settings.
*/
public static function getDefaultSettings() {
$defaults = [
public static function getDefaultSettings(): array {
return [
'type' => 'line',
'library' => NULL,
'grouping' => FALSE,
......@@ -122,8 +126,6 @@ abstract class ChartBase extends PluginBase implements ChartInterface {
'colors' => self::getDefaultColors(),
],
];
return $defaults;
}
/**
......@@ -132,7 +134,7 @@ abstract class ChartBase extends PluginBase implements ChartInterface {
* @return array
* The hex colors.
*/
public static function getDefaultColors() {
public static function getDefaultColors(): array {
return [
'#2f7ed8',
'#0d233a',
......
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