Last active
September 20, 2018 15:54
-
-
Save dsnopek/b4e0bc096b216d63a96d17559484dc51 to your computer and use it in GitHub Desktop.
Drupal 8 block annotation with context example
This file contains 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
/** | |
* @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