You are here

private static function BaseSettings::buildLibraryConfigurationForm in Charts 8.4

Same name and namespace in other branches
  1. 5.0.x src/Element/BaseSettings.php \Drupal\charts\Element\BaseSettings::buildLibraryConfigurationForm()

Builds the chart library configuration form into the settings.

Parameters

array $element: The element.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

string $library: The chart library.

Return value

array The configuration subform.

Throws

\Drupal\Component\Plugin\Exception\PluginException

1 call to BaseSettings::buildLibraryConfigurationForm()
BaseSettings::processSettings in src/Element/BaseSettings.php
Processes the settings element.

File

src/Element/BaseSettings.php, line 1097

Class

BaseSettings
Provides a form element for setting a chart.

Namespace

Drupal\charts\Element

Code

private static function buildLibraryConfigurationForm(array $element, FormStateInterface $form_state, $library) {
  $library_form = $library . '_settings';
  $plugin_configuration = $element['#value'][$library_form] ?? [];

  // Using plugins to get the available installed libraries.

  /** @var \Drupal\charts\ChartManager $plugin_manager */
  $plugin_manager = \Drupal::service('plugin.manager.charts');

  /** @var \Drupal\charts\Plugin\chart\Library\ChartInterface $instance */
  $plugin = $plugin_manager
    ->createInstance($library, $plugin_configuration);
  $element[$library_form] = [
    '#type' => 'details',
    '#title' => new TranslatableMarkup('@library settings', [
      '@library' => $plugin
        ->getPluginDefinition()['name'],
    ]),
    '#group' => $element['display']['#group'],
    '#weight' => 4,
  ];
  $element[$library_form] = $plugin
    ->buildConfigurationForm($element[$library_form], $form_state);
  return $element;
}