0

I am working on the Charts module and have a stubborn issue that I'm trying to resolve.

Charts provides a Views style plugin and a Views display plugin called Chart Attachment. The display plugin extends the Attachment display plugin and sets the View's format to Charts. However, I run into an issue where I really need the Chart Attachment's formatting settings to apply to its display only ("This chart_extension (override)"). If it applies to all displays, it ends up breaking the Chart because the whole idea behind the Chart Attachment is for it to be different than its parent.

Here is what the Format settings should look like immediately after clicking "Add" -> "Chart attachment" in the View displays section:

showing the italic format section

Note the italic font on Chart and Settings within the Format section.

When you click on Chart from that attachment, this is what you should see without clicking anything else:

showing this chart_extension override

So how can one code the Display plugin to enforce style format options to "This chart_extension (override)"?

Or, if there is another approach that accomplishes the same thing, I would be open to that.

3
+50

This is how you can achieve that:

diff --git a/src/Plugin/views/display/ChartsPluginDisplayChart.php b/src/Plugin/views/display/ChartsPluginDisplayChart.php
index 3dbad31..68048ce 100644
--- a/src/Plugin/views/display/ChartsPluginDisplayChart.php
+++ b/src/Plugin/views/display/ChartsPluginDisplayChart.php
@@ -29,6 +29,10 @@ class ChartsPluginDisplayChart extends Attachment {
     $options['style_plugin']['default'] = 'chart';
     $options['inherit_yaxis'] = ['default' => '1'];

+    // Set the default style plugin to 'chart'.
+    $options['style']['contains']['type']['default'] = 'chart';
+    $options['defaults']['default']['style'] = FALSE;
+
     return $options;
   }

API docs: https://api.drupal.org/api/drupal/core%21modules%21views%21src%21Plugin%21views%21display%21DisplayPluginBase.php/function/DisplayPluginBase%3A%3AdefineOptions/8.2.x

  • Wouldn't it be better to make your own plugin that extends the ChartsPluginDisplayChart and add your options there? – sareed Jun 28 '18 at 14:11
  • No, the question is about find the way to automatically change the display style for Chart attachment, which is defined in ChartsPluginDisplayChart. It's the perfect place for this change. – quex Jun 28 '18 at 16:21
  • If you are able, you should extend contrib modules, not patch them. Unless of course you feel it's a bug and are going to open a ticket and submit the patch as a fix. – sareed Jun 28 '18 at 16:53
  • 1
    I believe that andileco (he is one of maintainers of Charts module) was asking for solution for Charts module itself. – quex Jun 28 '18 at 17:13
  • Ah, I did not notice the connection. If that is the case, then I withdraw my objection :) – sareed Jun 28 '18 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.