PHP code example of lullabot / proxy_block

1. Go to this page and download the library: Download lullabot/proxy_block library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lullabot / proxy_block example snippets


    $target_block = $this->blockManager->createInstance($plugin_id, $block_config);
    

    if ($target_block instanceof ContextAwarePluginInterface) {
      $this->passContextsToTargetBlock($target_block);
    }
    

    $access_result = $target_block->access($this->currentUser, TRUE);
    

    $build = $target_block->build();
    

    $this->bubbleTargetBlockCacheMetadata($build, $target_block);
    

protected function passContextsToTargetBlock(ContextAwarePluginInterface
$target_block): void {
  $proxy_contexts = $this->getContexts();
  $context_mapping = $this->getConfiguration()['context_mapping'] ?? [];

  // Map contexts based on configuration
  foreach ($target_context_definitions as $name => $definition) {
    $source_name = $context_mapping[$name] ?? $name;
    if (isset($proxy_contexts[$source_name])) {
      $target_block->setContext($name, $proxy_contexts[$source_name]);
    }
  }
}