Context aware plugins I am working on porting a module from Drupal 7 to Drupal 8.
In the process I have to port a ctools content type plugin to the new context aware plugin.
The legacy plugin had "node" as a required context because it had to appear only on the node pages. I am finding it hard to implement it in the new plugin system.
Here is how I define the new plugin

/**
 * Provides a 'Custom' block for the current node.
 *
 * @Block(
 *   id = "machine_name_of_block",
 *   admin_label = @Translation("Admin label for the block"),
 *   context = {
 *     "node" = @ContextDefinition("entity:node", required = FALSE)
 *   }
 * )
 */
class ModuleBlock extends BlockBase {
  /**
   * {@inheritdoc}
   */
  protected function blockAccess(AccountInterface $account) {
    /** @var $user \Drupal\user\UserInterface */
    // $user = $this-&gt;getContextValue('user');
    $node = $this-&gt;getContextValue("node");
    if (!is_null($node)) {
      return AccessResult::allowed();
    }
    else {
      return AccessResult::forbidden();
    }
  }

  /**
   * {@inheritdoc}
   */
  public function build() {
    // Sample output which will be changed later.
    return array('#markup' =&gt; '&lt;span&gt;' . $this-&gt;t('Powered by &lt;a href="@poweredby"&gt;Drupal&lt;/a&gt;', array('@poweredby' =&gt; 'https://www.drupal.org')) . '&lt;/span&gt;');
  }

}


I have a problem in accessing the context value in this plugin using $this-&gt;getContextValue('node');. It seems to return null even if I am on a node page.
Am I missing something?
Why don't you just use the existing node type condition plugin?

That won't solve your problem if you also need the node to actually display something, but core currently just doesn't really do this for blocks, there is no UI to configure the mapping, so it only works if the context has the exact same name.

You will likely have to fall back to getting the parameter yourself out of the route match service, for now.