DerivativeDiscoveryDecorator example

public function testGetDerivativeFetcher() {
    $definitions = [];
    $definitions['non_container_aware_discovery'] = [
      'id' => 'non_container_aware_discovery',
      'deriver' => '\Drupal\Tests\Core\Plugin\Discovery\TestDerivativeDiscovery',
    ];

    $this->discoveryMain->expects($this->any())
      ->method('getDefinitions')
      ->willReturn($definitions);

    $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain);
    $definitions = $discovery->getDefinitions();

    // Ensure that both test derivatives got added.     $this->assertCount(2, $definitions);
    $this->assertEquals('non_container_aware_discovery', $definitions['non_container_aware_discovery:test_discovery_0']['id']);
    $this->assertEquals('\Drupal\Tests\Core\Plugin\Discovery\TestDerivativeDiscovery', $definitions['non_container_aware_discovery:test_discovery_0']['deriver']);

    $this->assertEquals('non_container_aware_discovery', $definitions['non_container_aware_discovery:test_discovery_1']['id']);
    $this->assertEquals('\Drupal\Tests\Core\Plugin\Discovery\TestDerivativeDiscovery', $definitions['non_container_aware_discovery:test_discovery_1']['deriver']);
  }

  
// Create the object that can be used to return definitions for all the     // plugins available for this type. Most real plugin managers use a richer     // discovery implementation, but StaticDiscovery lets us add some simple     // mock plugins for unit testing.     $this->discovery = new StaticDiscovery();

    // Derivative plugins are plugins that are derived from a base plugin     // definition and some site configuration (examples below). To allow for     // such plugins, we add the DerivativeDiscoveryDecorator to our discovery     // object.     $this->discovery = new DerivativeDiscoveryDecorator($this->discovery);

    // The plugin definitions that follow are based on work that is in progress     // for the Drupal 8 Blocks and Layouts initiative     // (http://groups.drupal.org/node/213563). As stated above, we set     // definitions here, because this is for unit testing. Real plugin managers     // use a discovery implementation that allows for any module to add new     // plugins to the system.
    // A simple plugin: the user login block.     $this->discovery->setDefinition('user_login', [
      'id' => 'user_login',
      
Home | Imprint | This part of the site doesn't use cookies.