Skip to content

Instantly share code, notes, and snippets.

@dsnopek
Last active September 20, 2018 15:54
Show Gist options
  • Save dsnopek/b4e0bc096b216d63a96d17559484dc51 to your computer and use it in GitHub Desktop.
Save dsnopek/b4e0bc096b216d63a96d17559484dc51 to your computer and use it in GitHub Desktop.
Drupal 8 block annotation with context example
/**
* @Block(
* id = "my_block",
* context = {
* "node" = @ContextDefinition("entity:node")
* }
* )
*/
class MyBlock extends BlockBase implements ContextAwarePluginInterface {
/**
* {@inheritdoc}
*/
public function build() {
// The render array.
$build = [];
$node = $this->getContextValue('node');
// @todo Do something with the $node to affect the $build array
return $build;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment