DRUPAL8 - How to pass context parameters into blocks added to a panel page ?

Public

Warning message

We recommend you to assign at least one category to this snippet so you could easily navigate it in the future. Edit your snippet here.

Get raw version
php
  1. <?php
  2.  
  3. namespace Drupal\mymodule_article\Plugin\Block;
  4.  
  5. use Drupal\Core\Block\BlockBase;
  6.  
  7. /**
  8.  * @file
  9.  * Render Social links.
  10.  */
  11.  
  12. /**
  13.  * Provides a 'SocialBlock' block.
  14.  *
  15.  * @Block(
  16.  * id = "social_block",
  17.  * admin_label = @Translation("Social block"),
  18.  * context = {
  19.  * "node" = @ContextDefinition("entity:node", label = @Translation("Node"))
  20.  * }
  21.  * )
  22.  */
  23. class SocialBlock extends BlockBase {
  24.  
  25. /**
  26.   * {@inheritdoc}
  27.   */
  28. public function build() {
  29. global $base_url;
  30.  
  31. $node = $this->getContextValue('node');
  32. $build = [];
  33. $build['social_block'] = array(
  34. '#theme' => 'social_links',
  35. '#full_url' => $base_url . $node->url(),
  36. '#node_title' => $node->getTitle(),
  37. );
  38. return $build;
  39.  
  40. }
  41.  
  42. }