You are here

public function PdbBlock::build in Decoupled Blocks 8

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

3 calls to PdbBlock::build()
EmberBlock::build in modules/pdb_ember/src/Plugin/Block/EmberBlock.php
Builds and returns the renderable array for this block plugin.
Ng2Block::build in modules/pdb_ng2/src/Plugin/Block/Ng2Block.php
Builds and returns the renderable array for this block plugin.
ReactBlock::build in modules/pdb_react/src/Plugin/Block/ReactBlock.php
Builds and returns the renderable array for this block plugin.
3 methods override PdbBlock::build()
EmberBlock::build in modules/pdb_ember/src/Plugin/Block/EmberBlock.php
Builds and returns the renderable array for this block plugin.
Ng2Block::build in modules/pdb_ng2/src/Plugin/Block/Ng2Block.php
Builds and returns the renderable array for this block plugin.
ReactBlock::build in modules/pdb_react/src/Plugin/Block/ReactBlock.php
Builds and returns the renderable array for this block plugin.

File

src/Plugin/Block/PdbBlock.php, line 47

Class

PdbBlock
Class PdbBlock.

Namespace

Drupal\pdb\Plugin\Block

Code

public function build() {
  $component = $this
    ->getComponentInfo();
  $this->configuration['uuid'] = \Drupal::service('uuid')
    ->generate();
  $attached = [];
  $framework = $this
    ->attachFramework($component);
  if ($framework) {
    $attached = array_merge_recursive($attached, $framework);
  }
  $settings = $this
    ->attachSettings($component);
  if ($settings) {
    $attached = array_merge_recursive($attached, $settings);
  }
  $libraries = $this
    ->attachLibraries($component);
  if ($libraries) {
    $attached = array_merge_recursive($attached, $libraries);
  }
  $header = $this
    ->attachPageHeader($component);
  if ($header) {
    $attached = array_merge_recursive($attached, $header);
  }
  $contexts = $this
    ->getContexts();
  if ($contexts) {
    $contexts_values = $this
      ->getContextsValues($contexts);
    $this->configuration['contexts'] = $contexts_values;
    $js_contexts = $this
      ->getJsContexts($contexts_values);
    $attached['drupalSettings']['pdb']['contexts'] = $js_contexts;
  }
  if (isset($this->configuration['pdb_configuration'])) {

    // @todo Is there anything else unique to key off of besides uuid
    $attached['drupalSettings']['pdb']['configuration'][$this->configuration['uuid']] = $this->configuration['pdb_configuration'];
  }
  return [
    '#attached' => $attached,
  ];
}