You are here

protected function C3::getOptionsByCustomProperty in Charts 5.0.x

Same name and namespace in other branches
  1. 8.4 modules/charts_c3/src/Plugin/chart/Library/C3.php \Drupal\charts_c3\Plugin\chart\Library\C3::getOptionsByCustomProperty()

Get options by custom property.

Parameters

array $element: The element.

string $type: The chart type.

Return value

array Return options.

1 call to C3::getOptionsByCustomProperty()
C3::getOptionsByType in modules/charts_c3/src/Plugin/chart/Library/C3.php
Get options by type.

File

modules/charts_c3/src/Plugin/chart/Library/C3.php, line 116

Class

C3
Define a concrete class for a Chart.

Namespace

Drupal\charts_c3\Plugin\chart\Library

Code

protected function getOptionsByCustomProperty(array $element, $type) {
  $options = [];
  $properties = Element::properties($element);

  // Remove properties which are not related to this chart type.
  $properties = array_filter($properties, function ($property) use ($type) {
    $query = '#chart_' . $type . '_';
    return substr($property, 0, strlen($query)) === $query;
  });
  foreach ($properties as $property) {
    $query = '#chart_' . $type . '_';
    $option_key = substr($property, strlen($query), strlen($property));
    $options[$option_key] = $element[$property];
  }
  return $options;
}