You are here

protected function PdbBlock::getJsContexts in Decoupled Blocks 8

Get an array of serialized JS contexts.

Parameters

array $contexts: The contexts to serialize.

Return value

array An array of serialized JS contexts.

1 call to PdbBlock::getJsContexts()
PdbBlock::build in src/Plugin/Block/PdbBlock.php
Builds and returns the renderable array for this block plugin.

File

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

Class

PdbBlock
Class PdbBlock.

Namespace

Drupal\pdb\Plugin\Block

Code

protected function getJsContexts(array $contexts) {
  $js_contexts = [];
  foreach ($contexts as $key => $context) {
    if (is_object($context) && method_exists($context, 'toArray')) {

      // Get the array version of the entity context.
      $js_contexts[$key] = $context
        ->toArray();
    }
    else {

      // Leave the context as it is otherwise.
      $js_contexts[$key] = $context;
    }
  }
  return $js_contexts;
}