Created
November 20, 2016 23:30
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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