You are here

public function ChartsBlock::build in Charts 8.4

Same name and namespace in other branches
  1. 8.3 modules/charts_blocks/src/Plugin/Block/ChartsBlock.php \Drupal\charts_blocks\Plugin\Block\ChartsBlock::build()
  2. 5.0.x modules/charts_blocks/src/Plugin/Block/ChartsBlock.php \Drupal\charts_blocks\Plugin\Block\ChartsBlock::build()

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

modules/charts_blocks/src/Plugin/Block/ChartsBlock.php, line 95

Class

ChartsBlock
Provides a 'ChartsBlock' block.

Namespace

Drupal\charts_blocks\Plugin\Block

Code

public function build() {
  $chart_settings = !empty($this->configuration['chart']) ? $this->configuration['chart'] : [];

  // Creates a UUID for the chart ID.
  $chart_id = 'charts_block__' . $this->configuration['id'];
  $uuid_service = \Drupal::service('uuid');
  $id = 'chart-' . $uuid_service
    ->generate();
  $build = Chart::buildElement($chart_settings, $chart_id);
  $build['#id'] = $id;
  $build['#chart_id'] = $chart_id;
  return $build;
}