You are here

public function WSDataBlock::build in Web Service Data 8

Same name and namespace in other branches
  1. 2.0.x modules/wsdata_block/src/Plugin/Block/WSDataBlock.php \Drupal\wsdata_block\Plugin\Block\WSDataBlock::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/wsdata_block/src/Plugin/Block/WSDataBlock.php, line 102

Class

WSDataBlock
Provides a 'Green House Gas Emissions' block.

Namespace

Drupal\wsdata_block\Plugin\Block

Code

public function build() {
  $form = [];
  $result = $this->wsdata
    ->call($this->configuration['wscall'], NULL, $this->configuration['replacements'], $this->configuration['data'], [], $this->configuration['returnToken']);
  $form['wsdata_block_data'] = [
    '#prefix' => '<div class="wsdata_block">',
    '#suffix' => '</div>',
    '#markup' => is_array($result) ? print_r($result, TRUE) : $result,
  ];
  return $form;
}