Skip to content

Instantly share code, notes, and snippets.

@sdboyer
Created June 4, 2013 04:11
Show Gist options
  • Select an option

  • Save sdboyer/5703514 to your computer and use it in GitHub Desktop.

Select an option

Save sdboyer/5703514 to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* Contains Drupal\block\DefaultBlockController.
*/
namespace Drupal\block;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Page\HtmlFragment;
use Drupal\block\BlockPluginInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
/**
* Default controller for rendering a block.
*/
class DefaultBlockController implements BlockControllerInterface {
/**
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
public function __construct(ModuleHandlerInterface $moduleHandler) {
$this->moduleHandler = $moduleHandler;
}
/**
* Renders a provided block into an HtmlFragment.
*
* @param Request $request
* @param BlockPluginInterface $block
*
* @return \Drupal\Core\Page\HtmlFragment
*/
public function respond(Request $request, BlockPluginInterface $block) {
$fragment = new HtmlFragment();
$fragment->addAssetBag($block->getAssets());
$fragment->setTitle($block->getTitle());
if ($content = $block->build()) {
$render = array(
'#theme_wrappers' => array('block_ng'),
'#block' => $block,
'content' => $content,
'#block_config' => array(
// @todo most of this doesn't make sense, but it's here to kinda keep things on the rails for now.
'label' => check_plain($block->getTitle()),
),
);
$this->moduleHandler->alter('block_ng_view', $render);
$fragment->setContent(drupal_render($render));
}
return $fragment;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment