ConfigurablePlugin example

/** * @coversDefaultClass \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection * @group Plugin */
class DefaultSingleLazyPluginCollectionTest extends LazyPluginCollectionTestBase {

  /** * {@inheritdoc} */
  protected function setupPluginCollection(InvocationOrder $create_count = NULL) {
    $definitions = $this->getPluginDefinitions();
    $this->pluginInstances['apple'] = new ConfigurablePlugin(['id' => 'apple', 'key' => 'value'], 'apple', $definitions['apple']);
    $this->pluginInstances['banana'] = new ConfigurablePlugin(['id' => 'banana', 'key' => 'other_value'], 'banana', $definitions['banana']);

    $create_count = $create_count ?: $this->never();
    $this->pluginManager->expects($create_count)
      ->method('createInstance')
      ->willReturnCallback(function D$id) {
        return $this->pluginInstances[$id];
      });

    $this->defaultPluginCollection = new DefaultSingleLazyPluginCollection($this->pluginManager, 'apple', ['id' => 'apple', 'key' => 'value']);
  }

  
Home | Imprint | This part of the site doesn't use cookies.