Skip to content

Instantly share code, notes, and snippets.

@edutrul
Created November 20, 2016 23:30
Show Gist options
  • Save edutrul/3e1d07bfc533195442b2f580fb0b32b6 to your computer and use it in GitHub Desktop.
Save edutrul/3e1d07bfc533195442b2f580fb0b32b6 to your computer and use it in GitHub Desktop.
Create a block with Context to be used in panels and load context entity:node
<?php
namespace Drupal\dies_event\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* @file
* Article Library Menu.
*/
/**
* Provides a 'EventDetailBlock' block.
*
* @Block(
* id = "dies_event_detail_block",
* admin_label = @Translation("Event detail block"),
* context = {
* "node" = @ContextDefinition("entity:node", label = @Translation("Node"))
* }
* )
*/
class EventDetailBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
$build = [];
$node = $this->getContextValue('node');
// Only available on event nodes.
if ($node->getType() === 'event') {
$build['dies_event_detail'] = [
'#theme' => 'dies_event_detail',
'#node' => $node,
];
}
return $build;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment