You are here

class TestNodeContext in Component blocks 1.x

Same name and namespace in other branches
  1. 1.0.x tests/modules/component_blocks_test/src/TestNodeContext.php \Drupal\component_blocks_test\TestNodeContext
  2. 1.1.x tests/modules/component_blocks_test/src/TestNodeContext.php \Drupal\component_blocks_test\TestNodeContext

Defines a class for a test node context.

Hierarchy

Expanded class hierarchy of TestNodeContext

1 string reference to 'TestNodeContext'
component_blocks_test.services.yml in tests/modules/component_blocks_test/component_blocks_test.services.yml
tests/modules/component_blocks_test/component_blocks_test.services.yml
1 service uses TestNodeContext
component_blocks_test.context in tests/modules/component_blocks_test/component_blocks_test.services.yml
Drupal\component_blocks_test\TestNodeContext

File

tests/modules/component_blocks_test/src/TestNodeContext.php, line 15

Namespace

Drupal\component_blocks_test
View source
class TestNodeContext implements ContextProviderInterface {

  /**
   * Node.
   *
   * @var \Drupal\node\NodeInterface
   */
  protected $node;

  /**
   * {@inheritdoc}
   */
  public function getRuntimeContexts(array $unqualified_context_ids) {
    $result = [];
    $context_definition = EntityContextDefinition::create('node')
      ->setRequired(FALSE);
    $cacheability = new CacheableMetadata();
    $cacheability
      ->setCacheContexts([
      'route',
    ])
      ->setCacheMaxAge(0);
    $context = new Context($context_definition, $this->node);
    $context
      ->addCacheableDependency($cacheability);
    $result['node'] = $context;
    return $result;
  }

  /**
   * {@inheritdoc}
   */
  public function getAvailableContexts() {
    $context = EntityContext::fromEntityTypeId('node', 'A node');
    return [
      'node' => $context,
    ];
  }

  /**
   * Sets value of Node.
   *
   * @param \Drupal\node\NodeInterface $node
   *   Value for Node.
   */
  public function setNode(NodeInterface $node) : void {
    $this->node = $node;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TestNodeContext::$node protected property Node.
TestNodeContext::getAvailableContexts public function Gets all available contexts for the purposes of configuration. Overrides ContextProviderInterface::getAvailableContexts
TestNodeContext::getRuntimeContexts public function Gets runtime context values for the given context IDs. Overrides ContextProviderInterface::getRuntimeContexts
TestNodeContext::setNode public function Sets value of Node.